More on the Bluetooth BS2sx issue
NWUpgrades
Posts: 292
OK, After playing around some with the following code, I am able to get the servos to turn, but only upon the first arrow push from the BoeBot Remote Control Program available here. http://www.parallax.com/Portals/0/Downloads/docs/prod/comm/30085_Easy_BluetoothSoftware.zip
I can get this to work with no problems with the BS2 module on a BOE Board (With Modified Baud and Servo_Speed). However, with the BS2sx module, when I run the BoeBot Remote Software, After I get a connection and Press any of the arrows, the Servos move, but then if I press stop or any of the arrows the program freezes and the servos stop turning. Any clues as to what might be going on?
' =========================================================================
'
'·· File...... Easy Bluetooth.bsx
'·· Purpose... Control a Boe-Bot with a GUI interface
'·· Author.... Technical Support & RoboTech SRL
'·· E-mail.... support@parallax.com
'·· Started... April 1st 2009
'·· Updated... N/A
'
'·· {$STAMP BS2sx}
'·· {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
' This program is what is loaded into the BASIC Stamp prior to using the GUI interface
' from RoboTech SLR. It allows a Boe-Bot to be controlled via a GUI interface.
'
' Commands are as followed:
'
'···· Up Arrow··· = Forward
'···· Down Arrow· = Backwards
'···· Left Arrow· = Left Turn
'···· Right Arrow = Right Turn
'···· Space Bar·· = Stop
'
' You can press and hold and release an arrow key for 2 seconds to access a double speed
' of each action. For example, Press Up Arrow, release to make the Boe-Bot move faster
' forward.
'
[noparse][[/noparse] I/O Definitions ]
BT_RX········· PIN···· 2···················· ' RX of the Easy Bluetooth
BT_TX········· PIN···· 0···················· ' TX of the Easy Bluetooth
LED··········· PIN···· 5···················· ' Indicator LED for Bluetooth Connection
'
[noparse][[/noparse] Constants ]
BT_SPEED······ CON···· 240·················· ' baud 9600 true UART
'
[noparse][[/noparse] Variables ]
tLeft········· VAR···· Word················· ' Left Servo control pulse durations
tRight········ VAR···· Word················· ' Right Servo control pulse durations
temp·········· VAR···· Word················· ' Temp variable
' Buffer array not declared as buffer VAR Word(5) for SERIN functionality.
' It can still be accessed as buffer(0), buffer(1), etc.· However,
' buffer0, buffer1, etc. should be used in SERIN commands with variations
' of WAIT.
· buffer0······· VAR···· Byte················· ' Buffer - Start char = $ff
· buffer1······· VAR···· Byte················· ' Message Index value
· buffer2······· VAR···· Byte················· ' Command
· buffer3······· VAR···· Word················· ' Argument 1 (return data 1)
· buffer4······· VAR···· Word················ ' Argument 2 (return data 2)
· buffer········ VAR···· buffer0·············· ' For standard array indexing
· msgIndex······ VAR···· Byte················· ' message index
· rxc··········· VAR···· Byte················· ' Receive Clear
'
[noparse][[/noparse] Initialization ]
Program_Start:
· LOW LED
· DEBUG CLS
· PAUSE 1000······················································ ' Wait for the RBT-001 radio to be ready.
· msgIndex = 0
· buffer0 = $FF··················································· ' Connection packet
· buffer1 = msgIndex
· buffer2 = $CC
· buffer3 = 100
· buffer4 = 100
· GOSUB Set_Servo_Speed
· DEBUG CR,"Waiting connection..."································ ' wait for connection request
· SERIN BT_RX, BT_SPEED, [noparse][[/noparse]WAITSTR buffer \ 3, buffer3, buffer4]··· '
'
[noparse][[/noparse] Program Code ]
DO
· SELECT buffer2
· CASE $CC························································ ' Connect
··· HIGH LED
··· msgIndex = 0
··· DEBUG CR,"Connected"
··· GOSUB Reply
· CASE $DD························································ ' Disconnect
··· LOW LED
··· DEBUG CR,"Disconnected"
··· GOSUB Reply
··· GOTO Program_Start
·CASE $11························································ ' Servo
·· DEBUG CR,"Servo"
··· GOSUB Set_Servo_Speed
··· GOSUB Reply
· CASE ELSE······················································· ' Error
··· buffer2 = $EE
··· GOSUB Reply
· ENDSELECT
·Resume:·························································· ' If Message not rcvd, try again
·PULSOUT 13, tLeft················································ ' Servo control pulses
·PULSOUT 12, tRight
·SERIN BT_RX, BT_SPEED, 10, Resume,······························· ' Get next command
····· [noparse][[/noparse]WAITSTR buffer \ 2, buffer2,
····· buffer3, buffer4]
·PULSOUT 13, tLeft················································ ' Servo control pulses again
·PULSOUT 12, tRight
·LOOP
·Reply:
· msgIndex = msgIndex + 1········································· ' Increment message index for reply.· Next message from PC has to use
· buffer1 = msgIndex·············································· ' reply's buf[noparse][[/noparse]1].
· SEROUT BT_TX, BT_SPEED, [noparse][[/noparse]STR buffer \5]
'
[noparse][[/noparse] Subroutines ]
Set_Servo_Speed:·················································· ' Range of 0 to 200 with 100 = stopped maps to 650 to 850 with 750 stopped.
· tLeft = buffer3 + 1775··········································· ' Decode servo speed.
· tRight = buffer4 + 1775
RETURN
'
[noparse][[/noparse] Data ]
ResetOnOff········· DATA 0········································ ' On/off toggle w/ Reset button
RequestConnect····· DATA $FF, 0, 1, 0, 0
ConnectionGranted·· DATA $FF, 0, 2, 0, 0
RequestCommand····· DATA $FF, 0, 3, 0, 0
ServoSpeeds········ DATA $FF, 0, 4, 0, 0
I can get this to work with no problems with the BS2 module on a BOE Board (With Modified Baud and Servo_Speed). However, with the BS2sx module, when I run the BoeBot Remote Software, After I get a connection and Press any of the arrows, the Servos move, but then if I press stop or any of the arrows the program freezes and the servos stop turning. Any clues as to what might be going on?
' =========================================================================
'
'·· File...... Easy Bluetooth.bsx
'·· Purpose... Control a Boe-Bot with a GUI interface
'·· Author.... Technical Support & RoboTech SRL
'·· E-mail.... support@parallax.com
'·· Started... April 1st 2009
'·· Updated... N/A
'
'·· {$STAMP BS2sx}
'·· {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
' This program is what is loaded into the BASIC Stamp prior to using the GUI interface
' from RoboTech SLR. It allows a Boe-Bot to be controlled via a GUI interface.
'
' Commands are as followed:
'
'···· Up Arrow··· = Forward
'···· Down Arrow· = Backwards
'···· Left Arrow· = Left Turn
'···· Right Arrow = Right Turn
'···· Space Bar·· = Stop
'
' You can press and hold and release an arrow key for 2 seconds to access a double speed
' of each action. For example, Press Up Arrow, release to make the Boe-Bot move faster
' forward.
'
[noparse][[/noparse] I/O Definitions ]
BT_RX········· PIN···· 2···················· ' RX of the Easy Bluetooth
BT_TX········· PIN···· 0···················· ' TX of the Easy Bluetooth
LED··········· PIN···· 5···················· ' Indicator LED for Bluetooth Connection
'
[noparse][[/noparse] Constants ]
BT_SPEED······ CON···· 240·················· ' baud 9600 true UART
'
[noparse][[/noparse] Variables ]
tLeft········· VAR···· Word················· ' Left Servo control pulse durations
tRight········ VAR···· Word················· ' Right Servo control pulse durations
temp·········· VAR···· Word················· ' Temp variable
' Buffer array not declared as buffer VAR Word(5) for SERIN functionality.
' It can still be accessed as buffer(0), buffer(1), etc.· However,
' buffer0, buffer1, etc. should be used in SERIN commands with variations
' of WAIT.
· buffer0······· VAR···· Byte················· ' Buffer - Start char = $ff
· buffer1······· VAR···· Byte················· ' Message Index value
· buffer2······· VAR···· Byte················· ' Command
· buffer3······· VAR···· Word················· ' Argument 1 (return data 1)
· buffer4······· VAR···· Word················ ' Argument 2 (return data 2)
· buffer········ VAR···· buffer0·············· ' For standard array indexing
· msgIndex······ VAR···· Byte················· ' message index
· rxc··········· VAR···· Byte················· ' Receive Clear
'
[noparse][[/noparse] Initialization ]
Program_Start:
· LOW LED
· DEBUG CLS
· PAUSE 1000······················································ ' Wait for the RBT-001 radio to be ready.
· msgIndex = 0
· buffer0 = $FF··················································· ' Connection packet
· buffer1 = msgIndex
· buffer2 = $CC
· buffer3 = 100
· buffer4 = 100
· GOSUB Set_Servo_Speed
· DEBUG CR,"Waiting connection..."································ ' wait for connection request
· SERIN BT_RX, BT_SPEED, [noparse][[/noparse]WAITSTR buffer \ 3, buffer3, buffer4]··· '
'
[noparse][[/noparse] Program Code ]
DO
· SELECT buffer2
· CASE $CC························································ ' Connect
··· HIGH LED
··· msgIndex = 0
··· DEBUG CR,"Connected"
··· GOSUB Reply
· CASE $DD························································ ' Disconnect
··· LOW LED
··· DEBUG CR,"Disconnected"
··· GOSUB Reply
··· GOTO Program_Start
·CASE $11························································ ' Servo
·· DEBUG CR,"Servo"
··· GOSUB Set_Servo_Speed
··· GOSUB Reply
· CASE ELSE······················································· ' Error
··· buffer2 = $EE
··· GOSUB Reply
· ENDSELECT
·Resume:·························································· ' If Message not rcvd, try again
·PULSOUT 13, tLeft················································ ' Servo control pulses
·PULSOUT 12, tRight
·SERIN BT_RX, BT_SPEED, 10, Resume,······························· ' Get next command
····· [noparse][[/noparse]WAITSTR buffer \ 2, buffer2,
····· buffer3, buffer4]
·PULSOUT 13, tLeft················································ ' Servo control pulses again
·PULSOUT 12, tRight
·LOOP
·Reply:
· msgIndex = msgIndex + 1········································· ' Increment message index for reply.· Next message from PC has to use
· buffer1 = msgIndex·············································· ' reply's buf[noparse][[/noparse]1].
· SEROUT BT_TX, BT_SPEED, [noparse][[/noparse]STR buffer \5]
'
[noparse][[/noparse] Subroutines ]
Set_Servo_Speed:·················································· ' Range of 0 to 200 with 100 = stopped maps to 650 to 850 with 750 stopped.
· tLeft = buffer3 + 1775··········································· ' Decode servo speed.
· tRight = buffer4 + 1775
RETURN
'
[noparse][[/noparse] Data ]
ResetOnOff········· DATA 0········································ ' On/off toggle w/ Reset button
RequestConnect····· DATA $FF, 0, 1, 0, 0
ConnectionGranted·· DATA $FF, 0, 2, 0, 0
RequestCommand····· DATA $FF, 0, 3, 0, 0
ServoSpeeds········ DATA $FF, 0, 4, 0, 0
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
As I've mentioned before, since this program runs with some minor changes on a BS2 and only misbehaves when run on a BS2sx, the problem can only be:
1) The BS2sx is defective somehow
2) You haven't made all the required changes (in PULSOUT values and Baud constants) to adjust for the difference in execution speed between the BS2 and BS2sx
3) There is something somehow subtle in the logic of the program that is timing sensitive and shows up because of the higher speed of the BS2sx.
I do notice that the Reply subroutine falls through to the Set_Servo_Speed subroutine. I don't know whether that is intended or a mistake. You might check the original source code. If there's a RETURN missing, there might be other errors as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
It is the BoeBot Remote Control Software that comes with this zip file.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
The PULSOUT unit on the BS2 is 2us. The PULSOUT unit on the BS2sx is 0.8us. The values of buffer3 and buffer4 range from 0 to 200. On the BS2, the time range (pulse width) for both tLeft and tRight is 1300us to 1700us (650 + buffer3 or 4 = 650 to 850). If you divide these by 0.8us, you get:
1300 / 0.8 = 13000 / 8 = 6500 / 4 = 3250 / 2 = 1625 and
1700 / 0.8 = 17000 / 8 = 8500 / 4 = 4250 / 2 = 2125
If you're converting PULSOUT values intended for a BS2, you need a conversion factor of:
2 / 0.8 = 20 / 8 = 10 / 4 = 5 / 2 which is the same as 5 >> 1
Set_Servo_Speed has to be:
tLeft = ((buffer3 * 5) >> 1) + 1625
tRight = ((buffer4 * 5) >> 1) + 1625
Generally, it's best to run a BoeBot off a 6V supply, either 4 alkaline cells or 5 NiMH cells. If you're going to run it off AC, I'd suggest a 6V or 7.5V 1A supply.
If you've been using Vin to power your servos and 9V for Vin, the excessive voltage can cause increased wear on the motor brushes and can theoretically damage the control circuitry inside the servo. If they're still working, the control circuitry is probably ok.
The "it" in "run it off AC" was intended to refer to the power supply itself, not the output to the BOE.
Post Edited (Mike Green) : 10/22/2009 7:25:36 PM GMT
When does the Easy Bluetooth loose connection? Do you get an error that states what caused the disconnect? The coding is one thing, however the disconnection shouldn't be happening at the hardware level. I have tried connecting to a BS2sx and have no had any issues communicating. Can you run the code attached to see if you can maintain connection between the BS2sx and the Easy Bluetooth?
Regarding the power supply suggestion; I would agree with Mike, the 7.5V 1A supply is what I use for about 95% of my projects.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com
If you open a DEBUG (ctrl+D) window from the BASIC Stamp Editor and select the COM the Bluetooth is on from the drop down; you can start typing in the white portion of the screen to sending data through the Bluetooth connection. The first byte is to establish communication and start the program, and then you should see "You Pressed [noparse][[/noparse]key]" appear in the DEBUG screen with the correct key that was pressed on the keyboard.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com