Shop OBEX P1 Docs P2 Docs Learn Events
Servo and Basic Stamp 1 boards — Parallax Forums

Servo and Basic Stamp 1 boards

I have a Basic Stamp HomeWork Board (accepts bs2 code) as well as a Basic Stamp 1 Project Board (accepts bs1 code). With the Homework Board, the Parallax-supplied servo works as described in the book "What Is A Microcontroller." However, when the servo is connected to the Project Board, the servo moves in unexpected ways. I don't know if the PULSOUT commands are supposed to work the same way on both of these boards (with the bs1 and bs2 versions of the programming language). Rather than figure this out by trial and error I'm hoping somebody can describe how to use the servo with the Project Board and bs1. I want to be able to rotate the servo's horn both clockwise and counter-clockwise, through its full range of positions. Thanks in advance.

Comments

  • No trial and error needed.

    PULSOUT on BS1 is 10 usec units; BS2 is 2 usec units. So you need to adjust BS2 code by a factor of 5. 150 gets you center; limits are 120-180 or so.

    PAUSE is the same for both; units are 1 msec.

  • Thanks Tom. I'll give that a try.

  • Yep, that did it! With my Stamp 1 Project Board and servo the valid range for pulses appears to be 50 to 210.
    Here's a test program that slowly rotates the servo horn in both directions.


    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    ' July 14, 2021
    SYMBOL inner =W2
    SYMBOL counter =W3
    SYMBOL looper =W4
    SYMBOL width =W5
    SYMBOL pete =B0

    DEBUG "Program start", CR
    ' Working toward a jerkily turning dance stage for a Pete the Cat ...
    ' So the port is called 'pete'
    pete = 1
    FOR inner = 1 TO 5
    PULSOUT pete, 50
    PAUSE 20
    NEXT

    FOR looper = 1 TO 10
    DEBUG "Now starting counter-clockwise turn.", CR
    PAUSE 999
    FOR width = 50 TO 210 STEP 2
    DEBUG "Loop 1, width is ", width, CR
    FOR inner = 1 TO 5
    PULSOUT pete, width
    ' DEBUG "Width is ", width, CR
    PAUSE 20
    NEXT
    DEBUG "End of loop with width ", width, CR
    PAUSE 200
    NEXT
    DEBUG "Now starting clockwise turn.", CR
    PAUSE 999
    width = 212
    FOR counter = 50 TO 210 STEP 2
    width = width-2
    DEBUG "Loop 2, width is ", width, CR
    FOR inner = 1 TO 5
    PULSOUT pete, width
    ' DEBUG "Width is ", width, CR
    PAUSE 20
    NEXT
    DEBUG "End of loop with width ", width, CR
    PAUSE 200
    NEXT
    NEXT

  • Good job, Geezer

    Nice use of DEBUG statements.

    BTW, If my handle was Geezer, it would have to be Geezer1942. We old farts have to stick together. ;-)

  • WRT "We old farts have to stick together. ;-)" I agree. Thanks for the help and the complements on my code.
    I should have Pete the Cat dancing on top of a servo the next time I see my granddaughters. :-)

  • ercoerco Posts: 20,257

    @Geezer1948

    Re: "I should have Pete the Cat dancing on top of a servo"

    Even better, put Pete the Cat on a mobile platform and have him drive a figure 8. We've been having fun in that robotics thread for nearly ten years!

    https://forums.parallax.com/discussion/138125/ercos-figure-eight-challenge/p1

  • It's okay to do long delays if you don't have any load on the servo, but if you do, look out, there could be trouble. Some years ago I paid a visit to Legoland (near San Diego) and the complained that their BASIC Stamp controlled X-Wing fighter developed droopy wings. The culprit was:

      PAUSE 5000
    

    The wings put a load on the servos, and without being refreshed, the moved out of position. I showed them how to do something like this:

    ' {$STAMP BS1}
    
    SYMBOL  servoPin        = B2
    SYMBOL  msDelay         = W4
    SYMBOL  servoPos        = W5
    
    
    Main:
      GOTO Main
    
    
    ' Put delay time in msDelay
    ' Copy servo position to servoPos (2us units)
    ' Copy servo pin # to servoPin
    
    Servo_Pause:
      IF msDelay < 20 THEN SP_Exit
        PAUSE 19
        msDelay = msDelay - 20
        PULSOUT servoPin, servoPos
        GOTO Servo_Pause
    
    SP_Exit:
      PAUSE msDelay
      RETURN
    

    Problem solved, and they were delighted. Of course, I had a Propeller with me that day and I showed them some real fun!

Sign In or Register to comment.