ESP32 Feather S3 servo

I am trying to get an SG90 micro servo to run by attaching it to my S3.

Initially, I tried powering from the USB and GND connection on the S3, and the signal in pin 12. Since this didn't work I tried a separate battery pack supplying 6.4v from 4AA batteries.

I have a socket soldered to the S3, and with an extension plugged in, I can measure 6.4v at the end, and 49.94Hz on the signal line with my multimeter. (I also measured a stable 5v when it was connected to the USB pin) This rules out dodgy wiring or a busted S3 - I also tried this on an LOLIN D1 mini, and it didn't work there either.

I also wondered whether I was struggling with the pin, but moving it around did not help anything - other than maybe blowing up an S2 board while walking through pins, and now won't respond to the serial cable plugged in... that's another story.

This leaves 3 options
1: The servo is broken: I swapped servos and still nothing. I invested in a servo tester and they're both fine.
2: Logic level voltages: The servo specs say that they are logic level (3v3) and 5v tolerant... Could it be wrong?
3: I'm an idiot: Let's explore this a bit more.

Here is a sketch that covered multiple things, but as configured, should just be the same "sweep" example with some Serial output and the LED blinking... both of these work.

#include <ESP32Servo.h>

int led_pin = 13;
int servo_pin = 12;
bool led_on = true;

Servo myservo;

void setup() {
  Serial.begin(115200);
  delay(500);
  Serial.println("\nServo sweep and LED blink");

  pinMode(led_pin, OUTPUT);
  digitalWrite(led_pin, LOW);

  //  pinMode(servo_pin, OUTPUT);
  //  digitalWrite(servo_pin, LOW);

  //  myservo.setPeriodHertz(50);
  //  myservo.attach(servo_pin, 500, 2400);
  myservo.attach(servo_pin);
  myservo.write(0);
}

void loop() {
  int pos;
  Serial.println("loop(): on");
  digitalWrite(led_pin, led_on);
  //digitalWrite(servo_pin, led_on);
  led_on = !led_on;

  for (pos = 0; pos <= 180; pos += 2) {
    myservo.write(pos);
    delay(15);
  }

  Serial.println("loop(): off");
  digitalWrite(led_pin, led_on);
  //digitalWrite(servo_pin, led_on);
  led_on = !led_on;
  for (pos = 180; pos >= 0; pos -= 2) {
    myservo.write(pos);
    delay(15);
  }
}

What have I missed?

I'd rather not plug in something like a pca9685 as I need to keep weight and component count down. Also, the sweep example is an official example, and lots of websites explain exactly this example.

What else can I try?

Any help very much appreciated.
Kind regards
Nigel

A voltage level shifter in the servo signal line

Yeah. I had thought of that but it involves me going and looking for one somewhere in my pile of boxes. With all the examples of being directly plugged in though, I was hoping it was just me being an idiot - which is infinitely more fixable tonight :slight_smile:

The common factor would seem to be your servo, but not all SG90s are made equal and I would be very suspicious of the stated 3.3V lower limit of the signal voltage

I've run the metal geared servos directly driven by an ESP32's GPIO pins.

Post a schematic and images of the wired project and describe the issue, please.

Also your setup is a bit different than the ESP32 servo example.

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, 1000, 2000); // attaches the servo on pin 18 to the servo object
	// using default min/max of 1000us and 2000us
	// different servos may require different min/max settings
	// for an accurate 0 to 180 sweep
}

Thanks @Idahowalker I did start with that sketch. As for the schematic, I've tried a few, starting here:

After a couple of fo hours of sleep, I think I'm resigned to the fact I need a voltage step-up or another servo. I have ordered these (3-6v):

I also have a PI hut order coming and some of these are on there.

They specifically say they can be run directly off an Arduino

Finally, I have a couple 2.2gm servos which (supposedly) work off a single LiPO battery (but only have 0.2kg/cm torque)

So I will see what happens

Oh, this was the example I was looking for where it had a D1 mini driving a servo direct. It does specifically state the Tower Pro SG90.

Are your original servos genuine or clones though ?

I thought I was being efficient and reusing stuff in my box-o-spares but they are most likely cheap clones so I've ordered some probably-more-proper ones from PI hut. fingers crossed :smiley:

What is the problem you are having?

Powering a servo from a breadboard is not going to work, as a note.

What is the problem you are having?

Powering the servo from the 5V of the MCU is not going to work.

What is the problem you are having?

In the picture posted from post#6 a ESP8266 is shown to be in use. A ESP8266 is NOT a ESP32.

What is the problem you are having?

Did it work?

What is the problem you are having?

Blockquote
What is the problem you are having?

For all of them, "The Servo does not move."

The pic is diagrammatic as I do not have a Fritzing image of a Feather S3, but the D1 mini is also something I tried, signal pin on D4, like the example at WiFi Servo Controller using WeMos D1 Mini | Microcontroller Tutorials

I implemented that code, and nothing moved. I then started powering the mini from the USB and the servo from a separate USB cable from a power bank (I also tried a 4xAA cell to power the servo) Same thing happened - i.e. nothing moved.

I then moved to the S3, the web server is radically different so I moved to the ESP32 sweep sketch (changed the pin to pin 12) and... nothing moved.

So interesting things have occurred, none to fix anything, but weird behaviour. I went looking for the logic level shifters and I also found a lipo servo. I tried it, and it didn't work.

Interestingly, when I unplugged it, it moved... plugged it back in, nothing... wiggled the connector... intermittent jerky movement... it seems that brushing the signal cable over the GPIO pin makes it jiggle. No other pin does this and changing the pin in code still works for the specified pin... so there is something going on.

I went all in. Soldered the servo direct to the pins on the board. Still nothing. I went to check if there was any holding torque or if the horns would just spin because nothing was connected... The servo noticed and then kicked in and held at the original position... whichever position it starts up in. It has to be a voltage thing.

I have a sparkfun level shifter which I'm pretty sure I've used in a high-frequency project, so 50Hz would be no problem.

I soldered the high-voltage side to the battery-voltage, and the low-voltage side to the 3v pin on the board both with a common ground pin. Pretty much no change - servo is motionless but will recognise a horn push and lock back to where it started. dragging the signal wire over an exposed pin and jiggling ocurs.

I resoldered the high voltage side to the USB power pin on the board (still a common ground)... all still exactly the same.

I connected the Servo power to a 4xAA battery pack (signal pin still going through the level stepper). all still exactly the same.

Hoping the voltage sides are isolated, I connected the high-voltage side to a 4xAA battery pack. No magic smoke, but still all exactly the same things.

Something then occurred to me. When I plug my multimeter in on the Hz function I do see the 50Hz signal briefly and then it zeros until I reconnect it... I just assumed this was me not knowing how the thing works.

I've also noticed that the serial stuff can take an age to start, with 2 processors there is probably some parallelism but I'm wondering if there is something special about the Feather S3. I can't find any servo example of anyone doing this with one of them.

Is there some weird pull-up/down disabling I have to do?

I wish there was a Qwiic connected servo module :frowning:

And the answer is ..... don't buy cheap servos. I ordered these:

And they work on the LOLIN D1 mini at 5V bus power and 3.3v signal.

Will it work on the S3 at 4v... to be seen once I have unsoldered the mess I created :slight_smile:

So Happy!!!

Well, it may work.. when they fix an underlying bug somewhere in the ESP32 S2 (possibly S3) gibblets:

That's a smidge aggravating. :frowning_face:

On the plus side. Making the modification in the code mentioned here

And things seem to work a bit better now direct off the board on the USB pin, just a boost converter to 5v and sheer rotational bliss :smiley:

That should not really come as a surprise

Terrible idea, but as we see daily, typical of the rankest, most uninformed forum newbie.