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:

Continue reading Using USB Bluetooth dongle on Arduino to connect to Windows PC

Using USB Bluetooth dongle on Arduino to connect to Android phone

Arduino connected to Nexus S

Arduino connected to Nexus S

Since Kristian’s release of SPP service for USB Host 2.0 library I got many e-mails with questions about Bluetooth serial communications in general and using the SPP class in particular. While establishing a Bluetooth connection is quite easy when using PCs/smartphones/tablets, the Arduino implementation is less user-friendly (for a good reason) and somewhat confusing. This article is intended to be a short tutorial of Arduino USB Bluetooth connectivity using an Android device as a peer – in my opinion, the simplest one to set up and communicate.

To follow this tutorial, you will need the following:

  1. An Arduino board ( I sell them too )
  2. full-size USB Host Shield 2.0
  3. USB Host Shield 2.0 library downloaded and installed in your Arduino library directory
  4. An SPP example sketch
  5. Bluetooth dongle – see below for detailed discussion
  6. Android device – a phone or tablet. The accuracy of this tutorial has been checked on Nexus S phone and Nexus 7 tablet, both running Jelly Bean 4.1.1 OS.
  7. A Bluetooth terminal emulator app for Android – I use Blueterm

The hardware setup is shown on the title photo (click on it to make it larger). It is a good idea to use external power supply at least in the beginning – some Bluetooth dongles are not happy when powered together with Arduino board/USB Host shield from USB cable. On a side note, it is always a good idea to use external power supply while experimenting with USB devices, especially when using current Arduino boards with their weak regulators. Also, Bluetooth code requires plenty of resources. The example used in this article compiles in ~24K and even though it would work on standard Arduino, any meaningful project will likely require a bigger board, like a Mega.

Continue reading Using USB Bluetooth dongle on Arduino to connect to Android phone

Bluetooth RFCOMM/SPP service support for USB Host 2.0 Library released!

Compatible Bluetooth Dongles

Compatible Bluetooth Dongles

[EDIT] Here is Kristian’s post with more detailed explanation of the example sketch.[/EDIT]

Kristian Lauszus from TKJ Electronics, a man behind PS3 and Xbox360 code in USB Host Shield 2.0 library did it again! I’m pleased to announce that the library now supports standard RFCOMM/SPP implementation, thanks to Kristian’s work.

RFCOMM is basic Bluetooth service and SPP is serial port emulator on top of this. The code allows interfacing standard USB Bluetooth dongles to Arduino boards using USB Host Shield v.2.0. Bluetooth dongles (the ones I’ve tested can be seen on a title picture ) are widely available, cost much less than specialized serial Bluetooth modules (I have a couple of powerful class 1 dongles bought on eBay for $1 shipped) and won’t occupy precious serial port on Arduino board. Even though most dongles are compatible with the code, there are also some that don’t work. The code has been tested for compatibility with all major OSes – Linux, MacOS and Windows 7, as well as Android devices. It will likely work with any RFCOMM client, however, more testing is necessary.

The example code is a simple SPP server. It needs to be started before attempting to connect to it from a PC/phone. Once started, the state of the server is printed on a terminal. After that, the device can be discovered/paired/connected to; it is then possible to send characters from one device to the other by means of a keyboard. In the coming days I will write a series of posts with details of connecting different Bluetooth devices to Arduino. In the mean time, enjoy the code! Please give it a try and let me know what you think.


Testing RN-42 Bluetooth module using Android phone

RN-42 paired to an Android phone

RN-42 paired to an Android phone

Bluetooth modules from Roving Networks are popular among DIY enthusiasts – they are small, powerful and cheap. They are used in many projects; I’m currently building Yanis Android Wireless EOS Controller which uses Bluetooth module for communication between Arduino and Android phone. I know from experience that radio links are not always easy to establish and sometimes hard to troubleshoot, that’s why I have the habit to test radio component in stand-alone mode before other pieces of the project. In this article I show how I do it with RN-42 serial Bluetooth module using simple setup and test procedure. Other Bluetooth modules can be tested in similar fashion.

In general, any Bluetooth link is established in two steps. First is called “pairing” and the result of it is an exchange of credentials, which are then stored on one or both devices. Usually, pairing needs to be performed only once – for all subsequent connections stored credentials are used. Second step is actual connection – an application on one device connects to the other device and data exchange starts.

In order to test my RN-42, I need to somehow power the module and then be able to send and receive serial data. To achieve this, I made couple connections using pieces of thin wire (actually, cut-offs of resistor pins), which can be seen in detail on the picture below. Power connector for small LiPo battery is comprised of two wire strips on the right. A serial loopback, which connects TX and RX pins (more on this later) can be seen on the left. Title picture shows the module with battery connected.

When all necessary soldering was completed, I powered the RN-42 using small LiPo battery paying special attention to polarity and went to Network Settings on my phone. First, I made sure Bluetooth is checked and then went to Bluetooth Settings and started Scan for Devices. By default, RN-42 starts in discoverable mode on power-on so there is no need to do anything special. When device is discovered, I select it and enter 1234 as pin. When device is registered as “paired”, I can check the data transfer.

To send and receive serial data over Bluetooth, I need terminal program. There are several applications on the market, my favorite is BlueTerm. To check data transfer between RN-42 and Android, I start BlueTerm, connect to RN-42 and start typing. If RN-42 works correctly, characters I type will appear on the screen.

RN-42 connections

RN-42 connections

This happens because TX and RX pins on Bluetooth module are shorted together by a loopback wire. Data sent from the phone will appear on TX pin, then RX pin, then sent back to phone and then to the screen. To see if this is indeed the case I disconnect power from RN-42. Character echoing should stop.

This is all that needs to be done to check the module. Troubleshooting is also easy. If powered-on RN-42 won’t appear in discovery, check polarity (reverse polarity survival is not guaranteed – don’t make this mistake or you may need a new module). If polarity is correct, check battery voltage with multimeter. If voltage is within specs, check if it applies to correct pins. If everything is good but no pairing occurs, replace the module. If device is paired but no characters are echoed in terminal, check loopback pins and soldering quality.

When I confirm that my module is good, I can continue building the controller. I’ll write another post as soon as I get it working.


RC car controlled by Wii Remote on Arduino

This is a quick post about another great project. Tomoyuki Tanaka AKA Tomo on this site, active in PS3 and Wiimote game controllers thread, AKA moyuchin on Youtube posted this little video of RC car controller made of Wiimote, Arduino Pro Mini and USB Host Shield Mini interfacing with Bluetooth dongle. Check out the video to see how speed, direction and steering controls have been implemented.

Tomoyuki also made the code available on github. The code is based on Richard Ibbotson’s popular Wiimote Bluetooth code, as well as my MAX3421E and USB Host libraries. The code is well organized and even has a brief documentation in README file. Further development is on the way – Tomo is planning to add ultrasonic sensor support, so keep an eye on this repo. Good job, Tomoyuki and thank you very much for sharing your outstanding work!


Bluetooth code for Arduino USB Host

Arduino to Bluetooth connection

Arduino to Bluetooth connection

[EDIT]The standard RFCOMM/SPP implementation is available in rev.2.0 of the library.[/EDIT]

I am pleased to announce addition of Bluetooth dongles to the family of USB devices supported by USB Host Shield. Bluetooth dongles are affordable, interface is well documented, and USB transport layer is very simple. Even though full Bluetooth protocol is heavy and takes a lot of program space, it can be stripped down quite a bit for a particular application. One good example of such approach is Richard Ibbotson’s HID over Bluetooth implementation – see Wiimote Game Controller Interfacing article for details. I wanted to have simple communication transport over Bluetooth which would fit into Arduino and the code I’m presenting in this article is doing just that – it’s lightweight terminal program allowing two Arduinos talk to each other over Bluetooth. The code has been developed by George Lgotkin.

The source is hosted in GitHub repository. Standard Arduino library format of the code has not been tested yet, for now it’s easier to just copy all the files in a directory and open btclass_h.pde in Arduino IDE. To use the program, you need two Arduinos, two USB Host Shields, and two Bluetooth dongles. You need to compile and load the sketch into both Arduinos and then open two terminal windows, one to a serial port of each Arduino – this can be done from a single computer. Don’t use Arduino IDE built-in terminal. Also, SPI library shipped with recent versions of Arduino IDE is not compatible with USB Host library, if you have compiler errors related to SPI, replace your library with one from Arduino-0018 or the Playground. Serial port speed is set to 115200 in the sketch, it can be changed in setup(), if necessary.

Sketch starts by printing short help (see screenshot below) and then waits for the command. In order for two Bluetooth devices to talk to each other, one has to be the server and another one client. In one terminal, type ‘S’ and press Enter. This starts the server. If you are curious, type ‘M’, Enter – the address of the module will be printed. Note that if you send address request before starting the server, address containing all zeroes will be returned.

To establish connection, type ‘C’, Enter in other terminal. The sketch will print “Connecting…”. After some time ( 30 seconds or less ) both terminals will print “Connected”. Now type something in one terminal and press Enter – the string you just typed will appear in other terminal window. Easy.

This code is just a small example, error handling is minimal. It works better if no other Bluetooth radios are transmitting nearby. If client Arduino reports “Connected” but server doesn’t, it means that client has connected to some other server, most likely your laptop or phone. This can also be used to your advantage for testing – start Bluetooth on a PC and then see if both Arduinos are able to connect to it in client mode.

Continue reading Bluetooth code for Arduino USB Host

PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3

Wiimote controller wit USB Host Shield

Wiimote controller wit USB Host Shield

This is the third part of a series of articles written to describe development of interface between Arduino and popular game controllers using USB Host Shield. Previous parts:

Revision 0.4 – 13th January 2010

Part 3. Develop the Bluetooth USB and HCI interface used in the support of the Wiimote and PS3 game controller, and also some utilities needed to analyse and configure these devices.

1. USB Interface
As before, we first look at the descriptors for the USB dongle using the USB_Desc sketch. The result is:

Continue reading PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3

PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 2

Sony PS3 controller

Sony PS3 controller

This is the second part of a series of articles written to describe development of interface between Arduino and popular game controllers using USB Host Shield. Previous parts:

Revision 0.6 – 13th January 2010

Part 2: Develop the USB interface to the PS3 controller

1.       USB Reduced Hosts

Full USB hosts such as Windows and Linux based computers can manage a large variety of different USB devices and load appropriate USB drivers for each device. There is an enumeration or discovery phase where the host gathers information on the attached USB device and uses this information for the driver selection and configuration. In small embedded applications this is not possible or required to support this variety, so the application usually only supports a few devices, often only one. This means the discovery process can be much reduced since the results are already known. This will reduce the memory required for the application by hard coding the device configuration into the application.

Though the configuration will be hard coded, we still need to initially gather the information from the device itself and other sources.

The existing device drivers mentioned above for Windows and Linux are important in our development process. The Windows drivers are usually complete, but not available in source form. Linux drivers are available in source form, though not always as complete. Device manufacturers are usually very reluctant to provide information required to build a driver or embedded application. So we rely on copying Linux code or “sniffing” Windows code to give us guidance.

Continue reading PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 2

PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 1



Revision 0.9 – 13th January 2010

Part 1: Introduction

1.       Background
These articles describe how to interface PS3 and Wiimote game controllers directly onto the Arduino using the USB Host Shield. These controllers have not previously been directly connected to an Arduino due to the USB and Bluetooth interfaces and protocols used, and their relative complexity. The game controllers are a good match to the capabilities of the Arduino, and to the imagination of Arduino users, they have not only buttons and joysticks, but also motion sensing, and other goodies which deserve to be in the hands and ideas of Arduino users. Also I hope these articles provide some guidance for people to develop other USB host and Bluetooth applications for small embedded processors.
Arduino already comes in versions which have USB and Bluetooth interfaces, but these are not suitable for our chosen game controllers. When used in USB mode, the PS3 controller is a USB device and needs to talk to a USB host. The normal Arduino USB interface is also a device, so not compatible. When in Bluetooth mode, both of these game controllers use the Bluetooth HID protocol and this is not compatible with the commonly used Bluetooth modules which support only the RFCOMM Serial Port Protocol. Arduino users have successfully used a PC as an intermediary between the game controllers and the Arduino, so the PC is host to both devices.

These articles were written by Richard who is new to the Arduino, blogs, github, libraries, etc, so please give me any help and feedback on how I might improve or correct these articles and software.

Continue reading PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 1