Shop OBEX P1 Docs P2 Docs Learn Events
Problems with BS2, Microcontrollers, Servos, and programming. — Parallax Forums

Problems with BS2, Microcontrollers, Servos, and programming.

Ian TaiIan Tai Posts: 3
edited 2009-05-13 20:54 in BASIC Stamp
Hi, my name is Ian Tai and I am part of Project Lead The Way (engineering program) at my high school. We are working on our senior project and we are using the Basic Stamp BS2 Board of Education, the Serial 8-servo Controller, and 5 Power HD Micro Servos. Our problem is described as follows.

Our project's Problem Statement: It is inconvenient to turn a page of sheet music while playing an instrument.

Basically we are designing something that turns the pages for you on a music stand. So our solution is a device that attaches to the music stand that has 5 pins. These 5 pins each attach to one sheet of music (at the top of each sheet), and turn one at a time from right to left, 180 degrees. Each pin has one servo motor. Thus we need to write a program that turns each motor one at a time controlled with a swtich.

A basic idea we were thinking of is:

Switch pressed one time,
Motor 1 turns 180 degrees and stops.
Switch pressed two times,
Motor 2 turns 180 degrees and stops.
etc....until
Motor 5 turns 180 degrees and stops.

And after all this, when the motor is pressed 6 times, it resets all motors to turn back to their original position, essentially -180 degrees.

That is our basic idea of what our program should be. However, we cannot even get a micro servo to turn.

What are we doing wrong?

Our setup is as follows:

We have a USB cable from the computer to the Board of Education and BS2. We have power to the Basic Stamp.

From the Basic Stamp we have a three wire cable running from pulsout 12 to the input and output of the Serial Servo Controller. (http://www.pololu.com/catalog/product/727)

On the Servo Controller we have one motor (http://www.pololu.com/catalog/product/1041) at this time, we're just testing one motor first. The motor is coming out from the serout number 0. We have power running to the Servo Controller at two spots. One to the servo power inputs and another to the VIN and GND of the actual controller.

We were sent a demo program previously (below) We ran it, but we saw no movement at all.

' {$STAMP BS2}
' {$PBASIC 2.5}


sdat PIN 12
baud CON 396
buff VAR Byte(3)



FindPSC:

DEBUG "Finding PSC",CR
SEROUT sdat,baud+$8000,[noparse][[/noparse]"!SCVER?",CR]
SERIN sdat, baud,500,FindPSC,[noparse][[/noparse]STR buff\3]
DEBUG "PSC ver: ", buff(0),buff(1),buff(2),CR
END





Long Story Short, we can't get any movement in the motor. What do we need to do to get movement in the Micro Servo?

Thanks.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-05-01 21:07
    First off, I would like to thank you for the full post with complete descriptions. If only every question were posed as so...

    Have you seen this page? http://www.pololu.com/file/0J41/stamp.pdf

    It appears that your baud is off. You probably want to use the constant 84, instead of two different values.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-01 21:36
    The Pololu servo controller should work at either Baud (using constants 396 or 84), but you have to connect the Stamp properly. Do you have the documentation for the controller (www.pololu.com/file/0J38/ssc04a_guide.pdf)? This describes in detail what the Pololu controller requires. It's not identical to the Parallax Servo Controller (PSC) and the PSC commands will not work with it. Pin 12 has to be connected to the Pololu controller's logic level serial input connection as well as ground (Vss) and power (Vin).

    Do not connect the logic level serial output connection to the same I/O pin as the logic level serial input. This can damage the servo controller. You can leave the logic level serial output connected unconnected or connect it to a different Stamp I/O pin.

    Follow the example shown in the link that SRLM provided.
  • Ian TaiIan Tai Posts: 3
    edited 2009-05-04 20:51
    Thanks for teh replies so far. We have looked, studied, memorized, and stressed over both of the links that were sent, and we still can't get things right.

    The problem might be the set up, so I am going to as specifically as I can describe how we have this set up.

    Basic Stamp
    1. USB cable from computer output to Basic Stamp USB input. This allows communication between our PBASIC program and the Basic Stamp.
    2. 9-volt battery powering the Basic Stamp.

    ServoController
    1. 6-volt battery pack powering the servo motors, with + and - correctly aligned.
    2 Servo motor output 0 going to a micro servo.
    3. Three-wire cable from Basic Stamp output 12 to 3 pins on servo controller: Black going into reset, middle wire (red) going into logic-level serial output, and orange wire going into logic level serial input.
    4. 6-volt battery pack powering the controller: black into neg and red into positive.

    When the basic stamp is off, all three LEDs on the servo controller are lit. When the Basic Stamp is turned to the 2 position, no LEDs on the servo controller come on.

    We then used the sample program from the Pololu site - serout 15,84,[noparse][[/noparse]$80,$01,$01,0,1] - and nothing happens. Nothing. No LEDs, no servo movement, nothing.

    Do we have a set up problem? Or are we just floating down the river with a waterfall in sight waiting for the inevitable?

    thanks.

    Ian
  • SRLMSRLM Posts: 5,045
    edited 2009-05-04 21:46
    I don't think you want to use the $80,$01,$01 for making the servo move. According to the link I posted, that is to set the speed. Try the code that is provided in the first link. Make sure that the pin number matches the connection:

    testloop:
    serout 15,84,[noparse][[/noparse]$80,$01,$04,0,13,127] 'set pos servo 0
    serout 15,84,[noparse][[/noparse]$80,$01,$04,1,13,127] 'set pos servo 1
    pause 10000
    serout 15,84,[noparse][[/noparse]$80,$01,$04,0,35,127]
    serout 15,84,[noparse][[/noparse]$80,$01,$04,1,35,127]
    pause 10000
    goto testloop
    
    



    Also, make sure that your jumper is in the right position for the mode that you're using, Pololu mode.
  • Ian TaiIan Tai Posts: 3
    edited 2009-05-13 20:33
    Hi again. We worked out a solution for our problem with the motors and hardware. However we are having problems with our program.

    We have already talked to a technician named Josh over the phone. And to make things easier we are going to post our program on the forum.

    Here is the current program we have. Please let us know if there is anything wrong with this. Our basic idea is we have four motors and one switch. When we press the switch once, we want motor 1 to turn, when we press the switch twice, we want motor 2 to turn, etc. up to motor 4.



    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    counter VAR Word
    counter = 0
    INPUT 4
    IN4 = 0

    Checking:
    IF counter = 1 AND IN4= 1 THEN
    GOSUB add
    GOSUB turn1

    ENDIF

    IF counter = 2 AND IN4= 1 THEN
    GOSUB add
    GOSUB turn2

    ENDIF

    IF counter = 3 AND IN4= 1 THEN
    GOSUB add
    GOSUB turn3

    ENDIF

    IF counter = 4 AND IN4= 1 THEN
    GOSUB add
    GOSUB turn4

    ENDIF

    add:
    counter = counter + 1
    RETURN

    turn1:
    PULSOUT 12, 500
    PAUSE 20
    GOTO Checking

    turn2:
    PULSOUT 13, 500
    PAUSE 20
    GOTO Checking

    turn3:
    PULSOUT 14, 500
    PAUSE 20
    GOTO Checking

    turn4:
    PULSOUT 15, 500
    PAUSE 20
    GOTO Checking
  • SRLMSRLM Posts: 5,045
    edited 2009-05-13 20:54
    Your code isn't very structured. You probably want to have a loop in there, otherwise it can just fall through. And if you're going to use GOSUB, you should probably use RETURN instead of GOTO.
Sign In or Register to comment.