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
