Servo library

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
mflmartin
Posts: 17
Joined: Sat Jul 23, 2016 7:30 pm

Re: Servo library

Post by mflmartin » Mon Jan 02, 2017 11:44 am

pythoncoder wrote:An easy way might be to use a standard 180 degree servo and gear it up 2:1. The only snag is that at (say) 11.59 the clock's hand would sweep through 354 degrees backwards to get to 12.00.
Thanks... But that is not an option, due to the "aesthetics" of the movement. I want seamless analog like movement. But your suggestions is a way, for sure. Thanks!


Sent from my iPhone using Tapatalk

User avatar
pythoncoder
Posts: 3500
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Servo library

Post by pythoncoder » Mon Jan 02, 2017 1:46 pm

Fair enough, in which case I'd go for stepper motors.
Peter Hinch

User avatar
dhylands
Posts: 3202
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Servo library

Post by dhylands » Fri Jan 06, 2017 7:45 am

You can also setup the PWM yourself.

For example, this code:

Code: Select all

servo_pin = pyb.Pin.board.X1
t5 = pyb.Timer(5, prescaler=83, period=19999);
servo = t5.channel(1, pyb.Timer.PWM, pin=servo_pin)
servo.pulse_width(1000)
allows 1 usec resolution on the pulse width. The regular servo library only allows 10 usec resolution.

othoma
Posts: 1
Joined: Sat Jun 16, 2018 12:17 pm

Re: Servo library

Post by othoma » Sat Jun 16, 2018 12:19 pm

Hello, has anyone tested the library on ESP32 ?

I have some trouble to make it work.
Thanks

apollodriver
Posts: 9
Joined: Tue Jan 29, 2019 8:54 am

Re: Servo library

Post by apollodriver » Sat Aug 10, 2019 7:54 pm

hello dear all - well that would be great
Hello, has anyone tested the library on ESP32 ?

I have some trouble to make it work.
Thanks
i would love to use it on esp32

:)


BTW one question: - do we need that library - cannot we just start without that... - cf this post:

https://icircuit.net/micropython-contro ... demcu/2385
Servos are exciting devices. We can get precise posting with minimal code,
all we need is a controller that can produce PWM at 50Hz.
In this post we will understand how to use ESP32 to control Servo.
We will be using micropython to program ESP32/NodeMCU.
The grate thing about MicroPython is that it is platform independent (mostly),
which means code written for NodeMCU (ESP8266) can be used on ESP32 as well.

To use MicroPython on ESP32, First we need to load MicroPython Interpreter. Check out ESP32
– Getting started with MicroPython post to load interpreter and tools you can use with micro python. https://icircuit.net/esp32-micropython- ... arted/1999 If you are using NodeMCU, then refer to this post https://icircuit.net/nodemcu-getting-st ... ython/2406
MicroPython has PWM support. You can find full documentation of PWM library here http://docs.micropython.org/en/latest/e ... l/pwm.html

Environment requirements:
we need a ESP32 or NodeMCU

Machine with uPyCraft to load python files to the device

Controlling Servo:
Connect servo signal pin to GPIO2 of the ESP, you need to power the servo as well

Code: All you need is couple of python lines to control the servo, how easy is that

i

Code: Select all

mport machine
p4 = machine.Pin(4)
servo = machine.PWM(p4,freq=50)
# duty for servo is between 40 - 115
servo.duty(100)
The PWM method of machine takes two inputs, the pin to which we want connect servo
(in case of ESP8266 we can choose one from 0, 2, 4, 5, 12, 13, 14 and 15) and frequency of the PWM signal.
Most of the hobby servos work with 50Hz PWM, so we choose that. Then we can use duty method to set the anglewe can call servo.duty() method to change the set the servo angle



love to hear from you

Post Reply