I have a mystery I was unable to solve and would greatly appreciate it if anyone could shed some light on this.
I have a servo DSS-M15S 270 which I managed to run perfectly fine with Arduino Uno (code below). I need only 2 cables for this - output & ground. The power cable is connected to batteries and the analog is irrelevant (although I managed to connect it as well just fine).
Same exact code on an ESP8266 NodeMCU fails to run the servo. I validated the right GPIO with a different sensor (PIR) that worked fine with the ESP, but the motor wouldn't work - it slightly jitters after a few minutes but nothing works. I already tried changing between different GPIOs and seeing different reactions but still nothing.
Eventually, I connected a new ESP32 with the same code and it almost worked! the servo works during the calibration function but ANY attempt to move it again OUTSIDE the calibration function fails. so I cancelled the calibration function and the servo works perfectly fine now with the ESP32 ! I have no idea how or what is happening.. if anyone could help me get it to work on ESP8266, that would be amazing. Based on all those tests I reckon it's related to the different servo libraries of the chips somehow.
https://youtube.com/shorts/fZlu8wdeRGQ
In this second video I just return the cables back to the Arduino and everything works again (same code, same connection pins) - https://youtube.com/shorts/Jvr1oZV1AKI
#include <Servo.h>
Servo myservo;
// Control and feedback pins
byte servoPin = 4;
int feedbackPin = A0;
// Calibration values
int minDegrees;
int maxDegrees;
int minFeedback;
int maxFeedback;
int tolerance = 2; // max feedback measurement error
void calibrate(Servo servo, int analogPin, int minPos, int maxPos) {
// Move to the minimum position and record the feedback value
servo.write(minPos);
minDegrees = minPos;
delay(2000); // make sure it has time to get there and settle
minFeedback = analogRead(analogPin);
// Move to the maximum position and record the feedback value
servo.write(maxPos);
maxDegrees = maxPos;
delay(2000); // make sure it has time to get there and settle
maxFeedback = analogRead(analogPin);
}
int getPos(int analogPin) {
return abs(map(analogRead(analogPin), minFeedback, maxFeedback, minDegrees, maxDegrees));
}
void ServoSetup() {
Serial.println("Setting output");
pinMode(servoPin, OUTPUT);
Serial.println("Attaching");
myservo.attach(servoPin);
Serial.println("Calibrating");
calibrate(myservo, feedbackPin, 0, 270);
}
void setup() {
Serial.begin(9600);
ServoSetup();
}
void loop() {
Serial.println(analogRead(A0));
myservo.write(270);
Serial.println("270");
delay(2000);
Serial.println(analogRead(A0));
myservo.write(0);
Serial.println("0");
delay(2000);
}
The final code is basically like the above but without the calibration and different pins for the ESP32
Any ideas on what's happening here and how to make this work with ESP8266 would be great
Thanks, Shay