I got stuck at the base of the Pan & Tilt circuit. NodeMCU (ESP8266) + 2 servos. Does not work in Run mode. Uncertain in step mode. What have I done wrong? I need your help. mezjoc
Don't be impatient, they are mechanical devices - add a pause between each change of servo value to give the servos an opportunity to respond to your rapid-fire changes.
If somebody instructed you to face left, you could obey without problem.
Then after turning left, if you were told to turn right you could do that without problem.
But if they told you to turn left and right and left and right and left all in quick succession without allowing you time to move, you would not move much... except perhaps to fall down cos you injured yourself.
It takes a finite time for the servo to move from eg: 0 to 180, so you need to give it at least that much time as it needs to reach any new position before sending new info to send it somewhere different.
If you want to see what the servo is capable of, try changing it position from one extreme to the other gradually in a loop, pausing between each step for a specified delay, something like...
stepsize = 10
stepdelay = 500
for position = 0 to 180 step stepsize
servo 1, position
pause stepdelay
next position
That's just off the top of my head, so you may need to play with it yourself to get it to work - but it offers a starting point for playing around with stepsize and stepdelay values to get the servo to respond as smoothly and as quickly as it can.
If stepsize is 180 then it is being told to only go to the extremes, as you've been doing, and if stepdelay is too short it won't have time to reach it's next position before being moved on to another, as you've been doing... but it still could have reached its final instructed position if the servo's were not being disabled using servo.setup 1, OFF to prevent it... which is not really necessary during testing.
Dear Electroguard!
Thanks for your detailed explanation. I understood. SERVO is working. Regards: mezjoc
Code: [Local Link Removed for Guests]
'/program/servo2_proba3.bas
'servo1...0° - 180° - 0° - 180°...
angle=0:increase=1
servo.setup 1,12
servo 1,180:pause 1000
timer0 30, ciklus
wait
ciklus:
if increase=1 then
angle=angle+2:goto up
else
angle=angle-2:goto down
end if
up:
if angle=180 then increase=0
servo 1,angle
return
down:
if angle=0 then increase=1
servo 1,angle
return