help bluetooth terminal control boebot
this program is pretty much out of the book, everything works except when i wat to turn right the instruction to the servos fail, what ever pulse out command is first is sent to both servos, they work fine if you delet one or the other but will not work together bran new servos
' TerminalBoeBotControl_Keypad.bs2
' Moves the Boe-Bot based on the numbers 2, 4, 6, 8 or the
' letters A, W, D, X.
'control + d opens the debug window ( you must connect bluetooth and get the
' correct com port example com 5 look in stamps in class mini projects boe bot
' bluetooth
' {$STAMP BS2}
' {$PBASIC 2.5}
Piezo PIN 4
RX PIN 2 ' RX of the Easy Bluetooth
TX PIN 0 ' TX of the Easy Bluetooth
ltServo PIN 13 ' Left Servo Pin
rtServo PIN 12 ' Right Servo Pin
FwdLtFast CON 850 ' Left servo forward full speed
BwdLtFast CON 50 ' Left servo backward full speed
FwdRtFast CON 50 ' Right servo forward full speed
BwdRtFast CON 850 ' Right servo backward full speed
Baud CON 84 ' Baud set at 9600
myByte VAR Byte ' Byte to establish connection
index VAR Word ' READ index/character storage
character VAR Word
note1 VAR Word ' for peizo noise
x VAR Word ' for peizo noise
dirChar VAR Word ' Stores directional character
counter VAR Word ' Counter for FOR...NEXT loop
DO
' Recieve character from the PC
SERIN RX, Baud, [dirChar]
IF (dirChar = "8") OR (dirChar = "w") THEN
GOSUB Forward
ELSEIF (dirChar = "2") OR (dirChar = "x") THEN
GOSUB Backward
ELSEIF (dirChar = "4") OR (dirChar = "a") THEN
GOSUB Left
ELSEIF (dirChar = "6") OR (dirChar = "d") THEN
GOSUB Right
ELSEIF (dirChar = "5") OR (dirChar = "p") THEN
GOSUB noise
ENDIF
LOOP
Forward:
SEROUT TX, BAUD, [CRSRXY, 7, 0, "*", CRSRXY, 6, 1, "*", CRSRXY, 8, 1, "*"]
PULSOUT ltServo, FwdLtFast
PULSOUT rtServo, FwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 7, 0, " ", CRSRXY, 6, 1, " ", CRSRXY, 8, 1, " "]
RETURN
Backward:
SEROUT TX, BAUD, [CRSRXY, 7, 6, "*", CRSRXY, 6, 5, "*", CRSRXY, 8, 5, "*"]
PULSOUT ltServo, BwdLtFast
PULSOUT rtServo, BwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 7, 6, " ", CRSRXY, 6, 5, " ", CRSRXY, 8, 5, " "]
RETURN
Left:
SEROUT TX, BAUD, [CRSRXY, 3, 3, "*", CRSRXY, 4, 2, "*", CRSRXY, 4, 4, "*"]
PULSOUT ltServo, BwdLtFast
PULSOUT rtServo, FwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 3, 3, " ", CRSRXY, 4, 2, " ", CRSRXY, 4, 4, " "]
RETURN
Right:
SEROUT TX, BAUD, [CRSRXY, 11, 3, "*", CRSRXY, 10, 2, "*", CRSRXY, 10, 4, "*"]
PULSOUT rtServo, BwdRtFast
PULSOUT ltServo, FwdLtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 11, 3, "*", CRSRXY, 10, 2, "*", CRSRXY, 10, 4, "*"]
RETURN
noise:
FOR x = 1 TO 50 ' run about 5 seconds
RANDOM note1 ' create random note
note1 = note1 // 2000 ' don't let note go to high
FREQOUT 4,50,note1 ' play it
PAUSE 100 ' short pause between notes
NEXT
RETURN
' TerminalBoeBotControl_Keypad.bs2
' Moves the Boe-Bot based on the numbers 2, 4, 6, 8 or the
' letters A, W, D, X.
'control + d opens the debug window ( you must connect bluetooth and get the
' correct com port example com 5 look in stamps in class mini projects boe bot
' bluetooth
' {$STAMP BS2}
' {$PBASIC 2.5}
Piezo PIN 4
RX PIN 2 ' RX of the Easy Bluetooth
TX PIN 0 ' TX of the Easy Bluetooth
ltServo PIN 13 ' Left Servo Pin
rtServo PIN 12 ' Right Servo Pin
FwdLtFast CON 850 ' Left servo forward full speed
BwdLtFast CON 50 ' Left servo backward full speed
FwdRtFast CON 50 ' Right servo forward full speed
BwdRtFast CON 850 ' Right servo backward full speed
Baud CON 84 ' Baud set at 9600
myByte VAR Byte ' Byte to establish connection
index VAR Word ' READ index/character storage
character VAR Word
note1 VAR Word ' for peizo noise
x VAR Word ' for peizo noise
dirChar VAR Word ' Stores directional character
counter VAR Word ' Counter for FOR...NEXT loop
DO
' Recieve character from the PC
SERIN RX, Baud, [dirChar]
IF (dirChar = "8") OR (dirChar = "w") THEN
GOSUB Forward
ELSEIF (dirChar = "2") OR (dirChar = "x") THEN
GOSUB Backward
ELSEIF (dirChar = "4") OR (dirChar = "a") THEN
GOSUB Left
ELSEIF (dirChar = "6") OR (dirChar = "d") THEN
GOSUB Right
ELSEIF (dirChar = "5") OR (dirChar = "p") THEN
GOSUB noise
ENDIF
LOOP
Forward:
SEROUT TX, BAUD, [CRSRXY, 7, 0, "*", CRSRXY, 6, 1, "*", CRSRXY, 8, 1, "*"]
PULSOUT ltServo, FwdLtFast
PULSOUT rtServo, FwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 7, 0, " ", CRSRXY, 6, 1, " ", CRSRXY, 8, 1, " "]
RETURN
Backward:
SEROUT TX, BAUD, [CRSRXY, 7, 6, "*", CRSRXY, 6, 5, "*", CRSRXY, 8, 5, "*"]
PULSOUT ltServo, BwdLtFast
PULSOUT rtServo, BwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 7, 6, " ", CRSRXY, 6, 5, " ", CRSRXY, 8, 5, " "]
RETURN
Left:
SEROUT TX, BAUD, [CRSRXY, 3, 3, "*", CRSRXY, 4, 2, "*", CRSRXY, 4, 4, "*"]
PULSOUT ltServo, BwdLtFast
PULSOUT rtServo, FwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 3, 3, " ", CRSRXY, 4, 2, " ", CRSRXY, 4, 4, " "]
RETURN
Right:
SEROUT TX, BAUD, [CRSRXY, 11, 3, "*", CRSRXY, 10, 2, "*", CRSRXY, 10, 4, "*"]
PULSOUT rtServo, BwdRtFast
PULSOUT ltServo, FwdLtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 11, 3, "*", CRSRXY, 10, 2, "*", CRSRXY, 10, 4, "*"]
RETURN
noise:
FOR x = 1 TO 50 ' run about 5 seconds
RANDOM note1 ' create random note
note1 = note1 // 2000 ' don't let note go to high
FREQOUT 4,50,note1 ' play it
PAUSE 100 ' short pause between notes
NEXT
RETURN
Comments
If it's OK running one servo or the other, but not with both, then the battery is marginal (weak.)
Are those SEROUTs from out of the book?
SEROUTs take a lot of time and blow your servo routine refresh time (20ms limit.)
I put mine up on something like a stand (a cottage cheese container), so it doesn't move about, when I try figuring something out.
Write a little test program and just run/test one servo and test both, separately, that way.
I have experience with this stuff [ http://incredulist.blogspot.com/p/cypherbot_23.html ]
I'm not keen on the "9V battery" or the SEROUTs, but if they're "in the book"...
it's not sending "6" or "d"
or
it's not branching to Right with a "6" or "d"
???
In three of the direction examples, Backward, Forward, and Left, the order is:
PULSOUT ltServo, constant
PULSOUT rtServo, constant
but with Right, you have:
PULSOUT rtServo, BwdRtFast
PULSOUT ltServo, FwdLtFast
Is that how it is shown in the W-a-M book? The order shouldn't make a difference, and I guess they're getting plugged with the right values. The inconsistency strikes me as odd, perhaps telling - and Right is where the problem lies. Is what you have pasted here exactly what you have cut&pasted into the IDE and Saved to the BS2?
Walkin79, Did you swap the Servos from 12 to 13 and vice versa to see what happens?
I am thinking you may have a bad pin on your Servo inputs. I just plugged in 4 Ea. rechargeable batteries, each of which had 1.46 volts and this still worked fine for me.
I would wire the right servo to the breadboard and change the pin to see if that works.
The only thing I see in the code is that the laset SEROUT line contains "*" whereas the preceding 3 last lines do not. However, it works this way for me whether the * is there or not.
but anyway There's a lot of difference between a "9V battery" and a 9V "battery pack".