Shop OBEX P1 Docs P2 Docs Learn Events
RN-42 Bluetooth with Prop Quickstart board (Simple IDE C program) — Parallax Forums

RN-42 Bluetooth with Prop Quickstart board (Simple IDE C program)

twm47099twm47099 Posts: 867
edited 2014-03-03 17:18 in Accessories
I've attached an RN-42 module to my Propeller QuickStart Board and to my Activity Bot. At this point I've tested Spin programs from Gadget Gangster http://www.instructables.com/id/How-to-use-Bluetooth-with-your-Propeller/ to control a Led and a servo, and wrote a C program (using SimpleIDE) for toggling the Leds on the QS Board and an RGB Led attached to that board. While these are just demos, they give a simple approach for remote control using Bluetooth.

The stock BT programs I've found all use 9600 baud. The RN-42 module has a default baud rate of 115200bps. So the Gadget Gangster programs need to have the baud changed. He recommends the Sena BTerm app as the Android software.
https://play.google.com/store/apps/details?id=com.sena.btermon


This app is a simple VT-100 Terminal emulator and once paired it is quick to connect to the module. To keep things simple, I just use 1 key commands on the tablet. I am using the sparkfun RN-42 module which fits in the XBEE socket on the Prop Activity Board (Parallax didn't have any BT devices in stock when I bought mine). I expect that the Parallax RN-42 will also work since I only use the Vin, GND, RX and Tx pins.

Tom

Here's the C code:
/*   Blut.c
   Demo of control of QuickStart board using RN-42 Bluetooth adapter 
     and SenaBTerm app (https://play.google.com/store/apps/details?id=com.sena.btermon)
     on my Samsung Galaxy Tab 2.  
   The Bluetooth pins I am using are DIn (or Rx) on the module to prop pin 24, Dout (or Tx) to pin 25.
     Note that TX on the module is Rx on the Prop and in the fdserial_open command, and BT Tx = Prop Rx  
   Entering numals from 1 through 8 on Tablet softkeyboard toggles
    LEDs on pins 16 through 23 of QS board.
   Entering r, b, g (lower case) toggles the RBG pins on a
    common anode RGB LED on pins 12 (R), 13 (B), 14 (G)
   Entering 'q' ends the program and turns off LEDs and then sets pins to input.
  
 */
 #include "simpletools.h"                      // Include simple tools
 #include "fdserial.h"
 

 fdserial *blut;
 

 int main()
 {
     // fdserial * fdserial_open(int rxpin, int txpin, int mode, int baudrate)
   blut = fdserial_open(25, 24, 0, 115200);    
   char c;
   c = 0;
     // set_directions (int endPin, int startPin, unsigned int pattern)
   set_directions(26, 16, 255);      // pins 16 - 26 to output 
   set_outputs(14, 12, 7);           // set common anode LED 'grounds' to high - LED off
   set_directions(14, 12, 7);        // pins 12 - 14 to output
   while(c != 113)                   // Until 'q' is pressed
   {
     dprint(blut, "Enter 1 - 8 r b or g, \n");   // send text to the android device
     c = fdserial_rxChar(blut);                   // read a character from the android device
     switch(c)                       // c will contain ASCII value
      {
       case 49 :  toggle(16);       // ASCII 49 = number 1
         pause (100);
         break;
       case 50 :  toggle(17);       // number 2
         pause (100);
         break;
       case 51 :  toggle(18);       // number 3
         pause (100);
         break;
       case 52 :  toggle(19);       // number 4
         pause (100);
         break;
       case 53 :  toggle(20);       // number 5
         pause (100);
         break;
       case 54 :  toggle(21);       // number 6
         pause (100);
         break;
       case 55 :  toggle(22);       // number 7
         pause (100);
         break;
       case 56 :  toggle(23);       // number 8
         pause (100);
         break;
       case 114 :  toggle(12);       // ltr r
         pause (100);
         break;
       case 98 :  toggle(13);       // ltr b
         pause (100);
         break;
       case 103 :  toggle(14);       // ltr g
         pause (100);
         break;
       case 113 :                   // ltr q
         break; 
     default :   break;
     }      
   }

       set_outputs(14, 12, 7);     // turn off rgb Led
       set_outputs(26, 16, 0);     // turn off QS Leds
       set_directions(26, 16, 0);  // set pins to input
       set_directions(14, 12, 0);
       dprint(blut, "Done, \n");  
 }



Sign In or Register to comment.