Let's Make Robots!

Processing talking Bluetooth

Getting Arduino talking through Bluetooth seems like an easy task. There are plenty of tutorials showing you how to do the initial setups and most Bluetooth modules have their own wiki pages + datasheets you can use. It works, you can make the connection, use a terminal software, send packets back and forth. It's all good. Or is it ?


I thought it was untill I attempted to make Processing talking Bluetooth. What a hurdle it turned out to be. First it looked as if everything was working allright. The Serial.list() command showed the COM port of the Bluetooth and it seemed like I could connect to it.Apparently not. As it turns out the COM port listed by the Serial.list() command is the incoming port of the Bluetooth, but where is the outgoing ? I looked at the paired device in my Bluetooth settings on Windows, it was there listed with COM port number and everything. Then why couldn't I connect to it? You simply just can't. After 5 days of huzzle to get it working I was playing around with the BlueSMiRF at Uni. Somehow it worked right away with the desktopBluetooth library. I had played around with it at home without luck.


I thought to myself that I needed to figure out what the problem was or what could have been the problem. After many attempts to redo the error at home I found that having Serial Monitor open in Arduino would somehow remove the SPP port from the Bluetooth module, making it impossible to connect to it through bluetoothDesktop. After having found this new vital information I got home for the weekend and started fiddling with it. It worked. 5 damn days for something so simple.


So here is my guide for setting up Bluetooth to work with Processing.

I won't go through setting up the module, there are plenty of other guides/tutorials around the Internet.

Once you have your Bluetooth module paired with the PC, you should have a Serial port (SPP) under Services. Looking like this:

Bluetooth Services


If you have that setup you are ready to play around with Processing.

First you need to download bluetoothDesktop from extrapixel's website.



After you have that downloaded to your library directory in Processing, the best thing to do to test if it works is using this example:



In the example you need to change something to work with your Bluetooth module. The bluetoothDesktop library works differently from Serial.list() as it looks for Services to connect to. The example is looking for a service called "simpleService".

As you can see in the screenshot, the service name is "Dev B".

final String SERVICE_NAME = "simpleService";

Should be

final String SERVICE_NAME = "Dev B";

For it to be able to find the Service of the Bluetooth module. For your code it should be renamed to whatever your Bluetooth service is called. You can see this by opening the properties of the paired Bluetooth module in the Bluetooth settings.


After you have made this one change, you should be able to run the code and wait for it to connect. It takes a while to connect, everything from 10 sec to 45sec. Remember NOT to have Serial Monitor open as it won't be able to find the Service then.