• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

servo not workiing with wifi library

Q&A Forum › Category: ESP32 › servo not workiing with wifi library
0 Vote Up Vote Down
mcphie asked 3 years ago

Attempting to control servo from web client–servo does not respond.  Servo works fine without wifi library and web server code.  Using NODEMCU ESP-32S. Correct servo values are being returned from web client but servo does not respond to <object>.write(angle) commend.  

Question Tags: servo wifi
13 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.

What project are you trying to run?

When you say it doesn’t respond, what happens? Doesn’t it move?

What’s the GPIO that you’re using to control the servo?

Can you connect an LED to that GPIO and see if changing the slider changes the LED brightness? That way, you can see if the ESP32 is actually outputting a signal (or if you happen to have an oscilloscope, you can see if it’s outputting any signal).

Regards,
Sara

0 Vote Up Vote Down
mcphie answered 3 years ago

I am taking the Learn ESP32 with Arduino IDE course and trying to run the Web server servo control program.  When I run the standalone servo control program, the servo moves back and forth as expected but when the wifi/web server servo control program is loaded, I move the slider on the web client, the appropriate value is received by the ESP32 (as seen in the serial monitor) but there is no servo action at all.  I fried doing some explicit moves at the start of the sketch but still nothing,  No change to LED brightness when connected in place of servo. Is there a pin conflict with wifi and servo libraries?  Thanks for your help.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
It seems that Wi-Fi might be interfering with something. But it shouldn’t, because the project was working when we wrote the tutorial.
However, I suspect that it must be something to do with some pins and Wi-Fi. Can you try using GPIO 32 instead? Does it behave the same?
Regards,
Sara
 

0 Vote Up Vote Down
mcphie answered 3 years ago

Tried GPIO 32 still no action.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi again.
I tested the project myself and it controls the servo via web server.
Did you install the recommended library? What is the ESP32 board model you’re using?
Regards,
Sara

0 Vote Up Vote Down
mcphie answered 3 years ago

I installed the following board library on the Arduino IDE
http://arduino.esp8266.com/stable/package_esp8266com_index.json
I am using the exact web server/servo sketch from the course with wifi.h and servo.h libraries.  I am not using the DOIT version of the ESP32 board but a board called NODEMCU ESP32S with chip WROOM ESP32.  Maybe the problem is with this different hardware.  I will pick up the exact board identified in the course and try again.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi again,
But did you install the servo library we recommend? It’s this one: https://github.com/RoboticsBrno/ServoESP32
Regards,
Sara

0 Vote Up Vote Down
mcphie answered 3 years ago

Yes.  I tried again using the exact library you indicated.  No servo action when using slider bar from web site although values are being correctly sent as seen in the serial monitor.  Also tried connecting servo to 5v pin–instead of 3.3v–feel slight servo vibration but no movement.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
I’m sorry but I don’t know what might be wrong.
Can you tell me exactly what do you see in the Serial Monitor when moving the slider? Or can you post a print screen?
You may also consider trying a different servo library.
Can you install the ESP32Servo library? In your Arduino IDE, go to Sketch > Include Library > Manage Libraries and search for “ESP32 Servo”. Install the library by John K. Bennet.
Then, modify your code to use that library.
Include the library

#include <ESP32Servo.h>

Define the Servo pin

#define SERVO 13

Create a servo object:

Servo myservo;

Then, to move the servo use:

myservo.write(valueString.toInt());

Can you try it?
Regards,
Sara
 
 

0 Vote Up Vote Down
mcphie answered 3 years ago

Here is my output:

New Client.
GET /?value=24& HTTP/1.1
Host: 192.168.0.156
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
X-Requested-With: XMLHttpRequest
Referer: http://192.168.0.156/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
24
Client disconnected.

New Client.
GET /?value=39& HTTP/1.1
Host: 192.168.0.156
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
X-Requested-With: XMLHttpRequest
Referer: http://192.168.0.156/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
39
Client disconnected.
 
I used the library ServoESP32 which inserts the line <Servo,h. into the sketch.  I used the servo commands you described and then added a myservo.attach(SERVO); but in both tries, there was no servo activity. The serial output accurately showed my 2 slider positions.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
The library I was talking about is a different library. That should be included as ESP32Servo.h
With the information from the Serial output, it seems that everything is working as expected.
I have no idea what might be wrong. Did you experiment with a different ESP32 board?
Regards,
Sara

0 Vote Up Vote Down
mcphie answered 3 years ago

Finally got the servo to work using the John K. Bennet library you suggested.  I didn’t realize there were so many servo library alternatives and had not using the correct library.  One interesting detail–I found that the servo did not move the full 180 degree range.  I did some poking around and found out the ESP_Servo.h library has the pulse width values commented out for smaller servos like mine.  I commented out the values for larger servers and uncommented the other values. 
//#define DEFAULT_uS_LOW 1000 // 1000us
//#define DEFAULT_uS_HIGH 2000 // 2000us
// Values for TowerPro SG90 small servos
#define DEFAULT_uS_LOW 400
#define DEFAULT_uS_HIGH 2400
 
The servo works perfectly now!  Thank you for your assistance.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

GREAT!!!
I’m glad it is working now.
Thanks for letting me know about the pulse width for different servos. That’s a very important detail.
I’ll mark this issue as resolved.
If you need further help, you just need to open a new question in our forum.
Thanks for following our work.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.