Esp32 devkitv1 servo MG90s issues

I'm working with my esp32 Devkitv1 board and an MG90S servo. I have the servo connected to pin VIN (Red Wire), GND (Brown Wire), and GPIO pin 18 (Orange Wire). The code is simple, I based it off the example code esp32 sweep code. I can see from my voltmeter that it has 5V to the device but no response. Any thoughts as to what's wrong here?
I reviewed the spec sheet, and it should use 5v.
Micro Servo Motor MG90S - Tower Pro (components101.com)

#include <ESP32Servo.h>

Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position

#if defined(ARDUINO_ESP32S2_DEV)
int servoPin = 17;
#else
int servoPin = 18;
#endif

void setup() {
  Serial.begin(9600);
	// Allow allocation of all timers
	ESP32PWM::allocateTimer(0);
	ESP32PWM::allocateTimer(1);
	ESP32PWM::allocateTimer(2);
	ESP32PWM::allocateTimer(3);
	myservo.setPeriodHertz(50);    // standard 50 hz servo
}
void loop() {

  myservo.attach(servoPin, 0, 3000); // attaches the servo on pin 18 to the servo object
  Serial.write("0\n");
  myservo.write(0);
  delay(1000); 
  myservo.detach();

  myservo.attach(servoPin, 180, 3000); // attaches the servo on pin 18 to the servo object
  Serial.write("180\n");
  myservo.write(180);
  delay(1000);
  myservo.detach();

}

Here's some examples from a different library:

hmm, not sure why those are not working. Servo_Sweep.ino - Wokwi Arduino and ESP32 Simulator

c:\repo\Arduino\libraries\ESP32_ESP32S2_AnalogWrite\src\pwmWrite.cpp: In member function 'uint8_t Pwm::tone(uint8_t, uint32_t, uint16_t, uint16_t)':
c:\repo\arduino\libraries\ESP32_ESP32S2_AnalogWrite\src\pwmWrite.cpp:91:65: error: 'ledcChangeFrequency' was not declared in this scope
         ledcChangeFrequency(ch, frequency, config[ch].resolution);
                                                                 ^
c:\repo\arduino\libraries\ESP32_ESP32S2_AnalogWrite\src\pwmWrite.cpp: In member function 'void Pwm::ledc_attach_with_invert(uint8_t, uint8_t, bool)':
c:\repo\arduino\libraries\ESP32_ESP32S2_AnalogWrite\src\pwmWrite.cpp:319:3: error: 'ledc_channel_config_t' has no non-static data member named 'flags'
   };
   ^

exit status 1

Compilation error: exit status 1

Are you using the latest releases?

Arduino only lists 4.2.3 for ESP32-ESP32S2-AnalogWrite. I'm also using Arduino IDE 2.0.3 with ESP32 stable. https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Thanks for the info.

I was using using Arduino IDE 1.8.19. After installing 2.0.3, I selected the ESP32 Dev Module and updated all libraries. Then I closed and re-opened 2.0.3, then selected File-->Examples-->ESP32 ESP32S2 AnalogWrite-->Dual_Servo_Sweep_Speed.ino , then ran Verify.

If 4.2.4 is shown as installed, then 4.2.3 will be highest option on the version drop down selector.

Thanks for assisting. I tried an experiment, I think the ESP32 pwm signal is not strong enough for the servo. I connected the same servo to an uno board and ran the servo example sweep program and the servo works. I checked the pwm voltage and the uno sends .6 and the esp32 is sending .4 volts. I suspect this is the issue.

Well, if you're using a multi-meter to measure the DC voltage of a servo pwm pulse, then it would be normal to measure 0.6V on a 5V Uno and 0.4V on a 3.3V ESP32.

A scope would be the ideal instrument to use, but I don't think this is the problem. When using the ESP32, make sure to power the servo with 5V, preferably using a separate supply.

Post a schematic, post an image of the project.

Why utilize all 4 timers?

What is this supposed to be doing

myservo.attach(servoPin, 0, 3000); // attaches the servo on pin 18 to the servo object
  Serial.write("0\n");
  myservo.write(0);
  delay(1000); 
  myservo.detach();

  myservo.attach(servoPin, 180, 3000); // attaches the servo on pin 18 to the servo object
  Serial.write("180\n");
  myservo.write(180);
  delay(1000);
  myservo.detach();

?
Why not just attached the servo in setup and leave it attached?

The ESP PWM signal is strong enough.

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