Tuesday, February 17, 2009

Getting started with the GamePack in 3 steps

Taking a lesson from the Mark and Omar school of "this is how real programmers actually do things", Chris and I decided to spend some time hacking together this simple little set of apps to dramatically simplify how to get up and running and hacking the GamePack as soon as possible. It's also a bit embarrassing that it took this long to do. I'm starting to get the idea that this is the week of "catching up on the obvious stuff".

The general idea is that the GamePack is an Arduino, InputShield, and TouchShield (either Stealth or Slide), and this tutorial will get anyone up and running with a very simple app to start writing a simple game on the GamePack. It includes two programs: one program for the Arduino that polls the InputShield and sends a packet of information to the TouchShield, and another program for the TouchShield that displays the information on the screen.

Step 0

Build the GamePack by snapping the Arduino and Lithium Backpack to the back of a DoubleWide or DoubleTall ExtenderShield, and then place the InputShield and TouchShield on the top of the ExtenderShield. Wire up the Lithium Backpack to the TouchShield using two small wires so the circuit is battery powered and portable. Then use a USB cable to connect the Arduino to your computer.


Step 1

Download the InputShield forwarder app here. Open the application pde file with the Arduino IDE. If the GamePack is connected to the computer, go to the Tools->Board menu option and select "Arduino". In my case, I have a Diecimila, so I select "Arduino Diecimila". Then select from the Tools->Serial Port menu option the serial port the GamePack is connected to the computer via, which in my case is COM9.

Press the Play button in the Arduino IDE to compile the code, and then press the "Upload to IO Board" button to download the code to the Arduino module of the GamePack.

Now the Arduino has code that continuously polls the InputShield. The InputShield needs to be set to "Mode A" using the mode selector switch.


Step 2

Download the InputShield Display app here. This code runs on the TouchShield Slide and displays the coordinates of the Joystick, and the status of the buttons as simple text. Open the pde and source code with the Arduino IDE. Since this code runs on the TouchShield, go to the Tools->Board menu option and select the TouchShield option. In my case, I selected "TouchShield Slide".

Press the Play button to compile the code, press the reset button on the TouchShield, and then click the "Upload to IO Board" button to download the code to the TouchShield module of the GamePack.


Step 3

This shouldn't totally be necessary, but just in case it didn't work, reset the GamePack. If it's running on USB power (probably, if it just got programmed), I usually just unplug it and plug it back in. On the other hand, if it's running the Lithium Backpack battery, just flip the switch and it will reset the battery.


Step 4

Wiggle the joystick around, and press the buttons, and have fun :)




Step 5

Laugh at how mundane and simple this little app is, and hack up the TouchShield code to make it into a real game... and maybe email me too if you want to write it together!

In the meantime, I'm working on a mini version of Mario right now, which I'll publish just as soon as I get it in a basic working form...

2 comments:

Matt said...

...before I get called out on this, I'll confess... Chris wrote the first version, then I wrote the second version, and then Chris rewrote the whole thing again to make it faster, and finally Mike rewrote the arduino base code. So I guess I can't really take all the credit. :-) (there, Chris, ha! beat you to it)

Chris said...

You're right, Mike spotted really slow text drawing routines that got add in there somewhere between the inputshield reads causing it to lack like crazy, so many thanks as well!