Monday, May 16, 2011

Talking to the Arduino via Bluetooth (using BlueSmirf modem)

This entry involves using Bluetooth to effectively communicate to an Arduino board using the command line.

Parts/Requirements:

Stage 1: Installing Bluetooth and discovering BlueSmirf

  • Plug in USB Dongle into computer- Bluetooth icon should appear in task bar
  • Click on Bluetooth icon, and adjust settings by clicking on Options>check "Turn Discovery On", "Allow Bluetooth devices to connect to this computer">Click Apply
  • Next, power up the BlueSmirf with Dongle connected to computer
  • Click on Bluetooth icon>Devices>Add..>Check "My device is set up and ready to be found"> Click "Next"
  • The Bluetooth should detect the device (name should come up as FireFly-<ID>), if it does not detect...Try different ways such as restarting the computer, adding the device again, and making sure the BlueSmirf has solid connections (I soldered it to headers)
  • If it installs properly, at the end of the Bluetooth wizard you should see something like this:
  • Make not of the Outgoing COM port, as that will be the port you use to communicate with the BlueSmirf and Arduino
  • The FireFly-BE11 (BE11 was what it was on mine) will show up under your Bluetooth devices
  • Then, you must connect the device to the computer.  Open up HyperTerminal: Start>Programs>Accessories>Communications>HyperTerminal
  • A prompt will pop up saying the device wants to connect to the computer...click on prompt.  It will ask for a password, type in 1234, and your device is paired! You do not have to do this again after the first time  (unless you remove the FireFly device from the Bluetooth device list)
Stage 2: Building the circuit and programming the Arduino
  • I soldered headers onto the BlueSmirf for good connections
  • See following picture for connecting circuit (Use P0 and P1 for Rx and Tx instead, and I used P3 as the port to control the LED)



  • Now unplug the BlueSmirf, connect the USB serial programmer from the computer to the Arduino, I used the following code:
int counter;
byte newbyte;

void setup() {
 Serial.begin(9600);
 pinMode(3,OUTPUT);
 digitalWrite(3,HIGH);
 delayMicroseconds(1000);
 counter=0;
 newbyte='h';
}

void loop() {
  
  // put your main code here, to run repeatedly: 
  if(Serial.available()>0){
    newbyte=Serial.read();
    if(newbyte=='h'){
      digitalWrite(3,HIGH);
    }
    else
      digitalWrite(3,LOW);
  }
  
  Serial.println(counter,DEC);
  counter++;
  delay(300);
}

  • Once the Arduino is programmed, unplug the USB connection and re-connect the BlueSmirf
Stage 3: Talking to the Arduino using the commandline

  • Power up the Arduino/BlueSmirf- red light should be blinking on the BlueSmirf
  • Open up HyperTerminal, follow the steps below:
Type in a name for the connection (I used "Bluetooth")
Under the 'Connect Using' menu, select the COM port that was the Outgoing COM port when installing the Bluetooth (can also check again by clicking on the Bluetooth icon>COM Ports Tab) and then click OK
  • Should see the counter in progress
    • Can enter command mode by pressing '$$$' followed by Enter
    • Exit command mode by pressing '---' followed by Enter
    • Can configure the BlueSmirf in command mode
  • Can turn the LED on and off by pressing any key to turn it off, and 'h' to turn it on
VIDEO DEMO OF STAGE 3:






NOTES FOR USING BLUESMIRF INTERFACE WITH ARDUINO:
Troubleshooting:
1. -Power up BlueSmirf


-Make connection through your Terminal (I used SimpleTerm Gold trial version) and get the green led
-Type "$$$" before 60 secs from the power up, and it should respond with "CMD" and the red LED will flash
-Type "H" -> Set commands
-Type "SU,57600" -> to change the baudrate and respond "AOK"
-Type "D" -> Display settings to see the new baudrate.
-Reboot the BlueSmirf to make the change happen.


2. Solder connections to Bluesmirf for good connections

3. Use Hyperterminal (TeraTerm did not work for me):

-Power Arduino and Bluesmirf on
-Connect to COM7 (the SPP COM port)
- $$$ -> command mode
- --- -> exit command mode
-Should bring up the counter from the arduino board
-Can type commands, will get sent to Arduino

2 comments:

  1. can explain me in detail pls i want make that?

    ReplyDelete
    Replies
    1. Sorry for the late reply ronk4rompy, what details do you need explained?

      Delete