Shop OBEX P1 Docs P2 Docs Learn Events
RN-42 Bluetooth Communication Guidance — Parallax Forums

RN-42 Bluetooth Communication Guidance

Adam_KarlstedtAdam_Karlstedt Posts: 1
edited 2015-10-13 18:47 in BASIC Stamp
I would like to preemptively apologize for my ignorance in this matter, especially given the vast knowledge that is in these forums; however, I have only fairly recently became acquainted with Bluetooth communication and am having difficulties figuring out the syntax for utilizing sent and received information for my module. I am currently connecting the RN-42 to my phone and am using a Bluetooth terminal that allows me send ASCII and hex data as well as see a response. I have been successful with commencing command mode and executing the "D" get command, along with a few other basic commands and going into "fast-data mode," so I know that the communication is working the way it should. All that I am trying to do is 1.) Establish a variable on my BoE Bot 2.) Get my phone to change that variable to a specified one and 3.) Have my BoE recognize the change and go to a corresponding subroutine based on the variable. My simple question is: How would I get my phone to change the variable, and would I need to have special integration that into my main DO-LOOP to anticipate the change. I'm sorry if my wording is confusing, and if nothing else I would love any sample code I could be directed to. My end game is a phone-controlled BoE Bot.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
  • Mike GreenMike Green Posts: 23,101
    edited 2015-10-13 19:59
    Look at the product page for the RN-42 on Parallax's webstore (here). You'll find documentation on the RN-42 as well as sample code for the Stamp (BoE Bot). Essentially the RN-42 acts as a wireless serial connection and you use the SERIN and SEROUT statements to send commands to the RN-42 and receive and send data to the Bluetooth terminal program.
  • The main problem you'll run into is communicating with the phone at the same time as your main DO-LOOP is doing its thing. Unfortunately, when the Stamp is looking for serial data from the RN-42, it stops doing anything else. There's no buffer.

    Protean Logic may still be selling their serial input buffer. Check with them. It would solve this problem. With one of these, your main DO-LOOP could quickly check for waiting characters and only try to read them if there's something available. You'd type some kind of lead-in character like a "?" followed by a value like "523" followed by a space or carriage return using your phone and the Stamp could read the value using a SERIN statement which would discard the terminating space or return. Instead of a "?", you could type a letter and your Stamp program could use the letter to select from a list of subroutines to execute using an ON <char> -"A" GOSUB ... statement where <char> is the received character value.
Sign In or Register to comment.