ESP32 and a Continuous Servo

Hello everyone. I would like to thank everyone who had previously assisted me with getting a traditional 180 servo to work.

This time, I'm working with 360 continuous servos for a different task, and once again I'm using an ESP32.

I have familiarized myself with how continuous servos work, and the different signals they have, however, it appears there are great differences with the ESP32. When I upload my code, the motor receives power (it is much stiffer when the circuit is active), but it simply does not rotate at all.

I've looked around and there appears to not be many libraries or documentation on how to make this servo work, through I've noted fellow who has it figured out:

I even made a servo rotate for ~ 4 seconds while building and wiring up parts of the projection im building, though I have never been able to replicate this ever again.

My code:

#include <ESP32Servo.h>

Servo myservo;  // create servo object to control a servo
// 16 servo objects can be created on the ESP32

int pos = 0;    // variable to store the servo position
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33 
// Possible PWM GPIO pins on the ESP32-S2: 0(used by on-board button),1-17,18(used by on-board LED),19-21,26,33-42
// Possible PWM GPIO pins on the ESP32-S3: 0(used by on-board button),1-21,35-45,47,48(used by on-board LED)
// Possible PWM GPIO pins on the ESP32-C3: 0(used by on-board button),1-7,8(used by on-board LED),9-10,18-21
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
int servoPin = 2;
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
int servoPin = 2;
#else
int servoPin = 2;
#endif

void setup() {
	// Allow allocation of all timers
	ESP32PWM::allocateTimer(0);
	ESP32PWM::allocateTimer(1);
	ESP32PWM::allocateTimer(2);
	ESP32PWM::allocateTimer(3);
	myservo.setPeriodHertz(50);    // standard 50 hz servo
	myservo.attach(servoPin); // attaches the servo on pin 2 to the servo object
  myservo.write(180); // AS A CONTINUOUS SERVO, THIS SHOULD ROTATE CONTINUOUSLY AT MAX POWER
}


The wiring is good, otherwise, need assistance with this code.

Do you have a link to the servo motor?
If its a SG90 like here and you have similar issues, then you may need to level shift the pwm signal.

MG90S. A metal geared cousin. But from looking at your link, I think there maybe still considerations to made around libraries AND signals. Note I am using the traditional Keith ESP32 Servo library.

You might want to give the ESP32-ESP32S2-AnalogWrite library a try. Could use the inverted mode and simple, single transistor circuit to level shift the pwm signal and could also use the servo easing feature in linear mode to control the rate of acceleration or de-acceleration of your continuous rotation servo.

If you have the time, could you please ease me in into writing the possible code that could run a basic sweep for this type of motor? Especially incorporating the leveling of the shift of the pwm signal. It's a bit urgent and would be quite appreciated.

On the library's GitHub home page has a bunch of examples. This example is probably what you're looking for:

Wokwi_badge Servo_Sweep_Inverted Using inverted PWM mode to sweep a servo motor

Note: Make sure to use the latest version of the Arduino Core for ESP32.
What version or type of ESP32 do you have?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.