If I check the Serial Monitor, it says "Connecting to my ssid" and that's all correct but then it just prints out a series of dots....
Is there something wrong with the board?
Is this a known issue?
How can I troubleshoot this?
Thanks
If I check the Serial Monitor, it says "Connecting to my ssid" and that's all correct but then it just prints out a series of dots....
Is there something wrong with the board?
Is this a known issue?
How can I troubleshoot this?
Thanks
Please post the sketch that you are using.
Have you got the correct SSID and password in the sketch ?
I do have the correct ssid and password in there.
Thanks for the reply BTW.
I got this code from Google AI.
#include <WiFi.h>
#include <ESP32Servo.h>
// Replace with your network credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
Servo servo;
const int servoPin = 13;
WiFiServer server(80);
String header;
void setup() {
Serial.begin(115200);
servo.setPeriodHertz(50);
servo.attach(servoPin, 500, 2400); // Standard servo pulse widths
// Connect to Wi-Fi
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop() {
WiFiClient client = server.available();
if (client) {
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
header += c;
if (c == '\n') {
if (currentLine.length() == 0) {
// HTTP request ends with a blank line
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<style>body { text-align: center; font-family: Arial; }");
client.println("input[type=range] { width: 300px; }</style></head>");
client.println("<body><h1>ESP32 Servo Web Control</h1>");
client.println("<p>Position: <span id=\"posVal\">90</span></p>");
client.println("<input type=\"range\" min=\"0\" max=\"180\" value=\"90\" id=\"servoSlider\" oninput=\"servoRotate(this.value)\">");
// AJAX to update the server without reloading the page
client.println("<script>function servoRotate(pos) {");
client.println("document.getElementById(\"posVal\").innerHTML = pos;");
client.println("var xhr = new XMLHttpRequest();");
client.println("xhr.open(\"GET\", \"/?value=\" + pos + \"&\", true);");
client.println("xhr.send();");
client.println("}</script>");
client.println("</body></html>");
// Break out of the while loop
break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
}
}
// Check if the GET request contains our servo command
if(header.indexOf("GET /?value=") >= 0) {
int posStart = header.indexOf("?value=") + 7;
int posEnd = header.indexOf("&", posStart);
String posString = header.substring(posStart, posEnd);
int servoPos = posString.toInt();
servo.write(servoPos);
}
// Clear the header variable
header = "";
client.stop();
}
}
There's a "WiFi scan" example sketch somewhere in the Examples menu, probably under ESP32, WiFi or similar. Try running that to check that it can detect your access point, or any access point. It will report what access points it can detect, showing the SSID & signal strength.
It will probably come as no consolation to you but I can upload and run the sketch that you posted. I tried it on an Arduino Nano ESP32 which has an ESP32-S3 processor. I have not tried the servo functions but can connect to the web page showing the servo control slider.
Which board have you got selected in the IDE ?
Incorrect SSID?
Incorrect password?
Unsupported characters in one or both?
5GHz Wifi?
MAC filtering on the Wifi?
It's the ESP32S3 Dev Module
So when you tested it with the NANO it connected.
That helps! Sounds like it could be the board.
Another issue with this board is that it seems to have a problem uploading. I've got to try several times before it's successful.
Success! (sort of)
When I ran the WiFiScan it showed my network but the first letter was upper case. I did not know that the ssid would be case sensitive.
Anyway, now I'm connected and it shows the slider bar for my servo but the servo is not doing anything.
Perhaps I'm using the wrong pin...
I really appreciate all the help!
How is the servo powered ?
What do you see if you print servoPos ?
The servo is connected to the 5v pin.
ServoPos... I'll have to learn how to get that information.
Thanks for the reply.
You already have this in setup()
So you are starting the Serial interface
Add this line of code before writing to the servo
Serial.println(servoPos);
Upload the sketch, open the Serial monitor in the IDE (icon top/right of the IDE) and set the baud rate to 115200 baud
Connect to the web page created by the sketch and move the slider. The value of servoPos will be shown in the Serial monitor
Ah ha! Took me a minute but that's working! The readout anyway.
The Serial Monitor is reading the same value as the slider in my browser.
Bad idea. An ESP32 is not a power supply.
You can sort-off get away with it on a non-WiFi board (Uno etc.) and a tiny servo like an SG-90, but with an ESP32 things go south quickly. Bigger servos should never be powered from/through the board.
Congratulations, you have passed Arduino Debugging 101
Well I got it working. The 5v pin is not really 5v on this boad. Don't completely understand that yet. With this tiny servo mg90s and no load I thought it would at least move.
Anyway, I took an old USB cable and a wall charger to supply the servo separately. I did have to tie the ground to the board as well.
I read there is a workaround for that 5v pin but I have not looked at that closely. It seems like it should just pass through from the wall charger...
Thanks for the replies!