Close

Move to Hackaday.io

A project log for Universal Controller

One controller to rule them all! A PS2 controller crossed with an AVR and XBee / Bluetooth, to use in multiple physical computing projects.

the-big-oneThe Big One 04/09/2014 at 20:030 Comments

I am now in the process of moving all the documentation and files to this site.  This project is quite new (the original controller has been around for a few years, but it was specific to a quadcopter implementation and was quite awkward and unwieldy; I have only recently converted it to be self contained and universal).

Just yesterday I modified the protocol slightly to include both button press + release events (previously I only included press events), as well as a 'throttling' approach for analog stick output.  (Previously, I would send analog stick data whenever the raw value changed.  This can potentially send a lot of data if you are constantly moving the joysticks, and could even overflow whatever receiving buffers you may be using.  My change now lets the receiver (robot) decide how fast the analog stick data really needs to come in; for a slow walking hexapod, for instance, you would need fewer updates than a quadcopter.

The protocol itself is quite simple: one byte is sent for each button press / button release event, as well as one byte for each analog stick change.  Button press / release events are in the format b111XAAAA, where X is 0 for release or 1 for press, and XXXX is the 4 bit button address (there are 16 buttons on the controller).  There is a special command b10000000 (0x80) which means 'no buttons pressed' (more on this later).  Analog stick events are in the form b0SAXXXXX, where S is the side (Left / Right), A is the axis (X / Y), and XXXXX is the 5 bit value (the 5 MSB from the raw controller output).  I found that the ADCs in the PSX controller itself are not good enough to warrant sending the full 8 bits of data; the bottom 3 bits are pretty much just noise anyway.

Since there is no confirmation messages sent from the receiver back to the controller, the controller will poll its state every X milliseconds.  If there are any buttons pressed, it will send all pressed buttons.  If there are no buttons pressed, it will send 0x80 to indicate such.

There is another single-byte based protocol which allows the receiver (robot) to set different parameters on the controller.  It can enable / disable individual buttons, enable / disable analog joysticks, change the polling frequency, and throttle the analog output.  This is documented in the source code comments; I may make a future post on the subject if there are questions.

Discussions