Shop OBEX P1 Docs P2 Docs Learn Events
More on the Bluetooth BS2sx issue — Parallax Forums

More on the Bluetooth BS2sx issue

NWUpgradesNWUpgrades Posts: 292
edited 2009-11-04 18:08 in BASIC Stamp
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
«1

Comments

  • dandreaedandreae Posts: 1,375
    edited 2009-10-08 15:23
    I have to ask the obvious, did you verify that·the I/O pins on the BS2sx are working regarding I/O pins 12 and 13?

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-08 16:58
    I assumed that since it is partially working that yes they are, but how would I confirm for sure?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-08 17:03
    Attach LEDs to the pins (with 330 Ohm series resistors) and download a short program that blinks the LEDs (makes them HIGH for 1/2 second, then LOW for 1/2 second). You want to try the LEDs first connected to +5V, then connected (in reverse) to ground. This way, you'll test both the high state driver and low state driver.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-08 19:44
    It seems you have accounted for the baud rate change on the BS2sx, but have you account for the difference in the PULSOUT timing for the servos and the PULSIN timing from the remote?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-09 20:11
    I did for the Pulsout, But have no control for the Remote, as it is packaged with the software at the link I provided.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-09 20:24
    Chris probably forgot that the PC is handling the Remote. He was referring to typical Stamp code for receiving IR remote codes which uses the PULSIN statement for timing the IR pulses. Your program doesn't use PULSIN.

    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.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-10 04:08
    Thanks Mike. I have not gotten around to checking the Stamp yet, but am hoping to do that tommorrow or the next day. As for the code, I basically just used the original code designed for the BS2 and modified the Pulsout and Baud rate, so nothing has changed there. I will let you know what I find out after testing the Stamp pins 12 and 13.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-10 17:37
    Perhaps you have some code I am not familiar with. I know we have code where the remote is handled within the BASIC Stamp code on the robot. Apparently you have code where the PC is handling the remote?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-11 04:55
    http://www.parallax.com/Portals/0/Downloads/docs/prod/comm/30085_Easy_BluetoothSoftware.zip

    It is the BoeBot Remote Control Software that comes with this zip file.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-16 01:38
    I finnally got around to testing Pin 12 and Pin 13 on my BS2SX chip and they are functioning correctly. Is it possible that the BoeBot Remote Control Program only works with the BS2 chip? Has anyone else had the same or similar issues?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-16 01:51
    The BoeBot Remote Control Program has no way of knowing what is on the other end of the "conversation". The only time a Stamp identifies itself is during the download process for a new program (or the identify function which is effectively a download without changing anything).
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-16 01:54
    So, Any idea as to what the problem might be.
  • FranklinFranklin Posts: 4,747
    edited 2009-10-16 05:27
    Could you attach the actual code you are running using the attachment manager?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-16 15:44
    OK, So here is the original .bs2 file, my modified .bsx file and the .zip file that contains the BoeBot Remote Control software and the Mobile Software.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-16 18:27
    You uploaded two copies of the BS2sx version.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-16 21:52
    Sorr about that. Here is the correct .bs2 file
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-16 22:50
    As far as I can tell, the problem still is that you haven't converted the timing values correctly. In particular, in Set_Servo_Speed:

    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
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-17 00:35
    This did not work either. I establish a BT connection and run the Remote Program. It connects but as soon as I press an arrow I lose the connection. Also, If I disconnect my Serial cale on Com 1, it will also lose the connection. However, the BT device shows connected on Com 40
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-17 03:08
    Well, there's nothing obvious in your program that would account for the difference between the BS2 and the BS2sx. The only other thing to think about would be power. The BS2sx draws more power (60mA) than the BS2 (3mA), but that doesn't go through the BOE regulator. The Stamp is powered directly from Vin. Maybe if Vin is on the high side, the BS2sx's regulator is getting too hot and shuts down.
  • AJ ScottAJ Scott Posts: 9
    edited 2009-10-17 23:41
    Have you exceeded 6 volts as a Vin for the servos? If so the servo's circuitry is possibly backfeeding the stamp's Vcc through the output driver protection diodes.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-22 18:32
    Is it safe to use a 9V 500 ma power supply on the BOE or not?
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-10-22 18:46
    It's safe, but that assumes you're NOT using Vin for the Servo Power connection (9 volts is too high for servos). Also, two servo's can take 500 mA when turning -- so you may be getting "brown-out" resets in your BS2sx.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-22 18:46
    It depends. The BOE itself is fine with a 9V supply although the regulator will get hot if you're drawing a lot of current through it since a 9V Vin will require the regulator to drop 4V. If you're drawing close to 1A, that's 4W of heat that has to be dissipated. Remember that servos can draw over 1A peak, particularly if heavily loaded. Two servos both stalled could draw on the order of 2A which would cause the regulator to shut itself down. This assumes that you're powering the servos from the regulated +5V supply. If you're powering the servos from Vin, the 9V supply will damage them. They're intended to be run from at most a 7.2 or 7.5V supply and will not last as long on that as they would from a 6V supply.

    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.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-22 19:12
    OK. So if I use a 7.5V 1.5A would that be a better route?
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-22 19:14
    Mike, The power is DC from the power supply, not AC.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-22 19:20
    Yes

    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
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-22 19:34
    Got it!! I have been using 4 1.5V rechargeable batteries. I am still having the issue with the Remote Control program not working correctly, but it seems if I can get some motion, but not all. I was thinking if I upped the juice just a little that maybe it would solve the problem.
  • JDJD Posts: 570
    edited 2009-10-22 19:55
    NWUpgrades,

    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
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-22 20:14
    The connection seems to get lost shortly after the servos go forward or reverse. I do not get any errors. As for the attached program, I can send it to the stamp, but no Debug terminalcomes up.
  • JDJD Posts: 570
    edited 2009-10-22 20:23
    NWUpgrades,

    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
Sign In or Register to comment.