Continous servos and esp32

Hello, i have 3 continuous servos running random times on an arduino nano, works fine. So then i tries the same servos on the esp32 with the example multiple code and cant seem to get them all to move. Is there a reason continuous sg90 wont work with the esp?

1 Like

How are the servos powered ?

They are powered from a separate 5v source, its exactly the same as i have it set up on the nano just switched to an esp32 dev board. Its just strange the dont move with the esp but plug them into the nano and the move again, ive tried a few different pins on the esp but to no avail.

You'll need to use a different servo library. Here's one.

Yeah ive tried the library. I used the multiple servo example, and sometimes only 1 spins. Thats what im asking, is there anything specific anyone can think of as to why its not working

  • None of the examples were written with continuous rotation servos in mind.
  • Make sure you're using ESP32 ESP32S2 AnalogWrite 4.3.4 and the latest version of the Arduino ESP32 Core (2.0.7 or 2.0.8)

Try this example ...

ok this is really strange. i can see in the simulation it works, but irl i flashed the sketch and literally only one servo is working again, but i hook it up to the nano and its fine, so this tells me it cant be the servos. but swapping the servo pins has the same single servo working.

So even curiouser, swapped one of the servos for a mg90, basically the same sevo and it moves. So there is some issue im guessing with the cheap sg90s and esp board.

Its possible that they need higher voltage than 3.3V for the pwm signal.

This library has an inverted pwm option that allows you to use a single NPN transistor or N-Channel MOSFET for voltage level translation.

Could you show a picture of your ESP32 board with servos and power supply connected?
Are you saying that only one ESP32 pwm output works at a time but not all 3 at the same time?

That would make sense. Ill try this shortly.

For the inverted option:

void setup() {
  pwm.attach(servoPin1, 0, 1000, 2000, 0, 1, true);
  pwm.attach(servoPin2, 1, 1000, 2000, 0, 1, true);
  pwm.attach(servoPin3, 2, 1000, 2000, 0, 1, true);
}

Wokwi_badge Using inverted PWM mode to sweep a servo motor


Its not powered by that usb sitting in front. Its from a 5v buck.

Are there resistors in this pic, if so what size should they be.

When i switch to the mg90 they both work and i assume all 3 would, they are 180degree servos, but switching to the sg90 continuous servos they do not. I tried the inverted sketch with a npn transistor and nothing happened, then i seen there should have been a resistor or two in there and the transistor got real hot.

Yes, you need resistors ...

  • I would go with 1K for the transistor base and also1K for the collector to 5V.
  • Use the setup code in post #12.

ok,well that seems to have done it, the cheap sg90 is working now. so 3 servos would need 3 transistors etc etc? correct?

1 Like

So should i get a level shifting board and use the normal library example with the inverse pwm?

what's your power supply

  • Yes, just 3 transistors, 6 resistors and inverted pwm to drive 3 servo motors.
  • Or a level shifting board (for 3 or more signals) and normal pwm to drive 3 servo motors.

Be careful to use the correct type of pwm, or the servo motors will not work and they'll overheat.