Snaxe on a breadboard!

September 21, 2011
by davidc

Hardware

As usual, I'm using the wonderful Teensy 2.0 USB. The interfacing is pretty simple: the joystick's horizontal and vertical pots feed into analog inputs F0 and F1 respectively, and the button into F4 (with the pull-up configured). The four pins for the DOGS display are connected to SS/SCLK/MOSI, and B7 for for the command/data pin, allowing me to use the standard SPI interface.

The display is 0.4" too wide to fit directly onto a breadboard, so I built a little adaptor out of Veroboard. It requires a 3.3V supply and inputs, so I added an LD1117V33 regulator and ran the inputs through a 4050 buffer. The Vcc for the 4050 is 3.3V, but it is happy for its high inputs to be 5V - the outputs are then correctly 0V low and 3.3V high.

The remaining components then are a button for LCD reset (which it hasn't actually been necessary to use), a current-limiting resistor for the backlight, three 1uF capacitors that the DOGS data sheet insists on, and various other capacitors across the power rails.

The USB cable pictured is just supplying power (though a #define enables debug output over the Teensy HID interface). So far, I have been unable to get it running off either a MintyBoost or a 9V battery with 7805 regulator. I'm not sure why this is, as it only draws 40mA with the backlight off, but it might have something to do with this particular Teensy having had a broken Vcc track that I repaired - perhaps something more fundamental is broken. (Edit: durrr, left in a #define USB_DEBUG 0, so it was still trying to usb_init()).

Software

Porting the game code was easy; since everything related to the game state and logic is encapsulated in the net.davidc.egp.snaxe.board classes with no dependencies on any graphics libraries, it was a simple matter of porting them to C++, removing the multiplayer support and simplifying it all somewhat in the process.

The thumb joystick axes is sampled with the ADC; if either are off-centre (outside a little tolerance), it picks the direction with the greatest magnitude (so if you've moved the joystick top-left, you'll move either up or left depending on which direction it is pushed more in).

For the display, I used the dogm128 library, which worked fine once I got all its dependencies in place and added all the necessary sources (pretty much one function per C file!) into my Makefile.

It took about three hours altogether, a large part of which was spent fighting to get the right files in the right places: this is tricky as everyone seems to depend on dozens of files from the Arduino project, many of which conflict with the ones I already use.