PS3 Controller BT Library for Arduino
I just finished porting the bluetooth library to Arduino. It’s based on the library for the USB Host Shield from Circuits@Home. It works exactly the same way as the class for the boards from GHIElectronics – FEZ Panda, FEZ Rhino etc. You should check out my other post, if you haven’t already: FEZ Panda & PS3 Controller, FEZ Panda & PS3 Controller via Bluetooth, and Demonstration of the PS3 Controllers in action.
To make it work, you’ll need a USB Host Shield or an Arduino ADK.
Update
I have now created another library that only supports the controller via USB. The source code for the USB library can be found at the github repository. An example can be found as well: PS3USB.ino.
Video Demonstration
The library can be found at our Github: https://github.com/TKJElectronics/USB_Host_Shield_2.0. You should also see the Github wiki for more details.

First of all: Really nice work
my question.
When i try to connect the PS3 controller, I get this in serial console:
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Local Bluetooth Address: 00:15:83:33:5F:7E
Wait For Incoming Connection Request
And the controller doesn’t connect…. I’ve no idea…
I must say that i’m using the sparkfun’s shield, but the PS3USB example works really good…
@Joan
It’s properly a power issue. Try to plug in a external powersupply.
The problem is that the Sparkfun shield has an onboard 5V regulator connected to VIN, so you have to connect the Arduino to a source that is more than 5V.
@Lauszus
Thank you for your reply, I’ve put a external suply but now i get that:
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Local Bluetooth Address: 00:15:83:33:5F:7E
Wait For Incoming Connection Request
When I press the PS button nothing happen….
Is the bluetooth dongle incompatible or if there appears the bt address it is ok?
(excuse me of my english)
Thx
@Joan
Did you remember to pair with the PS3 controller first? See the wiki for more details: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller.
Your english is not a problem
Ok, really thank you.
@Joan
Your welcome
I still have one question that i can’t understand….
when I press any button i get 8 times the same button pressed….
I only erased the ps3.move code
any suggestion??
did u understand or u want the serial output?
thanx
@Joan
What version of the code are you running? It should have been fixed.
do you have any ideas on how to make a motor(via a motor shield) respond proportionally to one of the ps 3 controllers joy sticks?
@matt whitehouse
Yes simply connect your Arduino to a motorcontroller and then you can use the output of the PS3 joystick as the input to the analogWrite function: http://arduino.cc/en/Reference/AnalogWrite
are you using the statement:
to check and see if it is centered?
@matt whitehouse
Yes exactly.
PS: I modified your comment a bit, as our server messed up the formatting.
Hi!
I’ve just tried the wired USB as a start. The PS3USB-example compiles and runs. But my PS3 controller doesn’t want to acknowledge that it is plugged in to anything. It just blinks for a while and then shuts down.
The arduino with the shield is connected to a power source.
Is there any kind of configuration that has to be made so that it can detect that it is plugged in?
Regards,
Martin
@Martin
No I should work automatically. What does it print when you run this example sketch: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/PS3USB/PS3USB.ino?
im trying to use the ps3bt example. but i got this massage when i connect my playstatiion controller
PS3 Bluetooth Library Started
Dualshock 3 Controller Connected
Bluetooth Address was set to: 00:00:00:00:00:00
and when i have the dongle connect it says this
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1F:81:00:08:30
Wait For Incoming Connection Request
@Juan Carlos
You need to set the Bluetooth address of the dongle into the PS3 controller. Simply plug in the dongle, unplug it and then plug in the controller. The reason why you need to plug in the dongle first is because the program doesn’t know the dongle’s Bluetooth address.
This can also be set at compile time by changing the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3BT/PS3BT.ino#L12 to:
See this this page for more information:
https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller
I got it!! thanks you very much
I want to connect a bluetooth shield and a motor shield in an arduino uno. I know that my motor shield uses pins 4 throu 8 and 12. How can i know what pins are needed for the bluetooth
@Juan Carlos
The pins used by the USB Host Shield are 9, 10 and the SPI pins. These are 11, 12, and 13 on an Arduino Uno.
@Lauszus
It just says PS3 library started. Although I have the Sparkfun USB host shield and I’ve read that I should couple pin 7 to the reset pin. Is this true?
I’m going back to the lab tomorrow to try this if it is the case!
Regards,
Martin
@Martin
Yes that is true. Check out the schematics: https://www.sparkfun.com/datasheets/DevTools/Arduino/USBHostShield-v13.pdf and http://www.circuitsathome.com/wp/wp-content/uploads/2011/02/UHS_20.pdf. You can also just bend the GPX pin located at pin 8, as it’s not used by the library by default.
You might also need to connect a external power supply to the Arduino, as the Sparkfun shield has a 5V regulator connected to the VIN pin.
HELP ME PLEASE: Bluetooth Address was set to: 00:1F:81:00:08:30
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1F:81:00:08:30
Wait For Incoming Connection Request
@OSCAR
I guess you have set the Bluetooth address inside the PS3 controller: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller?
Please describe you problem in order for me to help you.
OK THANks my problem is: Bluetooth Address was set to: 00:1F:81:00:08:30
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Write class of device: in this part I do no understand, how write class of device? Can you help me please
@OSCAR
You don’t have to do write anything! These are just debug strings. Simply plug in the dongle, wait a bit, then unplug it. Plug in your PS3 controller and finally plug in your dongle again.
After that simply press PS on your PS3 controller and it will connect to the Bluetooth dongle.
ok I have communication but what is the code motor dc in a car rc. I have
int left = 2;
int right = 4;
void setup()
{
Serial.begin(115200);
pinMode (pwm, OUTPUT);
pinMode (left, OUTPUT);
pinMode (right, OUTPUT);
}
void loop()
{
if ( Serial.available())
{
char Up = Serial.read();
switch(Up)
{
case ‘Up’:
analogWrite (pwm , HIGH);
digitalWrite (left , HIGH);
digitalWrite (right , LOW);
break;
}
}
}
but it does not Because no stop
@OSCAR
In order to stop the motor you will need to set both left and right LOW or both of them HIGH.
Your support really helped me to much, A question I CAN program SIXAXIS? and how is the code?
@OSCAR
What do you mean? You want to program the actual PS3 controller? Then the answer is no. This code simply allows you to communicate with a PS3 controller.
Btw you can find much more information here: http://felis.github.io/USB_Host_Shield_2.0/class_p_s3_b_t.html and by reading the readme: https://github.com/felis/USB_Host_Shield_2.0#usb-host-library-rev20.
Lauszus,
Thanks for the post! Really helpfull! I am trying to accomplish this “simple” task of pair the controller with the dongle. But when I am already done with plugging dongle, registering address, unplugging it, plugging then the PS3 controller via USB cable, and…. when I put back the dongle into USB Host Shield, and press PS button, it starts the comunication, the blue light starts to blink at BT dongle, all of the lights of the controller became blinking rapidlly, and a message of Incomming connection appears at Serial monitor… But the handshaking does not complete itself. Any ideas? Thanks!
Renato Aloi
@Renato Aloi
Please send me the output from your serial monitor and I will have a look
Thanks! Here it is: PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1B:10:00:2A:EC
Wait For Incoming Connection Request
Dualshock 3 Controller Connected
Bluetooth Address was set to: 00:1B:10:00:2A:EC
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1B:10:00:2A:EC
Wait For Incoming Connection Request
Incoming Connection Request
Sorry about one thing I forgot to tell, my USB Host Shield is Keyes from funduino.com
Is it an issue?
Thanks,
Renato
Lauszus,
I have added an DEBUG log for hci_state to print at Serial. Here is the output:
PS3 Bluetooth Library Started
Bluetooth Dongle Initializedhci_state: 0
hci_state: 0
hci_state: 0
hci_state: 0
hci_state: 0
hci_state: 1
hci_state: 1
hci_state: 1
HCI Reset complete
hci_state: 2
hci_state: 2
Write class of device
hci_state: 3
hci_state: 3
Local Bluetooth Address: 00:1B:10:00:2A:EC
hci_state: 4
hci_state: 4
hci_state: 6
hci_state: 10
Wait For Incoming Connection Request
hci_state: 11
hci_state: 11
hci_state: 11
hci_state: 11
hci_state: 11
hci_state: 11
hci_state: 11
hci_state: 11
Incoming Connection Request
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
hci_state: 12
So when it enters in hci_state = 12 nothing more happens…
Hope you can help me. I dont know what I am doing wrong. I just bought a brand new PS3 controller, change the bluetooth dongle for that one with red light… HID compliant, of course.
Thanks again!
Renato
Lauszus,
Sorry about flooding the comments area with debug logs, but this one appears to be important. I rolled back the comment on EXTRADEBUG and voila!
PS3 Bluetooth Library Started
BTD Init
Addr: 01
Endpoint descriptor:
Length: 07
Type: 05
Address: 81
Attributes: 03
MaxPktSize: 0010
Poll Intrv: 01
Endpoint descriptor:
Length: 07
Type: 05
Address: 82
Attributes: 02
MaxPktSize: 0040
Poll Intrv: 01
Endpoint descriptor:
Length: 07
Type: 05
Address: 02
Attributes: 02
MaxPktSize: 0040
Poll Intrv: 01
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1B:10:00:2A:EC
Wait For Incoming Connection Request
Class of device: 00 05 08
Incoming Connection Request
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
Connection Failed
Wait For Incoming Connection Request
Class of device: 00 05 08
Incoming Connection Request
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
Connection Failed
Wait For Incoming Connection Request
Class of device: 00 05 08
Incoming Connection Request
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
Connection Failed
Wait For Incoming Connection Request
Class of device: 00 05 08
Incoming Connection Request
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
HCI event error: 06
Connection Failed
Wait For Incoming Connection Request
Praying for these error messages help to solve the problem, I am anxious to see this working! It is an amazing job you have done with this lib! Thank you very much!
Renato