Step by step on how to connect a PS3 controller to an arduino via Bluetooth

I had to fill in a few gaps, but this wasn't as hard as I might have thought it to be. Still, there wasn't a guide so here's mine for the next guy. I found Oleg's and Laszarus's stuff and had already been working with the PS3 controller as a wired controller but wanted to shift to a wireless mode. I had the code, but it seemed like I was missing an important step or two.

For those of you that don't know, the pairing process of a PS3 controller to a host is different than most other Bluetooth devices like mice, keyboards, phones, etc. The PS3 controller needs to have the MAC of the host sent to it via USB first, then the controller will initiate the connection to the host. There's also a pinhole reset button on the bottom of the controller. That should wipe the address if you ever feel the need to.

Article/OP:
http://www.circuitsathome.com/mcu/bluetooth-code-for-arduino-usb-host/comment-page-1#comment-15294

How-to:

You have to go through an iterative process to get things going. First off the USB_Host_shield_2.0 library does work with Bluetooth now. That was unclear in the OP and comments due to their age (page and comments, not people). I managed to get this working with an Arduino MEGA ADK Rev 3 and a Cirago BTA-3210.

Step 1.
You need to run the PS3BT sketch with the Bluetooth (BT) dongle plugged in if you don’t have the MAC address already. If you do have the MAC, you can skip this part. Some dongles have the address on a sticker; some are too small for that. Mine was too small so I ran the sketch to find the MAC address. The MAC will be displayed in the Serial Monitor.

Step 2.
Hard code the MAC into the program in the commented out line:

// PS3BT PS3(&Btd,0×00,0×15,0×83,0x3D,0x0A,0×57); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch.

Make sure to uncomment the line too so that it will take effect.
This will send this address to the PS3 controller when connected. All you need to do is replace the hex digits after the “0x”. Make sure not to fat-finger it.
You'll want to comment out the other constructor so they don't interfere with each other:

PS3BT PS3(&Btd); // This will just create the instance

Step 3.
Remove the BT adapter and plug the USB cable into the PS3 controller and the USB host port or your arduino setup. USB is hot swappable but you can remove power first if you like. Note that while the hardware is hot swappable, the software probably isn't so you'll need to reboot for the arduino to see anything new plugged in.

I found that with the ADK I would have to plug in the BT adapter or the PS3 controller AFTER connecting the arduino to the PC. Otherwise the PC would not recognize the arduino COM port properly. I suspect it had to do with power draw, but never pursued the problem.

Step 4.
Reboot (or boot) your arduino. The modified code will send that address to the PS3 controller so that the controller can initiate the connection to the adapter. This is a similar process to how you pair a controller to a PS3.

Step 5.
Remove the USB cable from the PS3 controller to the arduino and plug your BT adapter back in.

Step 6.
Reboot/boot your arduino.

Step 7.
If it’s going to work, it should work. I verified it working by opening the serial monitor. The sample sketch shows you the button presses and certain values sent to the arduino.

The PlayStation button initiates the pairing. You might see all the LEDs flash at once for a bit while it gets started.

What should I change the MAC address to to connect the controller? After going through the process, the controller's LED's don't even blink, as if it never even found the MAC address to the Bluetooth dongle.

Also, should I comment out the "PS3BT PS3(&Btd); // This will just create the instance" and use "//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x56); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch"? I tried it, and it still never worked. Just wanted to know if I was doing something wrong.

You need to enter in the MAC address of the Bluetooth dongle into your code in the following line:

// PS3BT PS3(&Btd,0×00,0×15,0×83,0x3D,0x0A,0×57);

and yes, you do need to uncomment this line for it to work. There should be a similar constructor below it, you'll need to comment out that one so you don't overwrite your PS3BT object.

When you run the sketch with the BT dongle attached, it should spit out the MAC of the dongle. Does it do so? If you still need help, paste the output of the serial monitor here so I can see it.

i can't get the code to work. I have an arduino uno r3. I upload the code to the arduino...then i get a whole bunch of errors. Does anyone have code that works?? or a step by step guide....from the very first step. I need help. I am very new to arduino.

I upload the code to the arduino...then i get a whole bunch of errors.

I'm assuming that the errors come BEFORE the upload, like during the compile process. But, you don't seem inclined to share them.

Hi,
i use Arduino ADK R3 and this bluetooth adapter http://www.amazon.com/gp/product/B003VX3S3Y/ref=oh_details_o00_s00_i00 , but arduino stops at "PS3 Bluetooth Library Started" and does not go forward, i have I've modified the file avrpins.h uncommenting #define BOARD_MEGA_ADK.

I uploaded the sketch but it only shows "PS3 Bluetooth Library Started" in the serial monitor.
I thought if I uncommented "#define DEBUG_USB_HOST" in message.h I might be able to get the address, but then I get "avrdude stk500_recv() programmer is not responding" while uploading the sketch.

Any ideas or suggestions how I can fetch the MAC address of my bluetooth dongle?

Thank you.

hello!

I am trying to interface a ps3 controller via bluetooth to arduino mega 2560 adk.BUt didn't change the data coming from the ps3 controller.
i have attached the screenshot of the serial monitor data.
NEED HELP!

Wooohooo I got the PS3 controller to work with bluetooth. I have one question though. I noticed that the two joysticks values at full up are 0 and full down is 255. I need to reverse the right stick for tank style motor control. So lefty would be 0 to 255 and righty would be 255 to 0. What would be the best way to change this?

What would be the best way to change this?

ServoRight.write(255 - rightValue);

PaulS:
ServoRight.write(255 - rightValue);

OMG DUH sorry brain fart. Might have been overthinking that a bit.

I uploaded the sketch but it only shows "PS3 Bluetooth Library Started" in the serial monitor.
I thought if I uncommented "#define DEBUG_USB_HOST" in message.h I might be able to get the address, but then I get "avrdude stk500_recv() programmer is not responding" while uploading the sketch.

Any ideas or suggestions how I can fetch the MAC address of my bluetooth dongle?

I have the same problem. I tried 3 different dongles. Did you ever resolve this??
Note that if I run the board_qc sketch it sees the device?

I resolved the fact that it was halting on "PS3 Bluetooth Library Started" by rolling back from USB_Host_Shield_20 to USB_Host_Shield_Library and it worked straight away. I diffed the PS3BT sketch from each version and there was many differences. Not sure what caused the issue.

Hello I have a Uno r3, seedstudio motor shield v1.2, a USB shield with usb bluetooth dongle and a PS3 dualshock control which I would like to use this to control two DC motors in an RC car but I cannot figure out the code to get the motors to activate, a servo I can get going but not the motors via the shield. Any assistance would be greatly appreciated.

Thanks in advance!

#include <SD.h>
#include <PS3BT.h>

USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);

int speedpinA=9;//enable motor A
int speedpinB=10;//enable motor B
int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface
int pinI3=12;//define I3 interface
int pinI4=13;//define I4 interface
int spead =127;//define the spead of motor

void setup()
{
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(9,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(10,OUTPUT);
}

void setup() {
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
analogWrite(speedpinpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
}
void loop()
{
Usb.Task();

if(PS3.PS3Connected || PS3.PS3NavigationConnected) {

speedpinA.write(map(PS3.getAnalogHat(RightHatX), 0, 255, 0, 180));
speedpinB.write(map(PS3.getAnalogHat(LeftHatY), 0, 255, 180, 0));
}
else
{
speedpinA.write(90);
speedpinB.write(90);
}

if(PS3.getButtonClick(PS)) {
PS3.disconnect();
}
}

Try changing the pins of your motors, the usb shield are using pins 9,10,11,12,13 therefore you must not use them in any other applications...

i followed all the steps as u mentioned and im getting this..

PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 5C:F3:70:64:BB:F6
Wait For Incoming Connection Request
Dualshock 3 Controller Connected
Bluetooth Address was set to: 5C:F3:70:64:BB:F6
PS3 Bluetooth Library Started
Dualshock 3 Controller Connected
Bluetooth Address was set to: 5C:F3:70:64:BB:F6
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 5C:F3:70:64:BB:F6
Wait For Incoming Connection Request
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 5C:F3:70:64:BB:F6
Wait For Incoming Connection Request
Gamepad is connecting
Incoming Connection Request
Remote Name: PLAYSTA

i followed all the steps as u mentioned and im getting this..

PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 5C:F3:70:64:BB:F6
Wait For Incoming Connection Request
Dualshock 3 Controller Connected
Bluetooth Address was set to: 5C:F3:70:64:BB:F6
PS3 Bluetooth Library Started
Dualshock 3 Controller Connected
Bluetooth Address was set to: 5C:F3:70:64:BB:F6
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 5C:F3:70:64:BB:F6
Wait For Incoming Connection Request
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 5C:F3:70:64:BB:F6
Wait For Incoming Connection Request
Gamepad is connecting
Incoming Connection Request
Remote Name: PLAYSTA

Perhaps a bit off topic, but has anyone managed to do this WITHOUT using a usb-bluetooth and usb shield? I can understand needing it for setup, but if I plug in the mac address of another BT module capable of running in a central role...?

allanonmage,

Why I always show "Bluetooth Library Started PS3"

I am STILL having trouble with the bluetooth address, I have done everything you guys have done and it still doesn't do anything.

What should I do?

Orange321