360 servo not working on ESP32 & micropython

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Julian
Posts: 2
Joined: Fri Nov 19, 2021 1:38 pm

360 servo not working on ESP32 & micropython

Post by Julian » Fri Nov 19, 2021 1:50 pm

Hi guys. Please help me run 360 servo motor (MG996R) on esp32 devkit v1 board.
I tried same motor on arduino board and is working perfectly, can't figure out how to make this running on esp32 and it becames frustrately.
I tried code from all tutorials availables and all youtube videos related and nothing make this damn motor running, I also tried for loops for PWM.duty in hope that one will make the motor running.

Code: Select all

from machine import Pin, Timer, PWM
from time import sleep

pin = Pin(23)
servo = PWM(pin)
servo.freq(50)
servo.duty(anything here)
sleep(0.5)
I'm using external 5v power source for motor and the ground is common with esp board.
Please help me with solution

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: 360 servo not working on ESP32 & micropython

Post by OlivierLenoir » Fri Nov 19, 2021 5:25 pm

For a servo motor duty time on need to be between 1ms and 2ms. Currently the duty cycle has to be in the range of 0-1023.
So on an ESP32, duty cycle for 1ms is around 51 and 2ms is around 102.

Julian
Posts: 2
Joined: Fri Nov 19, 2021 1:38 pm

Re: 360 servo not working on ESP32 & micropython

Post by Julian » Thu Nov 25, 2021 12:10 pm

Thank you for your answer. I tried all the values for dusy, I even put a for there with range. The 360 motor is not running but the 180 version of the same motor it does working. Could you please also try to run 360 motor on esp32?

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: 360 servo not working on ESP32 & micropython

Post by OlivierLenoir » Thu Nov 25, 2021 4:54 pm

On your servo motor MG996R, you have tree wires:
  • (Yellow) PWM signal from EPS32
  • (Red) 5V
  • (Brown) GND
Do you supply the servo with 5V?

Post Reply