I’m quite pleased to announce that ever-popular Sony PS3 game controllers are now supported by current (rev.2.0) USB Host Library. Kristian Lauszus from TKJ Electronics developed a library to interface with Dualshock 3, as well as Move Navigation and Motion controllers via a Bluetooth dongle (only CSR-based ones are supported at the moment). This library has been merged into the main code and I will start maintaining it as soon as my Dualshock 3 arrives.
Sony PS3 controllers are advanced versions of ordinary HID joysticks. They can be interfaced via USB or Bluetooth, the buttons can be read as analog or digital and controller contains rumble motor which can be activated remotely to indicate a hit, for example. The controller also contains a gyroscope and accelerometers so it is possible to control a robot by simply waving and/or rotating the controller.
Kristian got his inspiration from Richard Ibbotson’s articles, as well as works by Tomoyuki Tanaka and others (full list can be found in PS3README file). His Wiki page gives implementation details, communication protocol, differences between controllers, as well as plenty of links to other sources of PS3 controller interfacing knowledge.
Kristian developed this library as a part of his Balancing robot project. The project is very well documented – if you are interested in robots, PID or remote control, please take a look. I also enjoyed watching this video presentation, give it a shot to see balancing robot in action.
Oleg.
This library is great! It’s saved me loads of time trying to get my hexapod robot responding to external input. Unfortunately I have an issue that I can’t figure out. I’ve got a CSR Bluetooth dongle visually identical to the one on the Balancing robot and am connecting it to an Arduino Mega ADK. I can then sync a PS3 Sixaxis controller to it and get the lights changing and read most of the inputs. However, I can’t read any of the analog buttons, the controllers status, or the motion sensor values. The same occurs with a different Belkin branded bluetooth dongle, but both work fine on PC when setup with MotioninJoy, able to read everything.
Anybody got any ideas what I’m doing wrong?
Hi,
I got one bluetooth dongle that has the exact same problem.
If you uncomment PRINTREPORT in PS3BT.cpp, you can see that the data is not changing. I still don’t know what the problem is. I had the same issue when I used it with the FEZ Devices: http://wiki.tinyclr.com/index.php?title=PS3_Controller with the same dongle.
I recommend getting a different dongle. Just buy some different ones at ebay and they will properly work. I think is related to if it’s supports EDR or not, but I’m not sure, as it must support V. 2.0+EDR.
Best Regards
Lauszus
The new ps3 library is graet. Thanks!
The library should work with Arduino UNO?
Did you use any timer or interrupt in the library? Can I still use timer2 to generate an constant 1 msec interrupt?
Thanks!
Yes it works with all the Arduinos supported by the USB Host Shield.
No I havn’t used timer2 in the library. I have only used the standard millis() and delay() functions which use timer0.
Regards
Lauszus
Fascinating articles guys, but what I would really like to see is an Xbox 360 Wireless Controller Library along similar lines to the PS3 and Wii libraries available. Is anybody doing any work on this?
Cheers
I might borrow a Wii Remote someday and port the library to version 2 of the usb host library ๐
For it to work with a wirelessly xbox controller, you will need a special receiver: http://www.amazon.com/Xbox-360-Wireless-Gaming-Receiver-Windows/dp/B000HZFCT2. I don’t know anybody who actually got one, so I don’t think I will create a library in the nearest future. But if I get my hands on a receiver I might take a look at it.
Regards
Lauszus
Hallo,
USB is working correctly with the Shield SPEEDLINK PS3 Controller Type SL-4445-BK.
Once connected via USB cable Controller in August and then reports the number of the program is part of BT Host to Controller. then when you insert the BT dongle everything works great.
But here I have a big problem … Original Sony PS3 Controller Model CECHZC2E b1 purchased today is not recognized by USB Shielt and I can not enter the host address to it .. I thought of is defective and replaced it with another … The same problem.
I tried to apply pressure all the keys on the Serial Monitor controller is there.
Is Genuine Controller Sony need to do something extra?
Please advice, I will not give you the same advice.
I send greetings
RomanF
Maybe Sony changed their controller recently? Check to see if VID/PID of your controller is different from one expected in the code -> https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3BT.h#L45
How do i pair PS3 controller with BT dongle?
Thanx ๐
See the wiki: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller ๐
@Lauszus, I have this code:
void loop() {
Usb.Task();
if(PS3.PS3Connected) {
if(PS3.getButton(TRIANGLE) {
Serial.print(“click”);
delay(1000);
}
}
}
On TRIANGLE press I get diffrent numbers of “click” on Serial monitor. From 6, 8 to 11. Why?
Thank you Lauszus! You are the best ๐
That sound very strange. What happens if you run the example sketch: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3BT/PS3BT.ino. Could you also send me all of the debug strings, so I can see what is going on?
What do you mean by “This can be achieved by plugging the controller in via USB and letting the library set it automatically”
Can you expand on this for me?
There is more information at the readme: https://github.com/felis/USB_Host_Shield_2.0#ps3-library
This is what i get if I press button TRIANGLE once and then CROSS:
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Local Bluetooth Address: 00:15:83:3D:0A:57
Wait For Incoming Connection Request
Incoming Connection Request
Remote Name: PLAYSTATION(R)3 Controller
Connected to Device: 04:76:6E:DA:DD:8C
Scan Disabled
Your dongle may not support reading the analog buttons, sensors and status
Your HCI Version is: 1
But should be at least 3
This means that it doesn’t support Bluetooth Version 2.0+EDR
HID Control Incoming Connection Request
HID Control Configuration Request
Wait For Incoming Connection Request
HID Control Successfully Configured
HID Interrupt Incoming Connection Request
HID Interrupt Configuration Request
HID Interrupt Successfully Configured
Dualshock 3 Controller Enabled
PS3 Controller – Traingle
PS3 Controller – Traingle
PS3 Controller – Traingle
PS3 Controller – Traingle
PS3 Controller – Traingle
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
PS3 Controller – Cross
I have tried this with 3 original Dualshock3 controllers on Arduino Mega and Leonardo.
What does this means “Your HCI Version is: 1”.
Does this applies to Bluetooth dongle or Dualshock3 controller?
Thankyou.
It applies to the Bluetooth dongle. The best answer I can give you is to try a different dongle, see the wiki for a list of cinfirmed working dongles: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Hardware
Hi Lauszus,
I’ve got a SparkFun USB Host Shield and a MadCatz PS3 controller. I downloaded the USB Host Library and ran the example sketch PS3USB (after changing the values for VID and PID in PS3USB.h so that they matched my controller’s) and the serial monitor is continuously scrolling and the parameter values don’t change regardless of whether or not I’m pressing any buttons on my controller.
Are there more values that I need to change in the header file? Or is this how the sketch should run? I’m a bit new to this so any help would be appreciated, thanks.
I’ve since gotten a usb cable for my official sony PS3 controller. I changed the VID and PID values once again and the sketch shows
PS3 USB Library Started
Dualshock 3 Controller Connected
Bluetooth Address was set to: 00:00:00:00:00:00
and nothing else; it doesn’t respond to any button presses/holds.
Try to connect an external power supply to the Arduino.
The Sparkfun shield rely on a VIN that it’s greater than 5V since it got an onboard 5V regulator connected to VIN on the Arduino.
hi, i have a problem to pair the dongle with the control( i have 2 dualshocks and 1 sixaxis only detects the sixaxis i dont know why) when i started the serial monitor detect the dongle and shows the address, then i plugged the control and showed dualshock 3 detected and show the same address of the dongle, plug the dongle again and push the ps button but it didnยดt pair only flash, what can be the problem? thanks a lot
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1F:81:00:02:50
Wait For Incoming Connection Request
Write clase of device?
This simply sets the type of the device other devices will see when they do an inquiry. See these lines for more information: https://github.com/felis/USB_Host_Shield_2.0/blob/91d719557762b196e5cd8dccd87ebf9038535142/BTD.cpp#L1024-L1033.
Please post the output from your console when you pair with the controller and I will have a look at it ๐
THANKS FOR ANSWERED, I DONT KNOW VERY MUCH OF THIS,WHAT DO YOU WANT TO LOOK? I DONT UNDERSTAND, COULD YOU EXPLAIN ME WITH MORE DETAILS, PLEASE, I NEED TO CHANGE SOMETHING IN THE SKETCH? THANKS
Please send me the output from the serial monitor after you have done the following: plug in the dongle and then unplug it again. Then plug in your PS3 controller.
Ps3 bluetooth library started
Bluetooth dongle initialized
Hci reset complete
Write class of device
Local bluetooth address:00:1f:81:00:02:50
Wait for incoming connection request
Dualshock 3 controller conected
Bluetooth adress was set to :00:1f:81:00:02:50
Bluetooth dongle initialized
No response to hci reset
Hci reset complete
Write class of device
Local bluetooth adress: 00:1f:81:00:02:50
Wait for incoming conection request
Incoming connection request
Thats all and no pair
The paring is working fine. It is happening when you plug in your PS3 controller and the following line gets printed:
Bluetooth adress was set to :00:1f:81:00:02:50
It’s a problem with your Bluetooth dongle. You will have to try a different one!
Ok i will, the dongle needs something particular? Thanks
See this comment for more information: https://www.circuitsathome.com/mcu/bluetooth-code-for-arduino-usb-host/comment-page-1#comment-21600 ๐
Hello , I would like to thank you for the library .
Iโm using it to control a motor of a rc Car using the ps3 controller by Bluetooth and arduino .
Im now in the programming process and I want to use switches or else the programe will be too long
so what should I edit to me code so that the the switch happens when I press a button
switch (when button pressed) {
case โPS3.getButtonPress(CROSS)โ:
digitalWrite(BLP, HIGH);
break;
case โPS3.getButtonPress(SQUARE)โ:
digitalWrite(BLP, LOW);
break;
}
Im trying to use the ps3bt with the arduino adk but its not working
the serial port gives me the following
OSC did not start
I have replied to both your comments at my blog: http://blog.tkjelectronics.dk/2013/01/usb-host-shield-is-now-available-in-the-webshop/#comment-420324.
How can I detect the PS3 has lost communications in my code? If this happens with the motors on, I need to turn them off. Thanks.
Simply check if
PS3.PS3Connected
is false.It looks like that information is not resetting, when an unexpected drop occurs.
I am simulating the connection drop by hitting the reset button on the PS3.
It looks like an unexpected disconnect is detected by HCI Event after about 20 seconds. I still can’t react to this in my sketch. I would like to turn the motors off instantly; 20 seconds is way too long. Can you please help me?
Are you pressing the reset button on the PS3 controller? In a real case scenario the PS3 controller disconnects when it get low on battery etc.
What you could do it reset a timer every time data is received here: https://github.com/felis/USB_Host_Shield_2.0/blob/8e6ab3f3ae6fc86a18c78c010b6d9b351b488a4d/PS3BT.cpp#L364. If there is a stop in the data you would know if the controller is disconnected.
I have this hooked up to my CMM (Coordinate Measuring Machine) at work. Some how it lost communications and the arm keep going. I had to run over to the wired controller to stop it before it crashed. Thanks for the response, I’ll try your advice and let you know.
I hate to bug; I see your a busy man. The timer method is inconsistent. Though I can detect a stop in data and react quickly in my sketch, which is great, it also triggers too often when the connection is good. Is there another way to check if the connection is good.
That is why I wanted to use a timer instead of always setting a flag if there is no data – the Arduino might be polling data faster than the PS3 controller actually sends it.
Instead you could reset a timer every time new data is received:
timer = millis();
And then just set a flag if the timer gets above a certain value.
Thanks for your help. I have it turn the motors off after each 200 millis delay. If it detects the PS3 button being pressed after that, it turns the motors right back on. If the 200 millis delay is detected 5 times in a row, it does a proper disconnect of the PS3.
It looks like that information is not resetting when an unexpected drop occurs.
Please disregard this thread.
Hello,
Im using a arduino leonardo and everytime i try to upload the PS3BT sketch I get the error that it is too large. Is there anyway to cut it down that way i can use it. My dongles work and everything i just can’t run the PS3BT.
Thanks
You can simply remove some of the irrelevant code in the example.
You can start by removing all the parts relevant to the Move controller: https://github.com/felis/USB_Host_Shield_2.0/blob/f8c0adc107b2ef7cbf383422c9d1fe3d0ad0b48f/examples/Bluetooth/PS3BT/PS3BT.ino#L123-L174.
After that remove these lines: https://github.com/felis/USB_Host_Shield_2.0/blob/f8c0adc107b2ef7cbf383422c9d1fe3d0ad0b48f/examples/Bluetooth/PS3BT/PS3BT.ino#L116-L121 and this line: https://github.com/felis/USB_Host_Shield_2.0/blob/f8c0adc107b2ef7cbf383422c9d1fe3d0ad0b48f/examples/Bluetooth/PS3BT/PS3BT.ino#L109. Now you should be able to compile it ๐
You can also remove the hub instance as well: https://github.com/felis/USB_Host_Shield_2.0/blob/f8c0adc107b2ef7cbf383422c9d1fe3d0ad0b48f/examples/Bluetooth/PS3BT/PS3BT.ino#L11. It is only needed for some Bluetooth dongles.
Hello, I’m using a USB Host Shield full size w/ Arduino Uno and confirmed compatible Bluetooth dongle.
When I start the serial monitor on several different sketches the library starts, but no further text is generated. For the PS3BT example it says
PS3 Bluetooth Library Started
No further information is given.
Any idea why this is happening?
Please see: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging.
After running a few different sketches the dongle started initializing for all of them, so that worked out.
My project involves two arduinos with USB host modules and identical Bluetooth dongles connecting with one another and exchanging data. What loop would cause one arduino to send pairing requests to other bluetooth devices? I’d need them to automatically pair with whitelisted addresses.
You can use this function: https://github.com/felis/USB_Host_Shield_2.0/blob/0c0541344752c9778e328ea17995c8ddc889b503/BTD.h#L399 to connect to any device. Note this will only establish a HCI connection.
I am experiencing difficulty similar to drewfire’s comments from November 6th, 2013. In my case, I believe that the drops are being caused by heavy wifi traffic in the area. I am going to implement the timing strategy that was discussed previously, but I would greatly prefer to minimize the number of hangups. I have read that BT 3.0 will run outside of the ISM band. Will your libraries function with BT 3.0? Do you have any suggestions as to how I can help minimize the occurrence of these incidents.
Just to give everybody else an update:
I have added this function: https://github.com/felis/USB_Host_Shield_2.0/commit/983a7d664fc5b89732e2dcfe75680684d1706270 that Tom wrote and sent to me via email. This should allow you to read how long it has been since an input report was last received.
If the value gets too large, then simply assume that the controller is disconnected.
And yes the library works with Bluetooth 3.0.
Is there a way to determine the MAC address of a PS3 connector from within a sketch?
I see that it is printed as debug when establishing a connection, but I’m not seeing a method to access that data.
I was thinking about an application using two controllers, and was hoping to ensure which controller gets assigned to a “PS3Left” and “PS3Right”. Using the MAC address seemed like the most natural way to accomplish this.
You can access disc_bdaddr in BTD: https://github.com/felis/USB_Host_Shield_2.0/blob/0c0541344752c9778e328ea17995c8ddc889b503/BTD.h#L489.
Thanks
I did see that – but with it only being the “last” device,
I was missing how I would be able to make an association with multiple connected devices.
Then it hit me:
That I could leverage this, and write the functionality that I need in onPSInit():
PS3.attachOnInit(onPSInit);
Tested with this, and looks like it works. Just need to do something useful now!
void onPSInit()
{
Serial.print(“\r\nBT Address of Last connected Device: “);
for(int8_t i = 5; i > 0; i–) {
Serial.print(Btd.disc_bdaddr[i], HEX);
Serial.print(“:”);
}
Serial.println(Btd.disc_bdaddr[0], HEX);
}
Yes that is exactly what the attachOnInit function is for ๐
Hi there!
thanks so much for the library. It appears that there is a problem with my dongle. I bought three dongles that are identical to the approved dongles, but with each one i get the error:
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Local Bluetooth Address: 00:15:83:3D:0A:57
Wait For Incoming Connection Request
Incoming Connection Request
Remote Name: PLAYSTATION(R)3 Controller
Connected to Device: 04:76:6E:DA:05:D4
Your dongle may not support reading the analog buttons, sensors and status
Your HCI Version is: 2
But should be at least 3
This means that it doesn’t support Bluetooth Version 2.0+EDR
HID Control Incoming Connection Request
HID Control Configuration Request
HID Control Successfully Configured
HID Interrupt Incoming Connection Request
HID Interrupt Configuration Request
HID Interrupt Successfully Configured
Wait For Incoming Connection Request
Dualshock 3 Controller Enabled
the main concern for me is the line that says “your HCI version is 2, but should be at least 3”.
All my buttons work except l2 and r2, the analog triggers. these will be crucial to the robot i am building for school, please help!
Hi there!
i have some problems when i use the PS3BT.im new to arduino and the error is
PS3BT:14: error: ‘USB’ does not name a type
Hey,
I am using arduino ADK to control servo motors. What are the changes are to be made as compared to interfacing ps3 with uno….please reply me as earlier as possible
Hi, Why USB shield and USB BT Dongle????????? No way to connect PS3 Controller direct to BT module???? for any initial setup of PS3 Cont. use PC??? may a total stupid idea by me!!!
Thanks! Good work but to complicated..
Hello,
Thanks for the code.Iยดd like to use 2 ps3 navigation controller instead of one.
Iยดve got one working but the other one can not paired.
Do you have any idea in how can i use both?
It would be just like the ps3 regular controller with 2 joystyck,bt this is a navigation with one in each controller.
Thanks in advance.
regards
carlos
hi
Need help,library works with my ps3 controller only issue was it was only working when my arduino board was plug on usb port of PC or laptop.
Im trying to make it stand alone and it was not working when arduino was powered by external power supply.
regards,
BON