Saturday 11 January 2014

TriviaBox - Trivia Game for RaspberryPi

Just before the holidays, my wife said "We should host a trivia night, it'll be fun!" ... of course, I turned this into a crazy project with custom buzzers and software. Some day I'll learn.

I settled on using my Raspberry Pi with the PiFace GPIO shield for inputs. Initially I was going to use the Pi for the GUI and an Arduino for the input processing. My thinking was the Arduino could constantly monitor the inputs while the RPi did other things. But it turns out the RPi was fast enough to do both, so the end result was much easier to deploy.

The wiring is pretty darn simple. Dry contact switches to the PiFace digital inputs. I used cheap speaker wire for the runs.

The switches all share a common ground. I had an old terminal block lying around that made this a piece of cake.
It didn't look like my bike handles were going to arrive from China in time, so I grabbed some plastic glasses from the Dollar Store for a stop-gap solution. They worked out pretty good actually.
But, as luck would have it, the bike grips showed up two days before game night. The switchover was pretty easy since the hard work of soldering and tinning the wire ends was already done. Got these off eBay from China for about $0.50 each. Perfect trivia grips.
A little knot in the wire was sufficient as a strain relief. No large currents or anything to worry about. The excess wire was just stuffed into the grip.
The completed, and final, buzzers (yes, I know what it looks like). 
The coding was a different matter, but fortunately I could work on this before the buzzers were all completed. I wrote the game in Python and used PyGame to handle all the graphics and input handling. The game is written such that the buzzers could be simulated with 1-4/5-8 for inputs so I didn't need a PiFace for local testing.

The source for the game is available here: https://github.com/SandyWalsh/trivia-box/tree/master/pi
It's a hack, so please excuse the mess. Patches welcome. There is so much more we can do with it. I have a YouTube video of the game play further down.

Then I set up for game night. Two teams of four players battle at any one time. Forty questions per game. Double elimination ladder for the full tournament. We had 8 couples (4 teams) which took about 3hrs to play through.


I asked the questions, so I was stationed at the end of the table. The RPi was plugged into a projector, then I had amplified speakers for sound and a keyboard for controlling the flow of questions. It's a console app, so no mouse needed.


My wife took care of all the other hosting duties ... here is the sugar cookie tray :)

Here's a demo of the TriviaBox software in action. The rules, flow and keyboard shortcuts are all explained in the source README file.

It was a great night. Everyone had a ball and the software/hardware worked perfectly. There is a lot more I could do with it. I'd especially like to do more around the tournament management ... controlling the win/lose status and the double elimination ladder.