Simple servo question

sbscott

Senior Member
I am sure there is an easy answer to this. Using the manual's sample code to move a micro servo arm from one range end to the other works fine. How do I stop it in the center between range ends. I have tried 'servopos 3,165'. This puts it in the center but then goes back to the first position...

</>
init: servo 3,75 ; initialize servo
main:
servopos 3,75 ; move servo to other end
pause 2000
servopos 3,165 ; move to center
pause 2000
servopos 3,255 ; move servo to other end
pause 2000
goto main
</>
 
Hi there,
I thought I'd try your code as written - I copied and pasted into PE6, with only the need to change the pin number as I'm using an 08M2.
The code appears to run fine, with the servo moving to each position (first end, middle, other end), pausing for 2 seconds between each position, and then repeating the whole cycle.
Not sure why yours would return to first the end directly after the mid point, sorry I cant be more help.
 

sbscott

Senior Member
Hummm? Yep, looks straight forward. Maybe its the servo. I will check. Thanks for your quick response!
 

sbscott

Senior Member
I tried a MG996R and it still is doing the same, goes to the midpoint and then returns to the starting point?
 

hippy

Technical Support
Staff member
Two possibilities I can think of -

The power supply is collapsing in some manner once it reaches half way, causing the PICAXE to reset and restart from the beginning.

That a position of 255 is causing some problem.

Perhaps try with 200 instead of 255. That should at least move it from half way to further along. If not I'd be suspecting the first possibility. Putting some SERTXD commands in the code will allow you to determine if the PICAXE is being reset, restarted, tell where it is getting to.
 

sbscott

Senior Member
Actually, I ended up putting an additional 'servopos b3,160' at the end and reduced from 255 to 240 on the second servopos and it worked as I had planned. Not sure why I could not do as I had originally planned..but all is well that ends well!! Thanks for everyone's help!
 
Top