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.
This video shows the PS3 controller and the Wiimote bluetooth working on the basic Atmega168 Arduino.
Introduction Youtube Video
Recently a new Arduino shield has been developed by Oleg here at Circuits@Home, which provides a USB host interface directly onto the Arduino. This shield is based on the MAX3421E USB controller IC from Maxim, which can operate in both device and host modes. Oleg has also created libraries for the basic functions of the MAX3421E and USB host operation. I have previously used the MAX3421E with success on other processors and decided to try to add support for our game controllers using this shield. There are significant challenges to this due to the complexity of the protocols and the limited flash and SRAM space on the base Atmega168 based Arduino.
The code developed here is licensed under the LGPL License and should be fairly easy to port to other USB host controllers. Given the recent explosion in availability of microcontrollers with integrated USB OTG or reduced host, from Atmel, Microchip and others, then I would expect quite a few derived versions.
You will see as the code develops the fairly high complexity of the protocols involved, and such development effort is only really justified in a case like this where no off the shelf alternative has been found. There are integrated USB host solutions from GHI Electronics and FTDI Vinculum, but these again do not support the Bluetooth HID yet. They do support many other devices and classes including mass storage, serial, and HID, they can be interfaced to Arduino and do not put such a drain on the memory and programming of the Arduino.
2. The PS3 Controller

I have used two PS3 different game controllers; the first is a Sony Six Axis Dual Shock 3 Wireless controller, and the second is the Madcatz Wireless six axis controller. The Sony has a USB connector and also operates in Bluetooth mode for wireless. The Madcatz comes with its own USB dongle, so uses a proprietary wireless protocol instead of Bluetooth. The PS3 controller is well documented and supported already with drivers and applications on Windows and Linux besides the PS3 itself, so there is plenty of interface information available.

The PS3 controller has a large number of buttons which can be read as digital values and some as analog pressure values. There are two joysticks which can be read with analog values to 8 bit resolution, and also 4 LED’s which can be remotely controlled. There are additionally a 3 axis accelerometer and a single axis gyro which give outputs based on the motion of the controller. The Sony controller additionally has two rumble motors.
The following sources have been used to find information and code examples for the PS3 controllers:
3. Wiimote Controller

The Wiimote has less buttons than the PS3 controller and the characteristic stick shape. Though less well endowed with buttons and joysticks than the PS3 controller it has a 3 axis accelerometer, rumble, Infra-Red Camera, speaker and LED. It also has an expansion port where additional devices including 3 axis Gyro and remote joystick can be connected.
The Wiimote does not have a direct USB connection and only works under Bluetooth.
The following sources have been used to find information and code examples for the Wiimote Controllers:
4. Arduino
I chose to use the lowest spec AtMega168 based Arduino and this forced me to be always conscious of the amount of Flash and data memory used. I made extensive use of the MemoryFree library to keep track of the usage of the 1K of RAM. I tried to limit were possible the number and size of data buffers, and to keep the number of text strings as low as possible.
I later modified MemoryFree to allow capture and storage of minimum values. This enables the viewing of free memory at the deepest level of the function calls, where any problems occur.
In terms of processing power the Arduino does not seem to limit performance. Some complexity is added to the code because it is necessary to avoid blocking code. Blocking code would prevent some of the background processes running. These processes are not absolutely time critical, but must be called regularly. The time taken to write a serial string is usually OK, the time to wait for a key press would not be.
5. USB Host Shield
The Circuits at Home USB host shield is based on the Maxim MAX3421E USB controller IC. This IC can operate in device and host modes, though the Arduino library only supports the host mode. The USB host shield offers a number of interface options for different Arduino types using 3.3V or 5V power supplies. There is also two 8 bit GPIO ports and a library to support an LCD display on this port.
The USB Host Shield is described and well documented here on the Circuits@Home website.
Full construction information is provided including schematic and PCB layout, or PCB and built boards are available in the on-line store.
The USB shield uses the following Arduino hardware resources which are then not available for other purposes:
Digital Pin 7 used for MAX_RESET
Digital Pin 8 used for GPX
Digital Pin 9/PWM used for INT
Digital Pin 10/PWM used for SS
Digital Pin 11/PWM used for MOSI
Digital Pin 12 used for MISO
Digital Pin 13/LED used for SCLK
Power for the USB host shield is taken from the Arduino and also powers the USB device. Care must be taken to ensure the total supply current required is available from the Arduino and its power source.
The MAX3421 is documented in Datasheets, programming guide, and application notes by Maxim:
Oleg at Circuits@Home has provided Arduino libraries for the MAX3421E function and the USB host function. Small modifications were necessary in these to support the game controllers, mainly in the NAK handling to ensure non blocking behaviour. The changes should not interfere with existing applications using the libraries and may be incorporated to the standard library.
The library is based on code from Maxim for the ARM processor, but this original code is not complete:
USB is a complex protocol and even though much is done automatically by the MAX3421E, some knowledge of the USB protocol is needed. As primers, these are good sources:
After that the best references are the USB protocol specifications:
6. Bluetooth Dongles
Bluetooth USB dongles come from many suppliers and there is no way to support them all in a simple embedded application. I have used devices which are based on the Cambridge Silicon Radio(CSR) Bluecore 4. These devices are common and low cost at less than $5 each. The dongle is used is based on the BC41B143A chip. The data sheet is here:
The dongle conforms to the Bluetooth specification for an HCI interface and is available here:
The dongle used came packaged like this:

A more general Bluetooth protocol tutorial is available from palowireless.
7. My Development Process and Following Articles
I decided to split the development and these articles into the following steps:
Part 2: Develop the USB interface to the PS3 controller. This allowed me to gain experience of the Arduino and the USB shield. It also provides a quick working wireless solution using the Madcatz game controller.
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.
Part 4: Develop the Wiimote support over Bluetooth
Part 5: Develop the PS3 support over Bluetooth
This article is provided under the Creative Commons Share Alike License
Associated software code developed by the author is licensed under the LGPL License.
Related posts:
- PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3
- PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 2
- Hook up PS3 controller to USB Host shield
- Arduino USB Host – Peripherals.
- Arduino USB Host Shield build log. Part 4.
- Arduino USB Host Shield build log. Part 3.
- Arduino USB Host Shield build log. Part 2.
- Arduino USB Host Shield build log. Part 1.
- USB Host Shield for Arduino – first prototype.
- Arduino USB host – Pre-prototyping.


[...] has put together some libraries that make it easy to use gaming controllers with an Arduino. They interface through the USB host shield. This means that PS3 controllers connect via USB [...]
Just wanted to say that I got the code to work with a Broadcom BCM2045 Here is my output from the program above:
freeMemory() reports: 1514
CSR Initialized
HCI Reset complete
ACL Data Packet Length: 1017
SCO Data Packet Length: 64
Total ACL Data Packets: 8
Total SCO Data Packets: 0
HCI Version: 3
HCI Revision: 16430
LMP Version: 3
Manufacturer Id: 15
LMP Subversion: 17166
Local Name: BCM2045B3
Unmanaged Event: 0
Unmanaged Event: 0
Local Bluetooth Address: 001E0A000062
Search for devices
Search complete
Devices Found : 1
Found BDADDR: 0017AB227962 Class: 042500 Mode: 1 Offset: 4C2D
Remote Name: 0 Nintendo RVL-CNT-01
Unmanaged Event: 0
Connected to device
However, I have issues getting the results to be consistent, so far I have to start the program, wait a few moments then push in the bluetooth dongle and hope for the best. It then searches for the wii remote, it says connected, but the light on the wiimote does not stay on. Is this normal, or do you get it to stay connected and receive events from pressing the various buttons on the wii remote?
Oh yeah, everytime I connect the Offset changes.
Good to see the BCM2045 shows signs of working.
The problems at startup may need some more delay for the Broadcom compared to the CSR.
Offset will be different every time. It is the clock offset between the two devices, and only used to speed connections. I don’t use it.
The blueutils sketch makes the HCI connection, but not the L2CAP connections, so that is why the wiimote times out.
I have been distracted and not posted the next article with th L2CAP and HID part. I will put a sketch on github today which supports the LED, buttons and accelerometers on the wiimote, or I can e-mail to you. The nunchuck and IR camera is not complete in this version.
I am not sure what the unmanaged event is, “0″ is not a normal event code. It doesn’t seem to give a problem, but it would be good to investigate. What is the external manufacturer and model of your USB Bluetooth ?
Sketch is here: http://github.com/ribbotson/USB-Host/blob/master/examples/wiiblue.pde
It should set the LED 1 on and stop the flashing.
Button codes are sent to serial port. “1″ button shows accelerometer values.
If you get a message after a sketch restart of ” No response to HCI Reset”, you may have to unplug and replug the dongle to cycle power because the USB Host shield does not have power control. I am still tring to find a reset method without power control.
I only wanted to drop you a short note to inform you that I really enjoy your articles. Thanks! Keep on the good work
Hi. I’m in my school’s robotics club and we’re following these guides to try and sync up a PS3 controller to an arduino board to control our robot. We have got the PS3LCD sketch to compile (finally) and now have absolutely no idea where to connect the pins? Is there a clear picture of how to connect it all up? We really need to know just what pins to plug into where from where and all that.
Any help would be incredibly appreciated. :)
Thanks so much and keep up the good work.
Sam.