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.
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
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.
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
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
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.
Hi again,
But did you install the servo library we recommend? It’s this one: https://github.com/RoboticsBrno/ServoESP32
Regards,
Sara
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.
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
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.
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
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.
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