Bluetooth Stuff
Bluetooth Suff
OK, so I have a project where I want to have a mobile robot I want to connect with. So I figure I had better get to grips with Bluetooth!
Bluetooth seems like a good choice for this project because I may ultimately want to use my android phone as a controller. The Android SDK allows use of the phone's Bluetooth hardware so I should be able to lash up something at that end - so that just leaves the mbed end of things.
Bluetooth hello world
Luckily for me Chris has written a Cookbook page on using the RN-42 Bluetooth module.
So I get myself a module a RN-42 module from Cool Components which arrives after a few days and 'dead bug' it upside down to a bit of strip board. I modify Chris's design slightly and add in two status LEDs so I can see what the module is doing. I also add a Molex header so I can quickly disconnect the module. After I'm finish it looks like this...
Hello World!
So After loading the Hello World program from the Cookbook page onto the mbed I set about powering up the RN-42 module. It is connected exactly the same as shown on the cookbook page. So I plug it all in and the red LED starts flashing - what does that mean? Well looking at the datasheet doesn't help at all! It just says that the Status LED blinks at various speed to indicate status. OK so flashing red means... something?
So next I had better plug my Bluetooth dongle into the laptop. Through Windows I 'add a device' from the Bluetooth menu and the PC scans for devices - and finds an device named RN42-095F! Awesome. I connect to the device and it asks for a pairing code. I remember form the Cookbook page that the pairing code is 1234, so I enter that and Windows connects and installs a driver. So far so good.
Windows then tells me that my device is ready to use. Clicking on the installation I now see that I have two new 'Standard Serial over Bluetooth links' set as COM31 and COM32. I fire up Tera Term and connect over Serial to COM31, and then notice that the red LED on the RN-42 booard has gone off and the green LED is on. That has to be a good sign right?
I then set the baud rate to 115200, and start typing. I see the characters echoed back to the terminal and LED1 on the mbed flashing away merrily. Cool that was quite painless now for something else...
Hello Android
So I can communicate with a PC but can I communicate with a mobile phone?
I turn on Bluetooth on my Sony X10i and scan for devices - once again the RN-42 is picked up. Again when I try to pair with it it asks for a pair code. I enter 1234 and the phone has successfully paired with the RN-42 module. So far so good.
But now it is showing up as paired but not connected. So how do I connect to it? I decide to see what apps are availible from the Android market. I find one called BlueTerm which is a terminal that operates over Bluetooth - and it's free, perfect!
I download BlueTerm and start it up. Click the 'Menu' key and select 'Connect Device' scan for devices and the RN-42 if found. I try to connect to it... And it shows as connected, so maybe I'll type something? - It's echoed back! and the mbed's LED1 is flashing (bit odd that I didn't need to set up the baud rate but who cares?)
So it looks like mbed over Bluetooth is definitely possible - which opens up a load of cool stuff I can now do...
Hello World Code
Here is the code I used to send characters to and from the PC and android phone.
9 comments on Bluetooth Stuff:
Please log in to post comments.
When you find out how to make Android Apps, especially with Bluetooth, please tell me, and the rest of the MBED community. Cheers Ceri.