-->
Page 1 of 1

Servo library sketch

PostPosted: Sat Apr 04, 2015 7:50 am
by penatenjoe
I have some Arduino projects which are using an ESP8266-modem but which now can run on the ESP8266 itself! I love this new platform and many things work like a charm. One of my projects is using servos as mechanical drives which are not yet supported. I eventually found a way to make them work using the Ticker-library. Attached is the example sketch together with some code that shows how this is done using software PWM. Usage is identical to the Arduino library. It is very simple and I apologize for that but the original library is far beyond my C++ skills. Having said that this code works well. What I tried:
* one and two servos at different pins / speeds
* servo driven via WLAN
Both seemed to work fine with no jitter. Notice though that every servo blocks roughly 10% of the CPU time.

Re: Servo library sketch

PostPosted: Sat Apr 04, 2015 10:26 am
by RichardS
Looks nice, does delay() really block? though IGRR had some tricks in there! :-)

Richard.

Re: Servo library sketch

PostPosted: Sat Apr 04, 2015 11:00 am
by penatenjoe
The documentation on github says "The delayMicroseconds function, on the other hand, does not yield to other tasks, so using it for delays more than 20 milliseconds is not recommended." I'm using delayMicroseconds for creating the pulse for the servo which is 1-2 msec long.
Delay (or here Ticker) does allow for the execution of other tasks.

Re: Servo library sketch

PostPosted: Tue May 26, 2015 7:13 am
by Lachezar Lechev
That's very cool and it works. However I didn't understand why I got some wicked results when I hooked up the Servo on GPIO2. Why don't you put it in github?