Shopping Cart

Posts

Using USB Bluetooth dongle on Arduino to connect to Windows PC

Discovering Arduino Bluetooth

Discovering Arduino Bluetooth


This is a second article about Bluetooth connectivity using USB Host library for Arduino. Previous article described Android connectivity; today, I will show how to connect an Arduino to a Windows machine using USB Host Shield ( available at the store ) and USB Bluetooth dongle.

The biggest issue with Bluetooth on a Windows machine is third-party Bluetooth stacks. They all work well but behave slightly differently and it is not possible to write a step-by-step walkthrough valid for any Windows PC. My setup is 64-bit Windows 7 with Broadcomm Bluetooth stack; other Windows versions and Bluetooth stacks will be slightly different.If you have any difficulties following the text, leave a comment and I’ll try to help. Also, Bluetooth protocols time out very quickly – 5-10 minutes, sometimes less. If you get a timeout at any step simply start over again; sometimes, resetting Arduino may be necessary.

First thing that needs to be done is to make a working Arduino setup. Previous article on the topic gives plenty of information about necessary gear, compatible Bluetooth dongles and expected terminal output. Once this is done, install Bluetooth on Windows. On Win7, the installation consists of plugging in a Bluetooth dongle to USB port and watching the progress of installation process which will start automatically. At the end of the installation system will give you the warning that your PC is not discoverable – ignore it. If installation is successful a Bluetooth icon will appear in the system tray.

The next step is to pair Arduino to a PC. At this point, an Arduino-USB Host Shield-Bluetooth dongle combo shall be put together as described earlier, tested, and set up as follows:

  • Powered from external supply – optional but highly recommended, at least for the first attempt. If you decide to use external supply, connect it before USB cable
  • Connected to a PC with USB cable. It could be the same PC to which you are going to pair your Arduino via Bluetooth
  • Terminal to Arduino opened. It can be Serial Monitor in Arduino IDE or third-party terminal program such as Putty or Teraterm. If everything is wired correctly and Bluetooth dongle is good you should see the following output in the terminal window:

SPP Bluetooth Library Started
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Local Bluetooth Address: 00:17:9A:2B:63:DA
The name is set to: Arduino
Wait For Incoming Connection Request

Now click on the Bluetooth icon in the system tray. “Device and Printers” dialog will open. Click on “Add a device”. After a short pause Arduino Bluetooth dongle will be detected and you will see the following screenshot. Sometimes a numerical address will be printed instead of a name, it will be the same address that is printed in Arduino terminal window (see above).

Bluetooth "Add Device" Dialog

Bluetooth "Add Device" Dialog


Select Arduino device and click “Next”. The system will try to probe the Arduino Bluetooth. The following output should appear in the Arduino terminal (the device address and remote name will be different on your machine):

Incoming Connection Request
Remote Name: DESK
Connected to Device: 91:68:19:C4:36:28
SDP Incoming Connection Request
SDP Configuration Request
SDP Successfully Configured
Wait For Incoming Connection Request
Disconnected SDP Channel
HCI Disconnected from Device
Wait For Incoming Connection Request

On the PC, the following dialog will open. Click on “Enter the device’s pairing code”.

Select pairing code

Select pairing code

On the following screen type ’1234′ and click “Next”. You’ll get a screen stating that the device is added successfully.

Pairing Code

Pairing Code

In the mean time, this is what should appear in the Arduino terminal window.

Bluetooth pin is set too: 1234
Disconnected SDP Channel
SDP Incoming Connection Request
SDP Configuration Request
SDP Successfully Configured
Disconnected SDP Channel
HCI Disconnected from Device
Wait For Incoming Connection Request

Both devices are now configured and are able to pass data to each other. “Devices and Printers” dialog should still be open with Arduino device in it. Right click on it, select “Properties” and then click on “Services” tab. You should see a screen similar to the title picture (click on it to make it larger). The screen shows SPP service on Arduino and corresponding virtual COM port on a PC, COM50 in my case. Open a terminal session to this port. The following screenshot shows Putty configuration screen – select serial connection type and enter the port number. Connection speed can be left to whatever it was initially – it won’t affect the actual speed of the link. Click “Open”.

Putty configured to COM50

Putty configured to COM50

What happens next will depend on the Bluetooth stack and system security settings. You may get a notification about connection attempt followed by pin entry dialog. In this case, enter 1234 again. The Putty window will eventually open with “Hello from Arduino” string displayed on the line 1. From this point it should be possible to type in one windows and observe the output in another as shown on the following screenshot of two terminal windows side by side.

Two terminal windows

Two terminal windows

As we can see, the steps to establish a connection between an Arduino and a PC are pretty standard:

  1. One device needs to start looking for devices and another one must be willing to answer. In our case, a PC is the one that is looking looking and Arduino is the one that is willing
  2. After they find each other, a key exchange needs to happen. This is the step where we entered ’1234′.
  3. After authentication, a service request needs to be made by one party and accepted by the other. In our case this is happening when a terminal session is open on a PC and is indicated by RFCOMM diagnostic messages in the Arduino window.
  4. Once service request is accepted data flow can begin

One can notice the same sequence when a Bluetooth headset is connected to a phone or phone is connected to a PC or any Bluetooth device is connected to any other Bluetooth device. The only difference is that any other Bluetooth service is more popular than SPP, therefore in our case the process is more involving. It is still quite simple on Windows 7 machines comparing to older OSes, like Windows XP, where the biggest difficulty is to actually find out the virtual COM port numbers created by the driver and which one of the two shall be used for outbound SPP connections.

This is it for today. Enjoy the article and please do not hesitate to ask questions if you have any issues.

Oleg.

No related posts.

15 comments to Using USB Bluetooth dongle on Arduino to connect to Windows PC

  • You have a great website!

    A question – you use a bluetooth dongle on an Arduino host shield. Do you believe this would work on the host USB port on an Arduino Due?

  • Juan Otth

    Thanks for give us your experience,.. y try the sample SPP with a Bluetooth Dongle with a Arduino One and Host USB Shield (it works with a keyboard), show the correct text (including the bluetooth address) but I cant found the device with my notebook with windows 8.

    Do you have a trobleshoting tips?

    Thanks in advance

    JO

  • Greetings,
    i have used bluecove java library to make a simple bluetooth spp between my PC and arduino.
    and i used the java classes in this project :
    http://code.google.com/p/sprime/source/browse/?r=8#svn%2Ftrunk%2Fsprime-bt%2Fsrc%2Forg%2Fjava%2Fbluetooth%2Fsprime
    at first i tried by using this code as client side to connect to any device but i couldn’t untill i changed a line in the client class:
    “connectionURL = servRecord[0].getConnectionURL(0, false);”
    i just set the boolean to true then i successfully connected to my android phone and recieved a string “Test String from SPP Client\r\n”) which the code automaticaly does when connected to a device.
    However by using the SPP.ino example of your library and the above code, when i try to connect to arduino i get this message in the console:
    “Device does not support Service.”
    does this have to do something with the UUID?………. i use the default spp UUID in the code
    “uuidSet[0] = new UUID(“1101″, true);”
    or where do you think is the problem?
    i know my questions sounds big but i think the problem is small, however i have tried and couldn’t solve it.
    thank you

    • I have actually experimented with that myself.
      Here is some code I got working: https://gist.github.com/Lauszus/5708155.
      But I decided to abandon it as it didn’t work very well and would often crash both on Windows and Mac.

      Instead I focused on written a Processing application: https://github.com/TKJElectronics/BalanduinoProcessingApp that communicates with it just like a normal serial port. It works very well in Linux, Mac and most Windows computers.
      I will properly create a dedicated Windows application later on so it works on all Windows machines – it seems like it’s a driver issue for some Windows machines.

      • Hello again,
        thank you for your reply.
        i have tried the application in the first link but unfortunately it didn’t work as you said.
        I understand that this application searches for the ‘TKJSP’ service in arduino and automatically connects to arduino,and the strange thing is that when looking for the services supported by arduino by seeing it’s properties in windows i really find the ‘TKJSP’ service, however the pc never connected to arduino.
        it’s like the problem is from the bluecove library.
        because also the code i posted before doesn’t recognize the only arduino service ‘TKJSP’.
        and about the processing application, i’m not really familiar with using applets, however i tested the “BalanduinoProcessingApp.java” code in the “application.windows32″ folder by copying and pasting it into a project in eclipse and imported the libraries found in the project then ran it as an applet, but i get this at the console:
        ControlP5 2.0.3 infos, comments, questions at http://www.sojamo.de/libraries/controlP5
        java.lang.NullPointerException
        at java.io.DataInputStream.readInt(DataInputStream.java:370)
        at processing.core.PFont.(PFont.java:336)
        at processing.core.PApplet.loadFont(PApplet.java:6198)
        at BalanduinoProcessingApp.setup(BalanduinoProcessingApp.java:68)
        at processing.core.PApplet.handleDraw(PApplet.java:2241)
        at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
        at processing.core.PApplet.run(PApplet.java:2140)
        at java.lang.Thread.run(Thread.java:619)
        Exception in thread “Animation Thread” java.lang.RuntimeException: Could not load font EuphemiaUCAS-Bold-30.vlw. Make sure that the font has been copied to the data folder of your sketch.
        at processing.core.PApplet.die(PApplet.java:3885)
        at processing.core.PApplet.die(PApplet.java:3894)
        at processing.core.PApplet.loadFont(PApplet.java:6201)
        at BalanduinoProcessingApp.setup(BalanduinoProcessingApp.java:68)
        at processing.core.PApplet.handleDraw(PApplet.java:2241)
        at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
        at processing.core.PApplet.run(PApplet.java:2140)
        at java.lang.Thread.run(Thread.java:619)

        then i tried to run the “BalanduinoProcessingApp.exe” alone. then i got a request for a pin and after about 5 minutes the application started, but when i connect to the serial port of arduino the application sometimes hangs and sometimes it continues on but when i press a button like ‘up’ for example i get nothing at the serial monitor !
        all i need to do is run an application with my own 1 page only GUI interface that connects to arduino from the pc and each button in the interface just sends a string via bluetooth…but i don’t know why it’s complicated like this…..do you know other bluetooth java library better than bluecove or do you know another spp sample of another language like c# that i can edit easily?
        thank you

  • Al

    Using this code, I was able to establish a connection between my Arduino and a Lego NXT brick. The NXT brick can send messages to the Arduino, but I am having trouble sending messages from the Arduino to the NXT. The NXT has a protocol in which I have to send a series of hexadecimal numbers and bytes before the message is sent. Is there a possible way for me to send these hexadecimal numbers and bytes? Any help would be appreciated. Thanks in advance.

    • Yes, simply use the different print function as you use normally for the Arduino.
      Use SerialBT.write will send exactly the value that is passed as an argument, while many of the print functions will manipulate it someway.

  • guddy

    hello.. i want to enable/discoverable the bluetooth dongle with only the power source or usb power hub.. (wall power hub) not computer usb port…
    plzz help me ..

  • guddy

    thanks Oleg for responding me..
    yes exactly … i just want to that powered enable bluetooth dongle for scanning.. not using for make a bluetooth connection..

Leave a Reply

  

  

  



You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">