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.

11 comments:

  1. A question - what switches did you use? Also, did you control the game using the keyboard, or another type of switch?

    ReplyDelete
  2. Fantastic! I wonder about using the rasp as a linux server running hadoop. A few rasps with 16g memory each would be awsome - but I wonder about the computing power. Any thoughts?

    ReplyDelete
  3. @scott - I used these switches:
    http://www.ebay.com/itm/10Pcs-Momentary-Red-Push-Button-Switch-3Pin-SPDT-/181105776885?

    @Don - the computing power is very low. These are slow machines and SDRAM cards are terrible. You'd be better off with an ATX-mini machine.

    ReplyDelete
  4. I Have read the readme an I still don't know how to connect the Buttons. One end goes to the pin thats written in the readme but where Do I connect the ground?

    ReplyDelete
    Replies
    1. With all the input switches, one side goes to the ground. That's why I have that big ground bar, tying all the lines together.

      Delete
  5. I want to do this at a school in Tanzania. We have the Raspberry Pi, but no PiFace. Will it be possible to adapt your code to work with the GPIO pins directly?

    ReplyDelete
    Replies
    1. Yeah, it can completely work without the PiFace.

      Delete
  6. Very clever!

    I built something simiilar a few years ago, dismantling a cheap joypad and wiring every button separately:

    http://forja.guadalinex.org/webs/muk/folder/El%2520increible%2520y%2520poderoso%2520mando/Machacando%2520el%2520Keypad

    Then I found out second-hand Buzz controllers on e-bay :-)

    ReplyDelete
  7. Hi Sandy, great coding!

    I'm putting this together for a group using an old raspberry pi v1 but I'm not using a PiFace. Can this be done without altering your code, I noted the "if piface" parts so presumed it can be?

    The software is running fine but during testing if I close the circuit by shorting pin 0 to earth the rpi fails and is restarted. This doesn't happen for pins 2,3,4,5,6,7 although it still doesn't trigger these users buzzers either.

    Do you have any ideas for me please, I'm at a dead end

    ReplyDelete
  8. I am absolutely in love with this project! I started building but I'm trying to get a grasp on how to compile/run the code on a Pi. While I'm not a n00b to technology - coding is a weak spot. Any pointers (even a "hey dummy this is how it's done" website link would be greatly appreciated!!!

    ReplyDelete
  9. Nice post, Great thing to play. Why make button if you can buy buzzer button online. There are sites which provide buzzer at very affordable price.

    ReplyDelete