Tuesday 17 April 2012

Beginning Blue Tooth

I did my first bits of work on the blue tooth connection today. I'm using a FirePlug RN-USB-X blue tooth dongle along with a BlueSMiRF Modem connected to the Arduino.

BlueSMiRF modem
This is probably my favourite gadget so far - it's so neat and simple. It has it's address printed on the top so is easy to connect to, and acts just like a standard serial connection to the Arduino. Thus I can use the SoftwareSerial library with it, just like I did with the SpeakJet,which also communicated over a serial connection.

RN-USB-X dongle in my PC
The RN-USB-X is a very clever piece of kit in a very simple shell, ideal for robot builders anywhere. On connection it behaves exactly like a serial port - all setup is done by communicating with it via hyper terminal. Normally this would be annoying, but for robot making it's perfect, as I don't need any fancy software and I can write programs to configure it very easily (they just have to send text down the COM port). I spent a while getting it working, but that was mainly because the manual was hard to find and I initially tried to get one of the various Blue Tooth management apps that most dongles require. Serves me right - never look for the complicated answer first :)

One thing to remember if you get one of those dongles. The default baud rate for the modem is 115200 - make sure you set this in hyper terminal or it won't communicate.

Anyway, I get the dongle working and can talk to it via hyper terminal (you enter $$$ and it switches into config mode). Now it's time for the modem to be connected to the Arduino. It's got 6 pins:

  • Serial receive
  • Serial send
  • Serial ready-to-send
  • Serial ready-to-receive
  • Vcc
  • GND
Before trying anything fancy I just connect the GND and Vcc up so the modem has power. In theory I should now be able to connect to to it from my dongle plugged into the PC. Once powered up the LED flashes red, so I go back to hyper terminal. After a bit of reading documentation I type:

$$$
SR,80085389029383CC
SM,1
C

Obviously :) In english that's apparently enter config ($$$), set the receiver address (printed on the modem), set mode to 1 (master) so it can connect to things and finally 'C' to connect. To my amazement the LED on the modem turns green. Hurray!

The ready-to-send and ready-to-receive aren't essential, so if you don't bother with them (which I'm not), you just connect them together - that's the job of the blue cable in this close up:



The serial receive and serial send (yellow/green) connect to IO pins so the Arduino can communicate with the modem. Everything is now wired up and I've got a connection from PC to modem. Time for some Arduino code - this is a cut down version of my test:

#define bluToothRx 11
#define bluToothTx 12

SoftwareSerial bluTooth(bluToothRx,bluToothTx);

void setup()
{
Serial.begin(9600);   
bluTooth.begin(9600); 
}

void loop()
{
while(bluTooth.available())
{
Serial.write(bluTooth.read());
}
}

The idea is to send messages out to the Arduino over blue tooth, which then transmits it back over the serial connection to the PC. What I'm expecting is:
  • I type a message in hyper terminal
  • The message is sent through the blue tooth (disgused as a normal COM port) to the modem
  • The modem receives it, and passes it to the Arduino
  • The Arduino receives it, and sends it over the USB (serial) connection to the PC
  • Finally, the message finds it's way to the serial monitor in the Arduino which prints my message! 
Sounds like a lot of work to type in one window and see it appear in another, but if it works I know I can communicate over blue tooth.

It kind of works. When I run it and type a character in hyper terminal the signal gets piped into the Arduino, which then pumps it back to the PC. Unfortunately somewhere along the way all the characters are being changed to 255. Then it occurs to me that baud rate was an issue when getting hyper terminal to talk to the modem, so maybe that's the issue here. I take a guess that it's the same as the PC one (115200) , so my final code is:

void setup()
{
Serial.begin(9600);   
bluTooth.begin(115200); 
}

And lo and behold - it works! Here's a video to prove my awesome blue tooth message transceiver actually exists:


That's all for now. Next up - controlling the robot over blue tooth.

-Chris



No comments:

Post a Comment