Breadboard Videogame Controller + Pygame Rectangle Animation

controller up closeI was inspired to work on a homemade videogame controller for my Raspberry Pi using a breadboard after taking apart two old video game controllers and seeing another maker’s idea. A breadboard with buttons in the right spot makes a controller that fits quite nicely in your hand.

My design included two four-way keypads on either side of the breadboard plus two extra buttons in the center to serve as maybe ‘start’ or ‘pause’ buttons. I also added two indicator LEDs that can be used for various purposes. Wiring it was a bit difficult, as I had to keep wires out of the way of the buttons. I ended up connecting the button signals (they’re all pull-downs) to the center of the breadboard, and running jumper wires from there to another breadboard, connected to my Raspberry Pi. I tested the controller with a few simple Python programs and verified that it works. The pic below shows the controller next to the Pi breadboard.100_4257

To put it to practical purposes, I made a simple Python program with Pygame that makes abstract art with rectangles. Basically, running the program opens a window where various sized rectangles are placed randomly on the screen every 0.1 seconds. Pressing the keypad buttons changes the rectangle colors, and pressing one of the center buttons saves the image. Unfortunately, Pygame saves images in .tga format, which I am trying to currently convert to .jpg or .png format so I can share the images.

You can see in the image below the whole controller and how it connects to the Pi. You can also see part of my monitor, which has the rectangle animation program open.100_4255

Here’s the code for the controller version on my Pi. There’s comments and more information.

I also made another version of my Abstract Art/Rectangles/Generator/Animation (not sure what to call it) that doesn’t use my controller, just a mouse if you want to test it out on your Pi (Pygame is installed by default in Raspbian).

Now I have to actually make a game for my controller! That will be a challenge. I might program it to control Minecraft on the Pi.


I figured out how to save images in Pygame in .png and .jpg format. In the code, you just have to add the file suffix to the save file name, so that it doesn’t save as the default .tga. I’ve updated the code links above to reflect the change. Here’s an image generated by the mouse version of the rectangle animation. rectangles0


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s