Pages: [1]   Go Down
Author Topic: Step by step on how to connect a PS3 controller to an arduino via Bluetooth  (Read 9225 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
// 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:
Code:
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.
« Last Edit: January 08, 2013, 09:19:02 am by allanonmage » Logged

Monson, Massachusetts, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Iceland
Offline Offline
Newbie
*
Karma: 0
Posts: 20
“Any fool can know. The point is to understand.” --Albert Einstein
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Regards,
Gunnlaugur

Pages: [1]   Go Up
Jump to: