-->
Page 1 of 2

Example - servo control

PostPosted: Tue Dec 09, 2014 4:18 pm
by Erni
In this example e servo is controlled via a UDP server.
I send commands from my phone UDPtester app
Forexample 1500 means the servo is in neutral and 1000 and 2000 to either side
For those who don't know:
The signal til control a servo is a pulse between 1000 and 2000 uS, sendt every 20 ms.
The servo seems a little "twichy" which I think is because of the GPIO Flicker mentioned here:
viewtopic.php?f=18&t=781

Don't send values outside 1000 to 2000, the servo might be damaged.
It would be more useful if I had a UDP sender with a knob or slider.
Anybody know of an androis app ?

Code: Select allif(pl==nil) then
pl=1500
end
port=88
pin=9
srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl)
   print("Command Reveived")
   print(pl)
--servo code
gpio.mode(pin,gpio.OUTPUT)
tmr.alarm(20, 1, function() 
gpio.write(pin,gpio.HIGH)
tmr.delay(pl)
gpio.write(pin,gpio.LOW)
end)
 --servo code
   end)
srv:listen(port)

Re: Example - servo control

PostPosted: Wed Dec 10, 2014 2:24 am
by sancho

Re: Example - servo control

PostPosted: Wed Dec 10, 2014 7:29 am
by gerardwr
Erni wrote:The signal til control a servo is a pulse between 1000 and 2000 uS, sendt every 20 ms.
The servo seems a little "twichy" which I think is because of the GPIO Flicker mentioned here:


Good to know that ESP/LUA is capable of sending accurate pulses between 1000-2000uS. To control 433Mhz power switches I currently use an Arduino+433MHZ-transmtter, and bit bang the required pulses for the protocol. Guess I could do the same with an ESP+433Mhz transmitter.

Could it be that the "twitchy" behavior is caused by the variance in the pulse lengths due to the variance in processing time of interpreted Lua code?

Nice example, thanks for sharing.

Re: Example - servo control

PostPosted: Wed Dec 10, 2014 10:22 am
by Erni
Thanks sancho
I had totally overlooked this. Comming from the Arduino world I am used to that the pwm has too high freqence and too low resolution.

So pwm.setup(9, 50, 76) should give a servo pulse of 1500 uS
The only drawback is a lover resolution, but it works

gerardwr
I am not sure what caused the twiching.
If I read zeroday's test correct it is not caused by the lua firmware.
I don't have an oscilloscop, so I can't see how this looks like.