Our pals over at @joypadbar had an idea for a new retro video gaming night – Video Game Democracy – a change to settle age old gaming arguments by voting on which games should get played next. Sonic vs Mario, Street Fighter vs Mortal Kombat, Pacman vs Donkey Kong – the audience will decide! [GGSGamer review here]

How it works in practice:

The Plan

We knew right from the start that a Raspberry Pi would be ideal to run this [jump to the build]. Self-contained (and thus easy for Joypad to transport and setup), all we’d need would be a TV and some push buttons and we’ve got ourselves a voting machine!

We can use the Pi’s GPIO pins as inputs for the buttons and then write some code usng Python to control the voting process. The TV will show what the current vote is (with a picture of each game), a countdown timer, and every time a red or blue button is pushed the red or blue team vote increases. The team with the most votes when the countdown is reached wins!

The Result

xq1Nyp9---Imgur

Voting Buttons

Bpak8X2---Imgur

Vote Screen

ZcpR4Td---Imgur

5 buttons per team to allow multiple people to vote at once

moR3nb8---Imgur aADPYXI---Imgur

Hardware Build

I needed something that we was easy to mess around with and that I could get the joypad guys to do via instructions over the phone, so we got the following kit on order:

The first step is to make sure that you can get a single button working. We used this guide to make sure we had our Pi setup correctly and that we’d soldered + connected the T-cobbler the right way round (don’t laugh – we did this bit wrong, twice!). Once we verified that our switches were working and that we could get the Pi detecting the switch, it was then onto planning handling of multiple buttons.

IMG_20150118_162728

This circuit uses a single 1K resister for the 3v3 line and a 10K resister on each of our two buttons (we’re working in a ‘pull-down’ style, so by default our button inputs are connected to ground). We then wire in the switch buttons to the 3v3 line, so that when the button is pushed the resistor is bypassed, registering a ‘GPIO_RISING’ event on the Pi. You should end up with something that looks like this:

IMG_20150118_162750

Software

This is the python code we used to test our buttons were working. (Remember to run with sudo!)

Awesome. Now you should get a message on the screen whenever a button is pressed!

IMG_20150118_165400

Writing a UI

Now the hardware interfacing is out of the way, we had to design the user interface to the vote system and work out how we were going to use Python to display the information. Luckily we can use the Tkinter library for handling our drawing and Pygame for playing sounds! All of this will happen in a windowed environment, so from now on we’ll be working in the X windows gui. To install the required libraries, type in:

sudo apt-get install python-tkinter python-imaging python-imaging-tk

The following code will show a screen with a background you supply (put into resources/bg.jpg) and then show a timer and the vote counts for both teams.

You’ll notice that we’ve split the code up into different classes – one to handle the UI, and one to handle the GPIO stuff. We then launch the code by calling run.py.

Where to go from here?

That’s up to you! You’ve got the basics now, and if you want to find out how the current system works then you can check out the full vote system code at our github repository.