Posts tagged ‘Bluetooth’

Bluetooth communication between BlueSMIRF and Ubuntu

A quick post on how to set up the Bluetooth communication between Ubuntu and a BlueSMIRF Modem.

My laptop was broken recently, and after getting a free new motherboard from the kind Sony people I reinstalled Ubuntu and tried to get all my software running again. Today I tried setting up the Bluetooth communication with my toy car’s BlueSMIRF (see previous posts) and  my laptop, and decided on documenting it. So here’s how to do it:

  1. (optional) It’s easiest if you can see what is happening on the BlueSMIRF side. Therefore, you’ll need a serial (TTL) to USB convertor like this one. Alternatively, if you have a Dwengo board (or similar), you can use that one by simly removing the PIC18F chip for a while:

    Now you can monitor the commands and data passing through the BlueSMIRF by opening “serial port terminal” (install it through the Ubuntu Software Center) on /dev/usbtty0 at the speed of your BlueSmirf (default 115200 baud)

    Details on the commands available are available in the Roving Networks Command datasheet.

  2. I didn’t get the default Ubuntu Bluetooth tool (the B in the taskbar) to play nice with the BlueSMIRF, so I installed “Bluetooth Manager” (BlueMan) through the Software Center.
  3. Power the BlueSMIRF, it should start blinking rapidly for about a minute. This means it is waiting for a connection. Once the rapid blinking stops, you can’t connect anymore!
  4. Click on the B in your taskbar of BlueMan, a window should open showing the Bluetooth devices in your environment. One of them should be FireFly (the BlueSMIRF). Right click on it an select “connect to SPP”:

    (the name in the screenshot is robot-719A instead of Firefly because I changed it earlier)
  5. Because this is the first time you connect to the BlueSMIRF, it needs to be paired. Therefore, Blueman will ask you the pass phrase. Enter “1234” (without quotes), this is the default passphrase of the BlueSMIRF.
  6. The bottom of the Blueman screen should now say “Serial port connected to /dev/rfcomm0”. Now you can open a serial connection to /dev/rfcomm0 using serial port manager (or from within a script) and start communicating 🙂
    The LED on the BlueSMIRF should turn green.

That’s it! Now the pairing is done, and you won’t need to enter the passphrase the next time you connect to the BlueSMIRF.

    December 19, 2010 at 11:15 am Leave a comment

    Using Android as robot remote control

    The flea market car / robot saga continues… Controlling the robot from my laptop via Bluetooth was cool
    , but running after the robot with the laptop in my hands kind of diminished the James Bond – feeling of it. Therefore, I decided that my first application I would create for my brand new Android smartphone would be a remote control for the robot!

    Luckily, the online developer information (available at, provides a wealth of information for getting started. What was more, I actually found a sample application there, called BluetoothChat, that almost did exactly what I wanted to do. The BluetoothChat application makes a connection to a Bluetooth device (this will be the robot) and it allows to send text to it once connected (the text will be the robot commands).

    Google provides a complete development environment for developing Android applications, which can be downloaded at Just follow the instructions over there to install the platform and create a “hello world” application. Connecting your phone over USB to the development computer allows you to debug / run the application on the phone. On my Ubuntu laptop, I have to restart the adb server as root after connecting the phone via USB:

    (while in folder /android-sdk-linux_86/tools)
    ./adb kill-server
    sudo ./adb start-server
    ./adb devices

    Now let’s skip to the application. I wanted to change a few things to the BluetoothChat application:

    • actually get it connected to a Bluetooth device, because this wasn’t working right away.. 😦
    • after connecting to the robot over Bluetooth, I wanted to automatically start my PING – PONG handshake (Android says “PING” and the robot answers with “PONG”, which indicates the connection is established successfully and the robot should start listening for commands)
    • Instead of typing the commands in the text field I wanted some big buttons (forward, backward, left, right, …)

    Connecting the BluetoothChat example to a Bluetooth device

    I first tried connecting the BluetoothChat Android application to Bluetooth on my laptop, but it didn’t work. Whatever I tried, I always got a “service discovery failed” exception on the following line of code in

    tmp = device.createRfcommSocketToServiceRecord(MY_UUID);

    After a long time trying to solve this, I found this site, which suggested to change the line of code to this code:

    Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
    tmp = (BluetoothSocket) m.invoke(device, 1);

    And this worked! Also, note that you have to connect at 57600 baud to the Android Bluetooth.

    Do a handshake once connected

    Once connected to the BlueSMIRF on the robot, the following should happen:

    • Android sends “PING\n” to robot
    • Robot receives this and sends “PONG\r\n” to Android
    • Android receives this, and knows the connection is succesfully established.
    • Now Android can send commands like “D,70,1” to set the servo to 70° and the drive motor to forward motion.

    I changed the run() method of the ConnectedThread to do the handshake once connected: see code.

    Big buttons that send commands to the robot

    And now for the fun part.. I wanted to change the layout to have nine big buttons which would send the robot in a certain direction:

    I used the example at this site to create the big button layout. Once a button is pressed, it will send a command over Bluetooth to the robot which will make it ride in that direction:

            mBRButton = (Button) findViewById(;
            mBRButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    // Send a message using content of the edit text widget
                    String message = "D," + right + "," + backward + "\r\n";

    And now a little movie to prove that it works!

    The source code can be downloaded here.

    edit: latest version of code is now available via


    September 4, 2010 at 5:18 pm 14 comments

    Time for a new steering system

    My last post was about putting Bluetooth in a flea market toy car in order to control it remotely from my laptop. One problem I had with the car was the amount of current it drew. Unexpectedly, it turned out to be the steering that drew most of the current. I thought the steering was done by a servo motor, but apparently they put a regular DC motor in it to turn the weels. A piece of plastic stops the turning and basically the motor stalls everytime you steer, and so draws the maximum amount of power..

    To reduce the power-demands of the car I cut out the steering DC motor (and all the plastic around it) and glued in a servo.

    Now to make the servo turn the weels, I used some good old Lego bricks. The flat one with the dents is glued to the thing that used to make the weels turn. Than I used a gear wheel glued to (God, I love hot-glue!) the servo, which makes the flat brick move. Because the servo sometimes turns too much (it’s a cheap one so not always that accurate), I cut most dents from the gear wheel. This assures that no damage is done if the gear wheel turns too much..

    August 15, 2010 at 9:34 pm Leave a comment

    Communication with Pinguino via Bluetooth

    I bought a BlueSMIRF Bluetooth module a few weeks ago, and this weekend I’ve finally had some time to put it in action 🙂

    Connecting the BlueSMIRF module is really easy. The BlueSMIRF module has 6 pins: CTS-I, VCC, GND, TX-0, RX-1 and RTS-0. You have to connect CTS-I to RTS-0, connect VCC to the supply voltage and GND to ground. The TX-0 pin is connected to the RX pin of the microprocessor, while the RX-1 pin is connected to the TX pin of the microprocessor. On the PIC18F4455 these are pins 26 and 25 (pinguino pins 9 and 8). s

    CTS-I  O----------------
    VCC    O--5V           |
    GND    O--0V (gnd)     |
    TX-0   O-- to RX PIC   |
    RX-1   O-- to TX PIC   |
    RTS-0  O----------------

    As explained in a previous post, I am using a Pinguino board, so the code should work on Arduino as well without needing too many modifications. This is the code I used for writing some text:

    #define PIC18F4550
    char incomingByte = 'K';	// for incoming serial data
    void setup() {
    void loop() {
    	// send data only when you receive a C character
    	if (Serial.available() > 0) {
    		// read the incoming byte:
    		incomingByte =;
    		if (incomingByte == 'C') {
    			Serial.print("I received: ");
    			Serial.print(incomingByte, DEC);
    In the setup routine I connect to the serial port at 115200 bauds. The bluetooth module is just used as a regular serial cable, so no fancy tricks are necessary.
    On my Ubuntu laptop, I had to do the following to get things running:
    • first connect your Bluetooth dongle to the BlueSMIRF (mine appeared as FireFLY-719A)
    • sudo hcitool scan #so we know the MAC address of the FireFLY
    • rfcomm connect 0 00:06:66:03:72:9A #substitute with your BlueSMIRF’s MAC address
    • sudo gtkterm -p /dev/rfcomm0 -s 115200 #start gtkterm to read/write to the serial port

    Of course we don’t want to interact through gtkterm with our microcontroller. I wanted to employ Processing, but this gave some additional difficulties in my setup. In Processing, Serial.list() is used to list all available serial ports. The Bluetooth serial port /dev/rfcomm0 does not appear in the list though. A dirty hack to solve the issue is symlinking /dev/ttyS0 to /dev/rfcomm0:

    sudo rm /dev/ttyS0
    sudo ln -s /dev/rfcomm0 /dev/ttyS0

    If anyone knows a better way to solve the issue, please mention so in the comments! This is the Processing code:

    import processing.serial.*;
    Serial myPort;                // Create object from Serial class
    void setup()
      size(200, 200);
      myPort = new Serial(this, Serial.list()[0], 115200);  //the first port in the list is /dev/ttyS0 which we symlinked to /dev/rfcomm0
    void draw()
      while (myPort.available() > 0) {                      //if something was received via serial port
        String inBuffer = myPort.readString();
    void keyPressed() {
    void stop() {

    February 22, 2010 at 6:12 pm 3 comments


    Articles to be written…

    Twitter – kr3l


    RSS Google Reader Shared Stuff

    • An error has occurred; the feed is probably down. Try again later.

    RSS Listening to..

    • An error has occurred; the feed is probably down. Try again later.