Shopping Cart


PS4 controller support for the USB Host library

The PS4 controller is now also supported via Bluetooth. It uses the same API as the other libraries I have written, so if you have used them before, then you should be quite familiar with it.

The example code is available at Github:

For more information take a look at my blog post: This explains how to pair with the controller and have some background information as well.

You should also check out the readme which will always have the newest information available.

That is all for now. Hopefully this will be useful to anybody out there that wants to use the PS4 controller with the library.

Update 18. January 2014
A USB version of the library is now also available.

Bluetooth HID devices now supported by the USB Host library

PS3 keyboard

PS3 keyboard

I am glad to announce that Bluetooth HID devices are now supported by the USB Host library. The library already supports PS3 and Wiimote controllers, but now you are also able to use Bluetooth mice and keyboards with the library.

An example is available at the following link:

I have personally tested it with a PS3 keyboard (see image), an Apple Wireless Keyboard and an old Bluetooh mouse from Microsoft and all of them works fine.

For more specific instructions on how to use the library I recommend taking a look at the blog post at my own blog:

Feel free to post a comment below if you got questions or got problem with a specific device and I will answer as fast as possible.

Adding a display to a digital scale using Arduino and USB Host shield

Arduino reading digital scale

Arduino reading digital scale

I am the proud owner of Model 510 5lb digital scale. It is a nice little scale which works very well (much better than service itself) while attached to my workstation. The scale doesn’t have a display making any kind of standalone use difficult. However, since the scale is a USB HID device reading data from it should be as easy as from a joystick and Arduino board should be adequate to provide a display function for it. To test this theory I made a simple setup consisting of Arduino UNO, USB Host shield and HD44780-compatible LCD display. I also wrote a small sketch which polls the scale and outputs the weight. The secondary objective of this project was to demonstrate LCD support in USB Host shield library.

For this project I used the following:

  1. An Arduino board. Standard size board, such as UNO, Duemilanove or Leonardo, will work
  2. USB Host Shield
  3. Toshiba HD44780-compatible LCD display, in 16×1 or 16×2 configuration. If you’re planning to use this sketch for something else, like data logging, the display is optional – all output from the scale is repeated to the serial port
  4. 5lb digital scale. Scales are standard HID devices with usage table 0x8d, therefore, scales from other brands may work as well with no or minimal modifications to the code
  5. USB Host library

The example code is also hosted at github, as well as in ‘examples’ section of the library under ‘HID’. It has been tested with Arduino IDE version 1.0.5.

In this project, the LCD is connected to the shield’s GPOUT pins, as documented in max_LCD.h header file. In addition to data lines, 5V and ground must also be connected to the shield’s 5V and GND terminals; the RW pin must be grounded – I do it on the LCD itself. In order to see the characters, the display must be biased – a 5K-10K pot with wiper on Vo and other two pins on 5V and ground will provide contrast adjustment.

Continue reading Adding a display to a digital scale using Arduino and USB Host shield

Wireless Xbox360 controller support for USB Host 2.0 library

Wireless Xbox360 code

Wireless Xbox360 code

[EDIT] Four simultaneous controllers are now confirmed to work [/EDIT]
This is a short announcement of another nice contribution to the USB Host 2.0 library code. Kristian Lauszus from TKJ Electronics announced release of wireless Xbox360 controller support for USB Host 2.0 library; up until now only wired Xboxen were supported.

As announced, up to 4 controllers are supported, however, only one has been tested so far. If you have (or can borrow) multiple Xbox controllers, please help Kristian test his code.


Xbox360 controller support added to USB Host Shield 2.0 library

xbox360 announcement

xbox360 announcement

Kristian Lauszus from TKJ Electronics made another contribution to USB Host Shield 2.0 library – support for Microsoft Xbox360 game controller.

Files XBOXUSB.cpp and XBOXUSB.h contain the main functionality. An example sketch (a screenshot of which was used for the title picture) can be found in the examples directory. Also, check the EXTRAREADME file for additional information as well as Kristian’s github page.

I’d like to note that Kristian is a developer of support code for Sony controllers – Dualshock 3, Navigation, and Motioncontroller – in the current version of the USB Host library. The Xbox360 code
is another nice contribution. Once again – thank you Kristian!


Interfacing PS3 controllers to Arduino via wired USB

ps3 usb code

ps3 usb code

This is a short announcement about a new feature added to USB Host Shield 2.0 Library. Kristian Lauszus from TKJ Electronics developed and contributed code for interfacing to several Sony PS3 game controllers and has been working on refining it for several months. Two days ago he posted a pull request on GitHub with the following comment:

I don’t know if you could post it on your blog too, so people will know that it now also supports the controllers via USB?

Since the beginning, Kristian concentrated on Bluetooth interface for the controllers. This is the preferred way, however, the standard wired USB interface is as good as Bluetooth dongle plus it is 100% compatible. Take a look at this example showing how to initialize PS3 controller and access its buttons, joysticks and accelerometers.

Kudos to Kristian for this nice piece of code!


Using Logitech Extreme 3D Pro joystick with Arduino HID library

Logitech joystick connected to Arduino

Logitech joystick connected to Arduino

HID report parsing explained in the previous article works pretty well with properly aligned HID reports. The analog controls are placed on a byte or word boundary and buttons occupy dedicated fields. The majority of HID devices are designed this way, however, some other devices are not that simple to interface and today I’m going to show how to handle one of those.

A Logitech Extreme 3D Pro joystick is one nice HID device. It is good looking, well-built, and have a twist handle, which adds third axis to a stick making this model popular among FPV fliers since you can control pitch, roll and yaw with one hand. Also, X and Y axis are 10 bits which gives good precision. There is one problem with this joystick – its input report.

Logitech, in its infinite wisdom, decided to pack all the high and low resolution analog controls plus 12 buttons in 6 bytes of input report. The report looks like this – 10 bits of X, 10 bits of Y, and 4 bits of hat switch. After that, things become easier – one byte of Rz AKA “twist handle”, one byte of buttons, one byte of throttle (called “slider” in the report), and finally, one partially filled byte holding the rest of the buttons. Take a look at the screenshot below – two most important controls are not byte aligned, therefore, simple straightforward parsing of the report is not possible. Also, USBHID_descr won’t show this report correctly.

To demonstrate how to deal with this report I wrote a simple Arduino sketch. It was made by modifying an example from the previous article. I also made it as simple as possible – as soon as any of the controls changes its value, new report is printed on the serial terminal. The sample output is shown below followed by code explanation.

Continue reading Using Logitech Extreme 3D Pro joystick with Arduino HID library

Developing Arduino code for HID Joystick

This article focuses on how to use the existing USB code library and HID report descriptor info to implement joystick functionality.  Human readable HID report descriptor and report information can be easily obtained using USBHID_desc.pde sketch – see previous article for details. This information will help you getting field details such as size and count info. Also, if you don’t have Arduino Mega or 2560 to run USBHID_desc, report descriptor for your device can be obtained using one of many PC tools known as USB analyzers, or even the official device verification tool. This article is written by Alex Glushchenko – a developer behind second revision of USB Host Library as well as majority of device support code.

As you may already know report is a data structure used by HID device to return the information about the certain device parameters such as joystick coordinates or button events, or receive new settings such as switching on/off LEDs on keyboard.  

Report descriptor is a data structure which describes report or reports, if there are few in number, field sequence, sizes and counts.  Each report descriptor consists of several items. Each item describes some field property. I am not going too deep into details on items, explaining only the most important ones which are absolutely necessary in writing your own report parser.  

The items usually describe type of field (input/output/feature), minimum, maximum field values, units, value meaning (usage) etc.

Continue reading Developing Arduino code for HID Joystick

Visualizing HID device reports and report descriptors

Screenshot of USBHID_desc sketch output
Human Interface Device class of USB devices has a unique property – a report descriptor which contains information about data that device is sending to the host as well as data that can be sent to the device. This property allows for variety of devices – keyboards, mice, joysticks, digital scales, uninterruptible power sources, GPS receivers, and even toy missile launchers to belong to a single class – HID. A vendor just needs to pick a usage table which contains controls similar to vendor’s device – every OS has a generic support for HID devices so in most cases specific device driver is not necessary. The report descriptor again makes this possible – it contains definitions or report fields therefore a generic parser can process reports from any arbitrary HID device. However, this generic parser will take too much space on small microcontroller systems such as Arduino due to the amount of constants that needs to be present in the program code.

It shall be noted that a HID report itself is a simple structure of fixed fields and when this structure is known a very lightweight parser can easily be developed. HID development in legacy USB library has stopped at this point; I thought people will just take a look at the spec and write report parser for their device. It soon became evident that very few are actually willing to do this and in rev.2.0 of the library the HID report parsing is semi-automatic – a report descriptor has to be analyzed first using USBHID_desc utility presented in this article and then actual reports for the device can be parsed using library facilities (an article about coding report parsing is here).

Continue reading Visualizing HID device reports and report descriptors

Exchanging data between USB devices and Android phone using Arduino and USB Host shield

CueCat connected to Android phone

CueCat connected to Android phone

Today, I’d like to show how to exchange data between USB device and ADK-capable Android phone. I will be using CueCat barcode scanner as source device; the data will be received by the phone and displayed on a screen using Arduino Terminal Android application.

A phone is USB device, too, and since two USB devices are unable to communicate to each other directly, I’m using Arduino board equipped with USB Host shield to relay data between devices. The sketch which runs on Arduino is a mix of two other pieces of code, one from ADK terminal emulator article and another one from an article explaining interfacing with a barcode scanner. Refer to these articles if you have questions about a specific piece.

Below is a full text of an Arduino sketch. It can be pasted from this page in Arduino IDE, compiled, and loaded into the board. It is also included in the examples section of USB Host library rev.2.0 distribution on gitHub. The library itself shall be installed in Arduino IDE tree as well.

To receive data from Arduino you’ll need Arduino Terminal application installed on your phone. The source code of application is also available – it is released under GPL2, if you make modifications to the code, please make them available for other people!

Finally, we will need some hardware – an Arduino board, USB Host shield, a USB hub, “declawed” CueCat or any other HID boot barcode scanner, as well as ADK-compatible Android phone. We will also need a 5V power supply capable of providing ~700ma of electrical current. I will show arrangement of all necessary pieces after explaining the sketch code.

Continue reading Exchanging data between USB devices and Android phone using Arduino and USB Host shield