Awesome Sauce Wixel & Arduino/Atmega Based PlayStation 2 Project Controller
The Reason
Ok, so I was at my girlfriend’s family’s place on some recent holiday and I was being asked to show off what my robot ABE could do. I did the fully automated things by turning him on and doing a few little pre-programmed responsive actions (covering his “eyes”, covering both IR sensors etc1) but I quickly realised that in order to show off his full bag of tricks, I would have to send him a few commands (or at least requests). At the time, the only way to do that was to take my other Wixel unit, plug it into my computer and send it some serial love. I had no computer setup there, nor my other Wixel.
The Design
At first I had intended to add two interrupt buttons to ABE and I even studied Schmitt circuitry to that end. Then, I had a better idea - I would add an infrared remote to him. While I was looking into that option, I had the best idea yet. Why should I waste even more power on extra components when ABE already has inbuilt wireless comms via the Wixel? Why don’t I just build a Wixel-enabled remote control?
The Better Design
To begin with, I ordered an LCD from Little Bird Electronics along with a few other parts for various new ideas. I had intended to use some old contact pads I had laying around for the buttons but I couldn’t come up with a design that I liked. It had to be light, portable and I had to want to use it.
After a bit of pondering, I remembered that I had an extra PS2 controller in a box doing nothing except tangling my other cabling up. Surely someone had already thought of this before? Google time!
Feasiblity Study
I looked around for an Arduino library to communicate with a PS2 controller and I found it right here. Thanks to Bill Porter, I had my answer. Not only was it possible but much of the work and testing was already done. Music to my ears, and a BIG thanks to Bill.
What I wanted
I wanted a compact, portable replacement for communicating with my robot via the Serial Monitor. This was my general requirements list:
It must…
- be compact and portable… (duh)
- allow multiple user inputs to the robot
- allow human-readable output from the robot
- look professional and slick so I will want to play with it (oooh shiny!)
- not interfere with the ability to wirelessly reprogram ABE
What I ended up making
I ended up making a comfortable, portable replacement for communicating with any of my projects that include a Wixel
It…
- is pretty compact and portable (at least hand-held) and is fairly light
- allows multiple user input to the robot via:
- 10 digital buttons (all with
changed
, down
and up
event notifications)
- 4 analog pressure-sensitive buttons
- 2 biaxial analog stick controllers (with two additional digital buttons underneath them)
- a microprocessor-driven LCD-Menu interface (that I’m writing AFTER this post)
- allows 32 5x8 pixel backlit LCD characters over 2 lines for human-readable output and interaction
- looks professional (the Sony part… my bit looks nice enough :)
- allows pass-through reprogramming of ABE when the controller is plugged into a USB port using the standard Arduino IDE
Sweet - I’ve totally decimated my requirements list (that’s a good thing)!
Oh, and as an added “I wonder if I can….” bonus, I’ve also managed to design it in such a way that if ABE is plugged into the computer USB port, the controller itself can be wirelessly reprogrammed (without having to remove the chip). Woot!
What does that mean?
Well, it means I can remote control ABE and any other project that I’m making that includes a Wixel.
It means I can make stand-alone programs for the controller (and I have a few sneaky projects in mind) and its 2.4GHz transceiver (Wixel) - I could even theoretically reprogram ABE in-the-field.
It means - I’ve made myself a new toy to play with. :)
The LCD Bracket
To make a slick-looking controller, you’ve got to have slick-looking curves. Because I still have a fair bit of the stuff and because it’s durable, mouldable (if you’re really careful with a blowtorch or hot air machine) and strong, I decided on using more perspex. I wanted the bracket to tilt the LCD screen slightly towards the user (me) for good visibility and comfort. I also wanted not to mess up the beautiful aesthetics of Sony’s controller.
I scribbled up the design (above) on my whiteboard one afternoon and measured it carefully onto a piece a day or so later. To cut it, I used a fine-grade hacksaw and to sculpt it, I used a pocket blowtorch (very carefully) and a padded vice. I beveled the edges afterwards with some hand-files and wet-and-dry.
Bracket Parts List
- 3mm x 6mm (M3) Screws
- 10mm Hex Spacers
- 90mm x 3mm x 120mm Sheet of Perspex
After I’d drilled all the bracket holes, I also drilled holes in the PS2 controller’s lower shell. I had to be extremely careful to keep my M3 screwheads away from the interior circuitry but there was enough clearance for them to co-exist peacefully. Holes in the perspex were threaded using an M3 tap tool, so no extra nuts were needed (keeps the minimalist aesthetic).
PS2 Controller Wiring
The wire pinout provided at Bill’s site was a little different from the one I had, but it was noted that the colours were succeptable to frequent change.
Bill’s Site Pin/Wire layout:
- Brown = data
- Orange = command out
- Grey = dualshock power
- Black = ground
- Red = power
- Yellow = attention
- Blue = clock
- White = ?
- Green = ack
My Pin/Wire layout:
- Brown = data
- Orange = command out
- Purple = dualshock power
- Black, Grey (both) = ground
- Pink = power
- Yellow = attention
- Blue = clock
- N/C (shield and bare wire also both N/C)
- Green = ack
PS2 + Arduino
In order to link up the PS2 controller to the Arduino, I needed Bill Porter’s library called PS2X.
Download PS2X from Github
Once I had wired it all up as explained in the very top of the code (see the breadboard diagram below for the cheatsheet), I turned it on but it didn’t seem to work straight away.
Not to worry!
Bill has an absolutely brilliant section on his site that’s dedicated to troubleshooting the library. What a guy!
Bill’s Brilliant Troubleshooting Guide
It turned out that all I needed was a single resistor to act as a pullup for the controller. Simple as that.
PS2 + Arduino + LCD
After I’d linked up the controller to the Arduino (and yes, mucked about with it for a good half-hour), I added in the LCD. This was probably the easiest part. The wiring is only 4 pins (power, ground, SCL, SDA) and the sample code in the DFRobot-provided library gave me all I needed to find-and-replace all of the Serial.print
calls in Bill’s demo with lcd.print
.
Download the DFRobot LCD Library for Arduino from DFRobot
…more fiddling and mucking about ensued…
PS2 + Arduino + LCD + Wixel
For the home stretch (a few days later - I’m a busy guy), I added the Wixel into the mix. The following links came very much in handy:
For this part, (ABE has a Wixel Shield) I wanted the circuit to function similarly to the Wixel Shield. That way, I would be able to program both ABE and the controller remotely and still allow full communication between the two (without buying or powering more hardware). What followed was a simple (remember, this is version 1.0) design that was mostly voltage dividers2 and pullup resistors.
The Circuit
I’m going to write this in point form so that it reads simply. It’s not that complex a circuit, though. Here’s how it works:
- The Arduino powers everything from its 5V pin
- All grounds are connected (as they should be)
- The PS2 controller pins (shown on board left to right, pin1 to pin8) connect to Arduino digital pins, power and ground
(pins 3 and 8 are not connected)
- The LCD pins connect to the I2C bus (SCL,SDA), power and ground
- The Wixel takes its power directly from the Arduino 5V pin (it has its own regulator)
- Arduino Transmission (TX) lines are voltage-divided down to about 3.3V for the Wixel’s RX inputs
- The Wixel Transmission (TX) lines are connected directly to the Arduino (because 3.3V is still considered HIGH by 5V logic)
- Various pullup resistors were required to keep the Arduino/Wixel logic in certain states at certain times (especially during program-loading)
- The single transistor is part of a quick on-board digital inverter (NOT gate). When the Wixel wants to reset the Arduino (when programming), it sets P0_0 to HIGH. However, to reset the Arduino, the RESET pin has to be pulled LOW. This is a very simplified version of the connection shown on the Wixel Shield schematic (but it works well).
N.B. I can’t remember if I put the right resistance values into Fritzing before I generated the breadboard graphic.
Stay tuned for the next post. I’ll add a schematic with values and details of the next steps, and if required, I’ll post some more explanation about the inverter, pullup resistors and logic conversion. By then, I should have some code to post too.