I've fixed a couple of running bugs with the data packet, and I've modified the NXTI2CDevice library to be compatible with Arduino 1.0.
The attached zip file has
1. a new Arduino sketch
2. a new Processing sketch
3. the modified NXTI2CDevice library

You'll still need the Procontroll library in Processing, though.

Greetings, everyone, and welcome to my first instructable!
Today we'll be covering a few major bases to get to the final goal: controlling an Arduino-based robot via a PS3 remote! By the end of this instructable, you'll be able to control the speeds of both NXT motors with the two analog sticks of a PS3 controller.

Here's the idea:  
A PS3 communicates via bluetooth to the computer sending the value of its analog sticks to the Processing program.  Processing then sends this information as a packet of data to the Arduino bot through the Xbee wireless modules.  Lastly, the Arduino board "unpacks" this data packet and interprets it as the speed and direction to drive each motor.

Here are the  three basic milestones that we'll cover:

-- using Arduino to control NXT Motors
-- interfacing the Programming Language Processing with a PS3 controller
-- Wireless communication between your computer and Arduino via Xbee modules

If you aren't quite comfortable with either Processing or Arduino's Programming languages--fear not!  I've accompanied the project with my source code .

Here's what I'll assume:
-- you're mildly familiar with Arduino, and you can a user-created library to the IDE.
-- your computer has bluetooth-pairing capabilities
-- you can strip a few small wires and you have basic soldering skills.

Here's a few concepts that you'll learn about on the side:
(You don't need to know about these beforehand to get started on this project)
-- Xbee wireless communication
-- i2c communication (between the NXT motors and Arduino)

All right, Let's get started!

Lastly, feel free to check out the video for the final results of this project in action!


Step 1: Materials

For this instructable, you'll need quite a few things, but we're covering some major milestones in the process, and, heck, all of these parts can be reused for later projects!

I got the hard-to-find (nonLego) pieces from both Sparkfun.com and Mindsensors.com

Robot Materials:
-- two Mindstorms NXT Motors and two cables
-- Lego Technic Pieces to build your robot Chassis
-- Standard Arduino (I used the UNO.  This actually allows me to skip adding pull-up resistors to the analog inputs)
-- 9V batter and 9V battery Clip to power the Arduino.  ( We could power it off the motor battery, but I'll hold off on that to keep it simple.)
-- Battery Pack (or other power supply.  I'm using a 7.2V NiMH pack)
-- I2C Host Cable with NXT Connector
-- Tape (Gaffer's Tape is probably the least messy, but any tape will do the job)


-- Multiplexer for NXT Motors (this piece gives us the ability to speak to the NXT motors lots of ugly wire snipping)


Communication Materials
-- 2 XBee 1mW Wire Antennas  (Xbee radios)

-- XBee Explorer USB connector

-- XBee Wireless Shield

Other Hardware:
-- header pins (longer header pins are a bit more user-friendly)
-- PS3 controller
-- mini USB cable for connecting the Xbee to your computer
-- USB cable to program the Arduino

A bundle of OpenSource Software:
-- The Arduino IDE
-- Processing

-- The NXT Library for speaking to the NXT i2c Motors
(Side note:  This NXT Library is a great project all to itself!  Check out the man Clinton Blackmore behind the accomplishment at   http://robotclub.ab.ca/   )
-- The Processing Language Library called Pro Controll which will allow us to communicate with the PS3 controller. 

Final Tools to get the job done:
-- Soldering Iron
-- Solder
-- Exacto knife (or any small-and-precise knife)
-- wire strippers for stripping very thin wire.
<p>What exactly do I need? What is this &quot;XBee radio&quot; that you refer to? Do I need an adaptor for that to an Arduino? Where do I get the XBee radio? How do I connect it to an Arduino?</p>
Can I simply link the arduino to the computer instead of using the XBee? <br>I keep hearing you say that you want to figure out if you can do this or that...can you please actually do it? Range doesn't matter to me, so Can I or Can't I directly bluetooth the Ps3 controller to an arduino shield? <br>Thanks, but I really just need some way to take Ps3 controller stick movement and tie that to analog output pins on arduino. Can I cut out all of the wireless, just for a start?
Wait. So XBee can communicate with PS3 controllers?
Can u explain why u need 2 Xbee radios for this, instead of 1? <br> <br>Thanks, <br>Sjors
Sure, sjors073. The Controller needs to communicate with the robot wirelessly. First I'm sending the controller's signals to the computer via the computer's built-in bluetooth radio. The computer then has to transmit these signals over to the robot. There are many ways to do this, but I chose Xbees for their simplicity. The computer needs an Xbee attached to send out the data to the robot via radio waves. The robot then uses it's onboard Xbee to receive the radio waves and interpret the data sent wirelessly from the computer. The idea is that the two Xbees are like Walkie-talkies. The robot has one, and the computer has one. since Xbees and the Ps3 controller communicate wirelessly in two totally different ways, I&quot;m having the computer stand in as the middle-man, converting the information from one signal into information for the other.
Alright i get it. <br> <br>So this means that i cannot controll my robot without a computer/laptop as a middle-man? I always have to take my laptop with me to controll the robot? <br> <br>We're building a remote controlled hovercraft, and we'd like to controll it with a ps3 controller. We know the range of the ps3 controller isn't that far, but we can walk after the hovercraft when controlling, that's not a problem. But do we have to take our laptop with us too, to controll it properly? <br> <br>Many thanks for the fast reply, <br>Sjors
That's right; the ps3 controller has a very weird Bluetooth setup in that it doesn't give out it's address to let other devices talk to it unless it's physically connected to that device first, via a cable. It's way easier to do that on a computer than on the robot itself, so I opted for the xbees. Yep, you will have to take your computer with you, but on the plus side, your range of control will be limited by the Xbees, not the ps3 controller, which has about a 10 ft range. Depending on the model Xbees you get, you could have a decent range of control of a few hundred feet! Just note that the xbees that I have listed here had about a 50 ft range. I'm planning on redoing this instructable code for the arduino and ps3 controller to make it slightly more robust in the coming weeks. If you start soon and have some trouble with the code, rest assured that I should have a new version in the near future.
Please can I got your code ? :) <br><br>
I'm having a problem while testing the controller<br> <br> <br> Failed to poll device: Failed to poll device (8007000c)<br> Failed to poll device: Failed to poll device (8007000c)<br> <br> 0<br> 0<br> 0<br> 0<br> <br> &lt;&lt;&lt; available PLAYSTATION(R)3 Controller sliders: &gt;&gt;&gt;<br> <br> &nbsp; &nbsp; &nbsp;0: Z Rotation absolute<br> &nbsp; &nbsp; &nbsp;1: Z Axis absolute<br> &nbsp; &nbsp; &nbsp;2: Y Axis absolute<br> &nbsp; &nbsp; &nbsp;3: X Axis absolute<br> &nbsp; &nbsp; &nbsp;4: Pointer absolute<br> <br> &lt;&lt;&lt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br> <br> &lt;&lt;&lt; available PLAYSTATION(R)3 Controller buttons: &gt;&gt;&gt;<br> <br> &nbsp; &nbsp; &nbsp;0: Button 0<br> &nbsp; &nbsp; &nbsp;1: Button 1<br> &nbsp; &nbsp; &nbsp;2: Button 2<br> &nbsp; &nbsp; &nbsp;3: Button 3<br> &nbsp; &nbsp; &nbsp;4: Button 4<br> &nbsp; &nbsp; &nbsp;5: Button 5<br> &nbsp; &nbsp; &nbsp;6: Button 6<br> &nbsp; &nbsp; &nbsp;7: Button 7<br> &nbsp; &nbsp; &nbsp;8: Button 8<br> &nbsp; &nbsp; &nbsp;9: Button 9<br> &nbsp; &nbsp; &nbsp;10: Button 10<br> &nbsp; &nbsp; &nbsp;11: Button 11<br> &nbsp; &nbsp; &nbsp;12: Button 12<br> &nbsp; &nbsp; &nbsp;13: Button 13<br> &nbsp; &nbsp; &nbsp;14: Button 14<br> &nbsp; &nbsp; &nbsp;15: Button 15<br> &nbsp; &nbsp; &nbsp;16: Button 16<br> &nbsp; &nbsp; &nbsp;17: Button 17<br> &nbsp; &nbsp; &nbsp;18: Button 18<br> <br> &lt;&lt;&lt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br> Exception in thread &quot;Animation Thread&quot; java.lang<br> .NullPointerException<br> &nbsp;at Test.draw(Test.java:60)<br> &nbsp;at processing.core.PApplet.handleDraw(Unknown Source)<br> &nbsp;at processing.core.PApplet.run(Unknown Source)<br> &nbsp;at java.lang.Thread.run(Thread.java:662)<br> <br>
It looks like the library doesn't correctly understand the information from the controller. This actually may have to do with the driver of the ps3 controller, not the code itself. I actually don't have access to a ps3 controller right now, but I may be able to help in a day or two. <br><br>It looks like the driver is telling the proCONTROLL library that there are buttons or some other method of input that actually doesn't exist. <br><br>At this point, can you actually see the &quot;paired&quot; bluetooth symbol if you try to connect the controller to your computer?
lm using ds3 tool to my controller and the controller is connected by USB cable not BLUETOOTH DONGLE so there will be no bluetooth symbol
Hello, I'm having the same problem as devil and it's allready 2012 and I don't see a response to this problem..can you please help? (I think many ran into this problem). Ty.
I installed the library proCONTROLL processing is not top of my hair
I installed proCONTROLL library in processing.
Hey I am interested in doing something similar but I'm wondering how to go about it without the NXT motors, is it possible? Mostly I'm interested in how the micro controller on the robot would be programmed
can i use the following Battery if not which one <br><br>http://www.ebay.co.uk/itm/Ansmann-RC-Car-7-2v-3000mah-Battery-Delta-Pro-Charger-/280716528572?pt=UK_ToysGames_RadioControlled_JN&amp;hash=item415c024bbc<br><br>please reply ASAP!!!
Yes, this battery should work nicely. It's a great find! You may want to pick up an extra set of connectors to plug power into the NXT motors; otherwise, you'll need to cut the wires and connect those loose ends directly to the board. You can find a few extra male connectors on that same site here:<br> <br> <a href="http://www.ebay.co.uk/itm/RC-Ansmann-Male-Tamiya-Battery-Connector-5pcs-ESC-wire-/260817463004?pt=UK_ToysGames_RadioControlled_JN&hash=item3cb9eea6dc">http://www.ebay.co.uk/itm/RC-Ansmann-Male-Tamiya-Battery-Connector-5pcs-ESC-wire-/260817463004?pt=UK_ToysGames_RadioControlled_JN&amp;hash=item3cb9eea6dc</a><br>
I was about ask abou that thanks .PLEASE HELP ME WITH THE CONTROLLER TEST
Sure thing; I'll be able to take a closer look at it this evening. (I currently can't get to a controller until then.)
I m about to order every thing but i cant find theI2ccable that the only thing misiing from my list. Can u please give me a Url or type or name of the cable and for the robot chassia aswell please.
For the i2c cable, check out this website: http://www.mindsensors.com/index.php?module=pagemaster&amp;PAGE_user_op=view_page&amp;PAGE_id=136<br><br>I actually built the robot chassis using spare lego technic parts. The chassis itself doesn't matter for this instructable, so feel free to build your own, as long as it uses two nxt motors: one for each side of the robot.<br><br>Don't forget that you'll also need the multiplexor board to connect the motors into the cable also! You can find that here:<br><br>http://www.mindsensors.com/index.php?module=pagemaster&amp;PAGE_user_op=view_page&amp;PAGE_id=134<br><br>Have fun, and i'd love to here how it goes!<br><br>
Thanks <br>jsut need to orderthe stuff now.Could u please help me with processing (controller test)<br><br>=============================================================<br><br>Failed to poll device: Failed to poll device (8007000c)<br>Failed to poll device: Failed to poll device (8007000c)<br><br>0<br>0<br>0<br>0<br><br>&lt;&lt;&lt; available PLAYSTATION(R)3 Controller sliders: &gt;&gt;&gt;<br><br> 0: Z Rotation absolute<br> 1: Z Axis absolute<br> 2: Y Axis absolute<br> 3: X Axis absolute<br> 4: Pointer absolute<br><br>&lt;&lt;&lt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br><br>&lt;&lt;&lt; available PLAYSTATION(R)3 Controller buttons: &gt;&gt;&gt;<br><br> 0: Button 0<br> 1: Button 1<br> 2: Button 2<br> 3: Button 3<br> 4: Button 4<br> 5: Button 5<br> 6: Button 6<br> 7: Button 7<br> 8: Button 8<br> 9: Button 9<br> 10: Button 10<br> 11: Button 11<br> 12: Button 12<br> 13: Button 13<br> 14: Button 14<br> 15: Button 15<br> 16: Button 16<br> 17: Button 17<br> 18: Button 18<br><br>&lt;&lt;&lt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>Exception in thread &quot;Animation Thread&quot; java.lang<br>.NullPointerException<br> at Test.draw(Test.java:60)<br> at processing.core.PApplet.handleDraw(Unknown Source)<br> at processing.core.PApplet.run(Unknown Source)<br> at java.lang.Thread.run(Thread.java:662)
IS your controller connected wireless ley??? if yes how??? <br>:( :(
Ah, you're right! Not a problem. I've found another video tutorial that covers the same thing. Here's the link:<br><br><br>http://www.youtube.com/watch?v=y5LiI4uGXNk<br><br><br>(I will make the changes in the instructable itself also. Thanks for catching this!)<br><br>Also, I haven't yet looked into drivers for the PS3 controller on systems other than MacOSX to create instructables for them. I don't have a Windows system to try them out.<br><br>You might have some luck here though:<br><br>http://hackaday.com/2009/01/11/windows-drivers-for-ps3-controllers/
Can i use another vehicle instead of the lego kit?and if so what will i need to watch out for?
You should check my guide, as I write above. Here is the link anyway:&nbsp;<a href="http://arduino.cc/forum/index.php/topic,65022.msg475001.html#msg475001">http://arduino.cc/forum/index.php/topic,65022.msg475001.html#msg475001</a>
Yes, Absolutely!<br><br>In your case, I'm doubting that your motors will have the same interface as the I2C interface on the NXT motors.<br>You'll need to find some way of communicating with the motors. Usually, this involves clipping the motor wires and wiring them up to an H-bridge. Then, the arduino communicates to the H-bridge instead.<br><br>There are quite a few examples online of how to do this. Here are a couple good places to get started:<br><br>http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/<br><br>http://itp.nyu.edu/physcomp/Labs/DCMotorControl<br><br>https://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/#<br><br>http://www.societyofrobots.com/member_tutorials/node/164<br><br>I hope that this helps!
Check my post. I have succesfully made a NXT Motor Shield. I have made a little guide to the theory behind, and given some code demonstrations, including videos. Check it out:&nbsp;<a href="http://arduino.cc/forum/index.php/topic,65022.msg475001.html#msg475001">http://arduino.cc/forum/index.php/topic,65022.msg475001.html#msg475001</a>
also where can i find the 2 xbees?
If you're not using the internet, Xbees can be tough to come by.<br><br>(I'm not sure of any retailers that aren't online.)<br><br>Online, though, shouldn't be a problem.<br><br>you can find them on <br><br>sparkfun.com<br>or<br>http://search.digikey.com/scripts/DkSearch/dksus.dll?Selection<br>or<br>http://www.robotshop.com/ProductSearch.aspx?qs=xbee<br><br>I'd recommend Sparkfun because they also sell the other components that this instructable uses.
I think you can communicate directly! http://cgi.ebay.co.uk/Wireless-Bluetooth-Transceiver-Slave-Module-PCB-Adapter-/200521469684?pt=LH_DefaultDomain_0&amp;hash=item2eb002cef4 is selling bluetooth to UART serial converter, the ps3 controller pairs up to it automatically and starts streaming data. the only pins needed are +3.3v, GRD, Tx &amp; Rx. But i haven't tried it yet.
instead of using the xbees and computer couldn't you have gotten a bluetooth shield for the arduino and paired it to the ps3 controller?
Ah yes! At the time, I had the xbees available from an earlier project, so I decided to make use of them here. I have to say, I'd love to try interfacing with the bluetooth shield and PS3 controller directly, but I&quot;m not sure how they communicate with each other. I may not be able to get the Arduino to recognize the specific commands sent by the different button pushes and analog stick tilts. The Processing route made the commands a bit more explicit by only sending data that was specific to motor control. Do you know how these bluetooth devices would communicate with each other?
I'm pretty sure, that you have to get some kind of shield, because both the ps3 controller and the arduino bluetooth isn't a host module.
Is that even possible? I have googled it. But can't find any there has be able to connect a ps3 controller to a arduino via a bluetooth shield. The only thing i have seen is this: http://www.circuitsathome.com/arduino_usb_host_shield_projects. Where he connect a ps3 controller to the arduino via a usb host shield.<br>
That's a really good point. Theoretically, because both the controller and the Arduino bluetooth shield can communicate through bluetooth signals, we should be able to pair them and listen to the signals sent by the PS3 controller. I haven't tried it because I know that it's probably a bit more complicated in practice.<br><br>In my case, because the kind folks who created the proControll library were able to interface with a PS3 controller via Processing, and because Processing can send signals via a serial connection, I just took the project a step further by making a wireless serial connection between the computer and the Arduino via Xbee radios. <br><br>

About This Instructable




More by nahamancygig:RC Nintendo GameCube Robot Use a PS3 Controller to control an Arduino NXT Bot 
Add instructable to: