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!
Oleg.
Is it possible to detect button hold? Thanx 😉
Yes, just use getButtonPress instead of getButtonClick.
Thank you again Lauszus 😉
Can we connect the ps3 controller to arduino wirelessly. If yes how can we do that and what do we need to add
Take a look at this blog post: http://www.circuitsathome.com/mcu/sony-ps3-controller-support-added-to-usb-host-library. All you need is a standard Bluetooth dongle and of course the USB Host Shield.
I am creating an RC spy car. I have the car but no control can I adapt an arduino microcontroller to the ps3 dual shock 3 and use it to control the rc car? Do I need to take the original board from the car and replace it with the arduino or do i still have to use the orignal board?
Check out this post at my blog: http://blog.tkjelectronics.dk/2011/02/wifi-controlled-rc-car-with-the-arduino/.
Hi, I’m a student who wants to make a remote controlled quadricopter PS3. I’m looking for information on how to control the PS3 controller in arduino and turn on some LEDs. Not that I have to do I am very novice at this … Would greatly appreciate if you give me some explanation, you saw the PS3 library. Could you guide me please to configure some command? Connect this to arduino and hence will try to turn an LED for each button.
All the information is available at the readme: https://github.com/felis/USB_Host_Shield_2.0#ps3-library and at the followng site: http://felis.github.io/USB_Host_Shield_2.0/.
To turn on an LED every time you pressed cross you could do something like this:
Note that you can not use pin 13 if you are using an Arduino Uno, as it’s used by the shield for SPI communication. See: http://www.circuitsathome.com/usb-host-shield-hardware-manual.
I looked on the github page and couldn’t find an answer, so I’m hoping you can help me: if you plugged a USB hub into the host shield, would it be possible to talk to multiple PS3 controllers? Also, will the controllers charge while plugged into the host shield?
Yes you simply just create a Hub instance like so:
USBHub Hub1(&Usb);
at this line: https://github.com/felis/USB_Host_Shield_2.0/blob/f8c0adc107b2ef7cbf383422c9d1fe3d0ad0b48f/examples/PS3USB/PS3USB.ino#L10 – yes they will charge as well. Make sure you use a powered hub though if you want to charge them all at once.
Btw it supports multiple controllers via Bluetooth as well – see: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3Multi/PS3Multi.ino.
Hi.
Great work!
I’m dreaming of the day when I could control my quadcopter with a ps3 controller, and not having to use an expensive 500$ Futaba system.
Ideally, we should be able to connect our PS3 controller to an arduino device, witch will send the commands further trough 2.4Ghz wireless system to a receiver mounted on the quad.
How complicated do you think this is?
I have actually tried to control my small IR helicopter using the PS3 controller. I simply hacked the IR protocol, but I found that it was much harder to control using the PS3 controller compared to use a normal transmitter. I actually just got a quadcopter recently, so I might try that at some point 🙂
I actually have a very cheap 9xr: http://www.hobbyking.com/hobbyking/store/__31544__Turnigy_9XR_Transmitter_Mode_2_No_Module_.html which I have flashed with the following firmware: https://code.google.com/p/companion9x/.
Since it got an ATmega1284 inside you should be able to port the part that communicate with the RF module pretty easily.
Hi again, Lauszus. I looked around, Xbee would seem like a nice way to go (around 2km outdoor with the 2.4Ghz version, much longer for the 900Hz ones). There are already quads being controlled with them, but from PC (even some with PS or Xbox connected to them).
So I’m thinking PS3 via USB or BT -> Arduino -> Xbee transmitter ======> quad Xbee receiver -> Flight Controller.
What do you think?
I think that would be much easier as well! Some receivers actually use serial communication, so you should be able to connect the Xbee directly to a compatible flight controller. For instance I use SBUS with my KK2 board and I also just use a satellite receivers directly as well.
You should check out this post about the SBUS: http://forum.arduino.cc/index.php/topic,99708.0.html – I have not tried it myself.
Also check out the OpenAero2 source: https://code.google.com/p/nextcopterplus/source/browse/trunk/OpenAero2/src/uart.c.
Hey how would I use a Servo with the ps3BT library? like for controlling it with a joystick? I love this project and am very excited to use the library but I cant find any tutorials so this would be a big help thanks.
You could just do something like this:
Reference: http://arduino.cc/en/reference/servo and http://arduino.cc/en/reference/map.
Well this has been a TREMENDOUS help. Thanks so much for this (and how fast you replied also). I cant tell you how much of a help this is.
Can you please tell me how to convert buttonClicks and buttonPresses to Commands PS3USB OR PS3BT.
I’m not sure what you mean? What are you trying to do?
I want to be able to control speedcontroller for brushless motor using PS3USB or PS3BT do you have any code for that.
hi, my english is very basic (i’m from LA, CHILE), it’s possible conect a PS3 Dualshock 3 with Arduino without USB Host Shield, i have a module of HC-06 Bluetooth, i can create comunnication between hc-06 and dualshock 3?
Thanks for the help!!!
you’d have to use a BT module which supports HID; I’m not sure they even exist.
No that will not be possible with any HC-06 Bluetooth module I know of. Also note that the PS3 controller also needs a special command before it will even send out any data. This is the reason why I used the USB Host shield, as it allowed me to control the behavior of a Bluetooth dongle just how I wanted. Furthermore in order to pair with the PS3 controller you need to set the Bluetooth address of the dongle via USB. This is another reason why you will have to use the USB Host shield, unless you pair with it using a custom application on your computer.
is it possible to control a dc motor with a motorshield? And if yes, how?
Cekstuffertz
can ı use wifi dongle on usb host shield
Do you have any information on using two ps3 controllers with the same arduino?
Please see the provided example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3Multi/PS3Multi.ino.
I have found some problems with delays in control response PS3 to control a brushless motor. When I press a button to increase the motor speed, for example, the response takes more than 5 seconds to occur. Do you have any idea what might be happening? Thanks for the help!
Please post your code somewhere (for instance at: https://gist.github.com/), so I can see what is going on.
I am trying to start and control speed of a bldc motor using PS3 L2 button
here’s the part of code :
//Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0) {
Serial.print(F(“\r\nL2: “));
Serial.print(PS3.getAnalogButton(L2_ANALOG));
pos = PS3.getAnalogButton(L2_ANALOG);
pos = map(pos, 0, 255,1000,2000);
esc.writeMicroseconds(pos);
Serial.print(F(“\tR2: “));
Serial.print(PS3.getAnalogButton(R2_ANALOG));
}
but when i press the L2 button nothing happens … plz help !!
Please enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging. Btw you are using a very old version of the code. Please download the newest version from Github.
Hi, I’m making an animatronic alien mask for a film and I want to control the servos in it with a ps3 controller & an arduino uno. What would be the best way to do this? I don’t want to use a dongle, I just want to plug the controller into the usb shield and go from there.
Also, is it possible to create combinations of servo movement and assign said movements to one button? e.g. Angry face – squint eyes and flare lips- by pressing triangle.
Thanks for any help, its much appreciated
Jack
Lauszus,
I went through comments section here found that ps3 cannot communicate with hc 06.
Hc 06 is a slave bt. But hc 05 can act as master. Can it be connected to hc 05 provided hc05 supports Bluetooth 2.0 with EDR.
if it cannot be connected that way, can ps3 be connected to Bluetooth module connected to usb-to-ttl connector? If it can be connected connected, is there a library for it? If not, could you provide me some docs on what handshakes are happening between bt and ps3 so that I can write a library myself?
Thanks
Sachin
Lauszus,
Why I always show “Bluetooth Library Started PS3”
Thanks
zhangdedezhi
Hi, its necessary a Arduino host shield in order to use this code? I have an arduino uno standalone and i pass the code through FTDI converter and i need to control some brushless motors without buying this host shield
Is it possible to use this code, but with the wires soldered to the GPIO headers? In other words, cut the end off of a USB PS3 controller and solder the 5v, ground, positive signal, and negative signal wires to the appropriate pins.
I purchased a Thrustmaster T-Flight Stick X Flight Stick (PC and PS3). I bought the USB shield 2.0 host for Arduino. I plugged it onto the Arduino and loaded the library example for PS3 (that came bundled with the libraries). It printed ‘PS3 library started’ or something like that but did not print anything when I clicked or moved the joystick. I don’t think that the joystick was recognized? How do I trouble shoot this? There is no error message in the serial monitor…There are many rows of pins on the top of the USB host shield but no instructions to connect any of them for different applications (or maybe I just did not find it)?
Thanks so much for the help,
How to solve this?
C:\Program Files\Arduino\libraries\USBHostShield\PS3BT.cpp: In member function ‘float PS3BT::getAngle(AngleEnum)’:
C:\Program Files\Arduino\libraries\USBHostShield\PS3BT.cpp:107: error: ‘atan2f’ was not declared in this scope
C:\Program Files\Arduino\libraries\USBHostShield\PS3BT.cpp:109: error: ‘atan2f’ was not declared in this scope
I used ver1.0.5-r2 and simply compiled the example: PS3BT
I keep getting this when I try to upload the example:
PS3USB:15: error: ‘USB’ does not name a type
PS3USB:17: error: ‘PS3USB’ does not name a type
PS3USB.ino: In function ‘void setup()’:
PS3USB:28: error: ‘Usb’ was not declared in this scope
PS3USB.ino: In function ‘void loop()’:
PS3USB:35: error: ‘Usb’ was not declared in this scope
PS3USB:37: error: ‘PS3’ was not declared in this scope
PS3USB:38: error: ‘LeftHatX’ was not declared in this scope
PS3USB:38: error: ‘LeftHatY’ was not declared in this scope
PS3USB:38: error: ‘RightHatX’ was not declared in this scope
PS3USB:38: error: ‘RightHatY’ was not declared in this scope
PS3USB:51: error: ‘L2’ was not declared in this scope
PS3USB:51: error: ‘R2’ was not declared in this scope
PS3USB:59: error: ‘PS’ was not declared in this scope
PS3USB:62: error: ‘TRIANGLE’ was not declared in this scope
PS3USB:64: error: ‘CIRCLE’ was not declared in this scope
PS3USB:66: error: ‘CROSS’ was not declared in this scope
PS3USB:68: error: ‘SQUARE’ was not declared in this scope
PS3USB:71: error: ‘UP’ was not declared in this scope
PS3USB:74: error: ‘LED4’ was not declared in this scope
PS3USB:76: error: ‘RIGHT’ was not declared in this scope
PS3USB:79: error: ‘LED1’ was not declared in this scope
PS3USB:81: error: ‘DOWN’ was not declared in this scope
PS3USB:84: error: ‘LED2’ was not declared in this scope
PS3USB:86: error: ‘LEFT’ was not declared in this scope
PS3USB:89: error: ‘LED3’ was not declared in this scope
PS3USB:92: error: ‘L1’ was not declared in this scope
PS3USB:94: error: ‘L3’ was not declared in this scope
PS3USB:96: error: ‘R1’ was not declared in this scope
PS3USB:98: error: ‘R3’ was not declared in this scope
PS3USB:101: error: ‘SELECT’ was not declared in this scope
PS3USB:105: error: ‘START’ was not declared in this scope
PS3USB:111: error: ‘Pitch’ was not declared in this scope
PS3USB:113: error: ‘Roll’ was not declared in this scope
PS3USB:119: error: ‘Off’ was not declared in this scope
PS3USB:122: error: ‘Red’ was not declared in this scope
PS3USB:125: error: ‘Green’ was not declared in this scope
PS3USB:128: error: ‘Blue’ was not declared in this scope
PS3USB:131: error: ‘Yellow’ was not declared in this scope
PS3USB:134: error: ‘Lightblue’ was not declared in this scope
PS3USB:137: error: ‘Purple’ was not declared in this scope
PS3USB:140: error: ‘White’ was not declared in this scope
Can anyone help me?
Hello sir.I modified my old rc car in order to work with PS3 controller.It works very well expect for the backwards.
When i press right, it turns right
When i press left, it turns left
When i press Forward, it goes forward
When i press backwards, doesn’t respond at all.
What i am doing Wrong.Please help me.I need your help, sir.
My code is this:
#include
USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);
int const pwm_drive = 6;
int const dir_drive = 7;
int const pwm_steer = 5;
int const dir_steer = 4;
void setup() {
Serial.begin(115200);
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect – used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F(“\r\nOSC did not start”));
while (1); //halt
}
Serial.print(F(“\r\nPS3 Bluetooth Library Started”));
pinMode(dir_drive, OUTPUT);
pinMode(dir_steer, OUTPUT);
pinMode(pwm_steer, OUTPUT);
pinMode(pwm_drive, OUTPUT);
}
void loop() {
Usb.Task();
if (PS3.getButtonClick(RIGHT)) {
Serial.print(F(“\r\nRight”));
PS3.moveSetBulb(Red);
digitalWrite(dir_steer, LOW);
analogWrite(pwm_steer, 255);
PS3.moveSetBulb(Off);
digitalWrite(dir_steer, 0);
analogWrite(pwm_steer, 0);
}
if (PS3.getButtonClick(LEFT)) {
Serial.print(F(“\r\nLeft”));
PS3.moveSetBulb(Green);
digitalWrite(dir_steer, HIGH);
analogWrite(pwm_steer, 255);
PS3.moveSetBulb(Off);
digitalWrite(dir_steer, 0);
analogWrite(pwm_steer, 0);
}
if (PS3.getButtonPress(CROSS)) {
digitalWrite(dir_drive, HIGH);
analogWrite(pwm_drive, 255);
}
if (PS3.getButtonPress(TRIANGLE)) {
digitalWrite(dir_drive, LOW);
analogWrite(pwm_drive, 255);
}
else {
digitalWrite(dir_drive, 0);
digitalWrite(dir_steer, 0);
analogWrite(pwm_steer, 0);
analogWrite(pwm_drive, 0);
}
if (PS3.getButtonClick(PS)) {
PS3.disconnect();
}
}