2

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

4
  • Isn't the UNO running with 5V and the ESPs with only 3.3V? I suspect the servo needs 5V on the control input. It may work a bit with ESP32 but not with ESP8266 because the boards may give slightly different GPIO voltage?
    – datenheim
    Mar 4 at 22:57
  • I thought voltage makes a difference only for VCC and not GPIOs but it makes sense I suppose.. thanks
    – Shay Lavi
    Mar 6 at 4:07
  • How can you tell the voltage consumption of a GPIO? should that be specified somewhere??
    – Shay Lavi
    Mar 6 at 5:40
  • A GPIO does not have a voltage consumption. It can only source or sink current. A ESP8266 can not deliver more than 12 mA on a GPIO, while the ESP can deliver up to 40 mA per pin. That could explain that it works a bit better with ESP32. Both work on 3.3 V. But the UNO works on 5V - which is compatible with the servo's datasheet. I think your problem does NOT lie in the libraries or software. Show how did you wired everything up!
    – datenheim
    Mar 6 at 9:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.