Shop OBEX P1 Docs P2 Docs Learn Events
help with stamp code for bluetooth — Parallax Forums

help with stamp code for bluetooth

vw_gtivw_gti Posts: 10
edited 2009-06-02 17:58 in BASIC Stamp
i need it so when a bluetooth device is conected i need to have a output for a second thend when it disconects it would use output 2 for a secound
if anyone can help

thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-15 18:12
    What do you know? Do you already know how to program a Stamp? Have you read the documentation for Parallax's Easy-Bluetooth? Do you understand it? Have you looked at the sample code for the Easy-Bluetooth? Do you already have the EB500 Bluetooth adapter (which is now discontinued)?

    The EB500 and Easy-Bluetooth adapters have a mode where they will automatically connect to a paired Bluetooth device and look like an ordinary full duplex serial connection to the Stamp and PC. There's normally no indication to the Stamp that a connection has been made other than that the Easy-Bluetooth will begin to deliver serial characters to the Stamp from the PC (and vice versa). There are commands that the Stamp can send to the Easy-Bluetooth adapter that are in the documentation that will return connection status, but that's more complicated and not something to do as a "first project".
  • GeorgeLGeorgeL Posts: 131
    edited 2009-05-15 22:25
    Bluetooth is rather easy, but as Mike says, its not good for first project. Either way, I have made a few good guides on here for Bluetooth, and specifically into a VB.net project.

    http://forums.parallax.com/showthread.php?p=806358
  • vw_gtivw_gti Posts: 10
    edited 2009-05-15 22:45
    I know very little about programing stamps but I need this for a school project can't anyone please help me
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-16 00:26
    First you need to learn about programming Stamps. Start with "What's a Microcontroller?" and the Parallax Basic Stamp Syntax and Reference Manual, both downloadable from Parallax. Go to the main webpage and click on the Resources tab. Click on the Downloads link, then the Stamps in Class Downloads link and you'll see a list of the tutorials available.

    You'll have to learn how to program this yourself. It would be cheating for one of us to write a program for you, but people will be willing to give you advice and to help you to understand things.

    Download the documentation for the EB500. Go to Parallax's webstore and search for 'EB500'. On the webpage for the product, you'll see a list of links for documention and sample programs. Even though the Easy-Bluetooth is different from the EB500, the same ideas apply and I think the EB500 documentation is easier to understand.

    It would be helpful if you would describe what you have available in terms of equipment.
  • vw_gtivw_gti Posts: 10
    edited 2009-05-16 04:22
    For equitment I got the eb500 and the basic stamp development bored I don't think I need anything else bit thanks everyone for giving a good idea were to start out but If I get stuck can someone please push me in the right dorection
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-16 04:44
    Page 38-40 of the EB500 documentation shows how to manage a connection from a Stamp with an EB500 to a PC.

    Page 10 talks about the pins on the EB500 and what they're for. In particular, pin 8 (Stamp I/O pin 5) tells you whether or not there's a connection.
  • GeorgeLGeorgeL Posts: 131
    edited 2009-05-16 05:48
    Did you check out the guide I wrote up (link I put above). That should really jump start your project.
  • vw_gtivw_gti Posts: 10
    edited 2009-05-18 17:35
    im sorry i told you i had the other one the one thats not discontinued but definitly when i looked at the page numbers you had gave me it looks like after i fugure out what pin nuber it is it should take me know time
  • vw_gtivw_gti Posts: 10
    edited 2009-05-19 14:05
    i think i did this right some one please check it for me

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

    {$STAMP BS2}
    '
    [noparse][[/noparse] I/O Definitions ]

    lock PIN 8 ' Lock output
    unlock PIN 9 ' unlock output
    '
    [noparse][[/noparse] Constants ]

    Pdelay CON 500 ' delay 500 milliseconds




    'Wait for the eb500 radio to be ready
    PAUSE 1000

    'Connect to the remote device
    SEROUT 1,84,[noparse][[/noparse]“CON 00:24:36:6C:F4:E3”,CR]
    SERIN 0,84,[noparse][[/noparse]WAIT(“ACK”,CR)]

    'Wait for the connection to be established and switch to data mode
    WaitForConnection:
    IF IN5 = 0 THEN WaitForConnection
    IF IN5 = 1 THEN HIGH unlock
    PAUSE Pdelay
    LOW unlock
    THEN IF IN5 =0 THEN HIGH lock
    PAUSE pdelay
    LOW unlock
    GOTO Main
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-19 14:26
    Try compiling it. You'll find some errors. Correct those, then look at your program again.
    When you're done, post it again.
  • vw_gtivw_gti Posts: 10
    edited 2009-05-19 17:01
    i think i got the errors out but im not sure if its correct but i took a good educated guess

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

    '
    [noparse][[/noparse] I/O Definitions ]

    lock PIN 12 ' Lock output
    unlock PIN 15 ' unlock output
    RX CON 2 'Receive Pin
    TX CON 0 'Transmit Pin
    Baud CON 84 '9600 Baud

    '
    [noparse][[/noparse] Constants ]

    Pdelay CON 500 ' delay 500 milliseconds


    main:

    'Wait for the eb500 radio to be ready
    PAUSE 1000

    'Connect to the remote device
    SEROUT 1,84,[noparse][[/noparse]"CON 00:17:A0:01:57:F7",CR]
    SERIN 0,84,[noparse][[/noparse]WAIT("ACK",CR)]


    WaitForConnection:
    IF IN5 = 0 THEN WaitForConnection



    IF IN5 = 1 THEN HIGH unlock

    PAUSE Pdelay
    LOW unlock
    IF IN5 =0 THEN HIGH lock
    PAUSE pdelay
    LOW unlock
    GOTO Main
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-19 17:13
    IF IN5 = 1 THEN HIGH unlock
    
    PAUSE Pdelay
    LOW unlock
    IF IN5 =0 THEN HIGH lock
    PAUSE pdelay
    LOW unlock
    
    


    Some comments ...
    IF IN5 = 1 THEN HIGH unlock

    You don't need the IF IN5 = 1 THEN at this point in your program since IN5 has to be 1. The previous IF statement guarantees it

    After the 1st LOW statement, you need to wait for the connection to go away. Do the same thing that you did starting at WaitForConnection, just do the opposite ... WaitForNoConnection.

    Notice that your last LOW is for unlock, not lock.

    The GOTO Main doesn't have to go back to the beginning of the program. The SEROUT and SERIN only has to be done once at the beginning.

    This is what is known as a State Machine. The program spends part of its time in one section, then, when something happens, it switches to another section of the program where it sits until something else happens. Then it goes back to the first section. Each section provides a "state" and the "something happens" is the transition condition from one state to another. You can have very complex State Machines with lots of states and all sorts of transitions from one state to another. Do a web search for "Wiki State Machine" for an explanation and examples.
  • vw_gtivw_gti Posts: 10
    edited 2009-05-20 04:37
    thanks alot man but a question i had was the outputs are they correct because im not sure when i try to see if they had a voltage at the pins i defined the outputs its a negative voltage
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-20 04:48
    You would not get a negative voltage from the I/O pins unless you have your meter hooked up backwards. The only voltages possible are 0V (or slightly higher) and just under +5V. This is measured with respect to ground (also called Vss). HIGH will make the I/O pin approximately +5V and LOW will make the I/O pin approximately 0V. INPUT will make the I/O pin an input and a high impedance where it reflects whatever it's connected to (between 0V and +5V). Never connect an I/O pin directly to a negative voltage or a voltage above +5V (unless it's through a high value resistor that limits the current to less than 500uA).
  • vw_gtivw_gti Posts: 10
    edited 2009-06-02 17:58
    just wondering i still cand get this to work but is the program correct im not sure
Sign In or Register to comment.