Servo Problem

Recurrent H/W and software problems
Post Reply
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Servo Problem

Post by mezjoc »

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

Code: [Local Link Removed for Guests]

'/program/servo_proba.bas
'SERVO1...GND,VIN,GPIO12
'SERVO2...GND,VIN,GPIO15

servo.setup 1, 12  'GPIO12=D6
servo 1, 90
servo 1, 180
servo 1, 90
servo 1, 0

servo.setup 2, 15  'GPIO15=D8
servo 2, 0
servo 2, 180

servo.setup 1, OFF
servo.setup 2, OFF

end
User avatar
Electroguard
Posts: 835
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 267 times
Been thanked: 317 times

Re: Servo Problem

Post by Electroguard »

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.
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Re: Servo Problem

Post by mezjoc »

Dear Electroguard!
Thanks for your help. The included program works perfectly.

Code: [Local Link Removed for Guests]

'/program/servo_proba.bas
'SERVO1...GND,VIN,GPIO12
'SERVO2...GND,VIN,GPIO15
'***MÚKÖDIK***
start:
servo.setup 1, 12  'GPIO12=D6
servo 1, 90 : pause 1000
servo 1, 180 : pause 1000
servo 1, 90 : pause 1000
servo 1, 0 : pause 1000
servo 1, 90 : pause 1000
servo 1, 180 : pause 1000
servo 1, 90 : pause 1000
servo 1, 0 : pause 1000
servo 1, 90 : pause 1000
servo 1, 180 : pause 1000
servo 1, 90 : pause 1000
servo 1, 0 : pause 1000

servo.setup 2, 15  'GPIO15=D8

servo 2, 180 : pause 1000
servo 2, 0 : pause 1000
servo 2, 180 : pause 1000
servo 2, 0 : pause 1000

servo.setup 1, OFF
servo.setup 2, OFF

goto start
end
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Re: Servo Problem

Post by mezjoc »

Wrong entry.
Last edited by mezjoc on Sat Feb 19, 2022 12:23 pm, edited 1 time in total.
User avatar
Electroguard
Posts: 835
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 267 times
Been thanked: 317 times

Re: Servo Problem

Post by Electroguard »

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.
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Re: Servo Problem

Post by mezjoc »

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

Post Reply