Modified Easy Bluetooth code
NWUpgrades
Posts: 292
Does anyone have a modified version of EasybluetoothPBASIC.bs2 that will work on the BS2sx chip? I have been beating my brains out for 2 days trynig to modify it to get it to work and can not seem to nail it down. Thanks for any help.
Comments
Did you change the baud rate to match the BS2sx chip?
I haven't downloaded the .bs2 program in question but I can do that later.
Jim
t1200 con 2063
t2400 con 1021
t4800 con 500
t9600 con 240
t19k2 con 110
t38k4 con 45
Interesting Note:
Baud Rate 8-bit No Parity INVERTED 8-bit No Parity TRUE 7-bit Even Parity INVERTED 7-bit Even Parity TRUE
4800 * 17197 813 25389 9005
9600 * 16780 396 24972 8588
* The BASIC Stamp 2sx and BASIC Stamp 2p may have trouble synchronizing with the incoming serial stream at this rate and higher due to the lack of a hardware input buffer. Use only simple variables and no formatters to try to solve this problem.
Jim
' =========================================================================
'
'·· File...... Easy Bluetooth.bs2
'·· 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···· Byte················· ' Argument 1 (return data 1)
· buffer4······· VAR···· Byte················· ' 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 = 250
· buffer4 = 250
· 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 + 1625··········································· ' Decode servo speed.
· tRight = buffer4 + 1625
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