frankdyring
Posts: 9
Joined: Sat Feb 02, 2013 12:51 am

Quiz buzzer lockout system

Sat Feb 02, 2013 1:03 am

I want to use the Pi as a controlling device for a Jeopardy-like quiz buzzer lockout system.

The best way would be, if I could attach any number (max. 10) of buzzers in parallel on a cable or else in serial connection and then from the last buzzer go back to the Pi.

I would need to have some kind of output to a LED on each buzzer to show who pressed first and on a screen for me to look at (or a number of LED's) and a way to reset the system.

As a great feature, it could be nice, if the Pi could also keep track of the points given to each team. This could be done by mouse clicking or keyboard number presses.

Has anyone got ideas in which way to look or heard of anything similar? The closest I could find was the PiQuizMachine, but that's not completely what I need.

frankdyring
Posts: 9
Joined: Sat Feb 02, 2013 12:51 am

Re: Quiz buzzer lockout system

Tue Feb 05, 2013 7:35 pm

No-one who can help here?

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Quiz buzzer lockout system

Tue Feb 05, 2013 7:44 pm

Not yet it looks like a good project possibly for the Gertboard I don't know enough about yet. ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

ghans
Posts: 7893
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Quiz buzzer lockout system

Tue Feb 05, 2013 7:51 pm

I thing PiQuizMachine is a very good starting point.
There should be enough GPIOs for 10 buzzers.

A good Python tutorial can be found at
http://www.learnpythonthehardway.org

Don't be afraid , the author explains why the hard way is
easier in the long run.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

frankdyring
Posts: 9
Joined: Sat Feb 02, 2013 12:51 am

Re: Quiz buzzer lockout system

Tue Feb 05, 2013 8:11 pm

Haven't heard of Gertboard, but just ordered one now - seems like it may be usefull ;-)

malcolm851
Posts: 1
Joined: Sun Feb 10, 2013 11:02 pm

Re: Quiz buzzer lockout system

Sun Feb 10, 2013 11:13 pm

If have the wired version of the Sony Playstation2 Buzz! controllers and
are happy with a 4 player limit, then you could adapt this small BASH
script which plays a different soundfile depending upon the buzzer
pressed...

Code: Select all

#!/bin/bash
SOUND1="jamesbond intro.wav"
SOUND2="space1999 intro.wav"
SOUND3="trio intro.wav"
SOUND4="aha.wav"

function which_buzzer2
{
	LINE=$(
		od -t o1 -N 192 /dev/input/js0  \
		| cut -f9 -d" " \
		| head -12 \
		| tail -1 
	)
	let BUZZER=$LINE/5+1
	echo $BUZZER
}
		
Q=1
while [ 1 == 1 ]
do		
	echo "Question $Q"
	BUZZER=$(which_buzzer2)
	echo "Team number $BUZZER buzzed"
	case "$BUZZER" in
		1)	aplay "$SOUND1" ;;
		2)	aplay "$SOUND2" ;;
		3)	aplay "$SOUND3" ;;
		4)	aplay "$SOUND4" ;;
	esac

	echo "Another question ? [Y/n]"
	read  ANS
	if [ "$ANS" == "n" -o "$ANS" == "N" ]
	then
		break
	fi
	let Q=Q+1
done

echo Finished

Malcolm.

frankdyring
Posts: 9
Joined: Sat Feb 02, 2013 12:51 am

Re: Quiz buzzer lockout system

Sun Feb 10, 2013 11:51 pm

Thanks for the idea, but I would need at least 10 competing teams ;-)

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 288
Joined: Mon Nov 07, 2011 9:12 am
Location: UK

Re: Quiz buzzer lockout system

Tue Feb 12, 2013 1:42 pm

Some guidance as I haven't done it yet...

For the buttons - I would recommend getting a cheap USB gamepad and wiring buttons off the contacts for the digital inputs. I bought a Saitek P380 and it worked with no configuration with the Atari 2600 emulator so the joypad is plug and play on Raspbian.
To me this is the easiest way to get loads of input buttons without having to figure out the GPIO interface. 4 from the D pad, 4 from the main buttons and then the 4 shoulder buttons. There are also buttons under the analogue sticks and the Start and Select buttons.

Pygame has event handling which means it can queue the inputs so you can tell the order in which buttons were pressed. This code explains it well.
http://programarcadegames.com/index.php ... ction_11.5

With a bit of code to check the inputs you can figure out who was first. Then have the code light up their light/led and lock out further input until you reset it. Or if you have a screen light the contestants name or put a colour next to it on the screen.
For 10 leds, a couple of shift registers like the 74HC595 would allow you to do the leds from only a few pins. Here's a good example of the wiring for the 74HC595 and how it works.
http://www.protostack.com/blog/2010/05/ ... g-16-leds/
Not too crazy once you wrap your head around it.

Finally, the score piece can be another piece of code where you can press the number keys from 1 to 0 and when you do the score goes up by 1 for that person.

Based on above a cheap USB joystick ripped apart and repurposed would give the 10 inputs.
Pygames even handling would allow you to tell which button was pressed first
Python + GPIO library with a couple of 74HC595 shift registers would allow you to light up the led for the person who pressed first. Or without the GPIO and electronics you could do an on screen update using pygame to show who pressed first. Maybe even play a different sound for each person.
Then by pressing a key on the keyboard you can increment the score for right answers.

Sorry- I don't have the finished item for you, but I hope the pointers are useful.
Twitter:Winkleink
Google+: Winkleink

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 288
Joined: Mon Nov 07, 2011 9:12 am
Location: UK

Re: Quiz buzzer lockout system

Thu Feb 14, 2013 2:00 pm

I felt a bit guilty just posting a what to do and not really helping so I put together the following 'very rough' python code. I have done very little Python, so the chances are this code can be made a lot neater and better.

The code is for four (4) buttons using the arrow keys on the keyboard.
It waits for a keys to be pressed.
Checks if it is one of the 'button' keys and registers the first button by changing the colour of that players on screen button to red from black.
It then waits until the 'Return' key is pressed and resets the board.

This provides the lockout system required and only registers the first button pressed.
I hope this is useful.

Note: This code is run from IDLE, so I do not of the shebang statement at the top.
So, to allow this to be run as a standalone program on the Raspberry Pi you have to add the following line to the very top of your code. Nothing should be before this.

Code: Select all

#! /usr/bin/python
Here is the code

Code: Select all

 
#! /usr/bin/python

# Import a library of functions called 'pygame'
import pygame
 
# Initialize the game engine
pygame.init()
 
# Define the colors we will use in RGB format
black = [ 0, 0, 0]
white = [255,255,255]
red = [255, 0, 0]
 
# Set the height and width of the screen
size=[800,600]
screen=pygame.display.set_mode(size)
# Fill the screen White
screen.fill(white)
# Put something in the application Bar
pygame.display.set_caption("Testing key presses")

# Set the font for the text. Windows computer so usd Ariel
myfont = pygame.font.SysFont("Ariel", 30)

# Created Variable for the text on the screen
label = myfont.render("Quiz Buttons!", 1, black)
player1 = myfont.render("Player 1", 1, black)
player2 = myfont.render("Player 2", 1, black)
player3 = myfont.render("Player 3", 1, black)
player4 = myfont.render("Player 4", 1, black)

# Draw the 4 empty rectangles for the players
pygame.draw.rect(screen, black, (20,200,150,150), 0)
pygame.draw.rect(screen, black, (210,200,150,150), 0)
pygame.draw.rect(screen, black, (400,200,150,150), 0)
pygame.draw.rect(screen, black, (590,200,150,150), 0)

# put the text on the screen
screen.blit(label, (10, 10))
screen.blit(player1, (20, 150))
screen.blit(player2, (210, 150))
screen.blit(player3, (400, 150))
screen.blit(player4, (590, 150))

# show the whole thing
pygame.display.flip()

done=False # used to allow exit when you click close on the window
first = 0 # used to signify the first key pressed and stops other being used
waitReset = 0 # Reset section for the while loop

while done==False: # keep going unless I exit application

    # Stay in the loop until one of the 'button' keys is pressed
    while first==0 and done==False:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done=True
         
            # User pressed down on a key and it is not the first one
            if event.type == pygame.KEYDOWN and first==0:

                # Figure out which arrow key
                # Check of LEFT arrow key and that it was the first key pressed
                if event.key == pygame.K_LEFT and first==0:
                    print("left key pressed.") # Print to console
                    pygame.draw.rect(screen, red, (20,200,150,150), 0) # colour rectangle red
                    first=1 # set first to 1 so no other key presses will count
                if event.key == pygame.K_RIGHT and first==0:
                    print("right key pressed.")
                    pygame.draw.rect(screen, red, (210,200,150,150), 0)
                    first=1
                if event.key == pygame.K_UP and first==0:
                    print("up key pressed.")
                    pygame.draw.rect(screen, red, (400,200,150,150), 0)
                    first=1
                if event.key == pygame.K_DOWN and first==0:
                    print("down key pressed.")
                    pygame.draw.rect(screen, red, (590,200,150,150), 0)
                    first=1
                pygame.display.flip()
                # a 'button' was pressed and shown on screen
                # now got to the reset code

    # loop waiting until the 4 'button' are reset
    waitReset=0
    while waitReset==0 and done == False:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    done=True

                # User pressed down on a key
                if event.type == pygame.KEYDOWN:
                # Pressed Return Key which does a reset
                    if event.key == pygame.K_RETURN:
                        print("reset.")
                        # Draw the 4 empty rectangles for the players
                        pygame.draw.rect(screen, black, (20,200,150,150), 0)
                        pygame.draw.rect(screen, black, (210,200,150,150), 0)
                        pygame.draw.rect(screen, black, (400,200,150,150), 0)
                        pygame.draw.rect(screen, black, (590,200,150,150), 0)   
                        first=0
                        waitReset=1
                        pygame.display.flip()
            
            
# Quit in a clean way when done=True
pygame.quit ()
Twitter:Winkleink
Google+: Winkleink

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 288
Joined: Mon Nov 07, 2011 9:12 am
Location: UK

Re: Quiz buzzer lockout system

Fri Feb 15, 2013 1:11 pm

Another day and a bit of an update.
There are a few files involved so I have zipped them up and put them on Dropbox.

Dropbox link to ZIP file

This version is reading keyboard presses. You can buy a USB keyboard on ebay for about £5 and with the aid of some buttons and soldering you can attach the buttons to the keys as defined in your file.
Still leaving you with the full keyboard. As mentioned before I see this as the easier option than looking to use GPIO inputs.

These buttons from ebay look perfect.

So, for about £40 (+ cost of connecting wires and housing) you would have a quiz master set up.

Enhancements in this version.
1. Number of players, their names and sound played when they press their button is taken from a text file (example included)
2. Quiz master can go into lockout mode at any time by pressing return. An X appears top right to show in lockout mode
3. Text at the top of the screen is now taken from the text file - so it can be personalised
4. Now runs full screen

NOTE: I would never describe myself as a Python programmer. The code is done in the true hacker sense in that I figured it out as I went along.
It all works with the testing I have done but be aware your mileage may be different.
Twitter:Winkleink
Google+: Winkleink

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 288
Joined: Mon Nov 07, 2011 9:12 am
Location: UK

Re: Quiz buzzer lockout system

Sat Feb 16, 2013 10:05 pm

AHHHHHHhhhhhhh.
the code will not execute directly due to Windows doing silly line breaks.
in the end I copied the to into vi and saved it and then it runs perfectly.
The download works if opened by IDLE but not directly. Even after doing the chmod +x to it.

I will fix on Linux and package it up again.
Twitter:Winkleink
Google+: Winkleink

frankdyring
Posts: 9
Joined: Sat Feb 02, 2013 12:51 am

Re: Quiz buzzer lockout system

Sat Feb 16, 2013 10:11 pm

Winkleink> you are a star. I totally get your idea and it seems brilliant. Will update when I have tried it IRL :-D

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 288
Joined: Mon Nov 07, 2011 9:12 am
Location: UK

Re: Quiz buzzer lockout system

Sat Feb 16, 2013 11:25 pm

frank...

more fun with python.

i figured out that the program would run from a terminal window but not from within lxde as the path to the config fire and the sound files was not known so it just bombed out.

i have now fixed this where I get the path to the directory the program is run from and put it at the start of the entries for the players config file and the sounds. all works now.

I've attached the updated version that I finalised on my Raspberry pi
Attachments
quizcdw.py.bz2
(54.6 KiB) Downloaded 291 times
Twitter:Winkleink
Google+: Winkleink

frankdyring
Posts: 9
Joined: Sat Feb 02, 2013 12:51 am

Re: Quiz buzzer lockout system

Sun Feb 17, 2013 10:31 pm

With a combo of your excellent code this board: http://www.ebay.com/itm/USB-30-input-ke ... 27cf44c219 I think I can make this project as near perfect as possible.

Thank you so much for your effort and ideas ;-)

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 288
Joined: Mon Nov 07, 2011 9:12 am
Location: UK

Re: Quiz buzzer lockout system

Mon Feb 18, 2013 1:22 am

Glad it works for you.
Nice board. 30 inputs. Who needs a Makey Makey
Twitter:Winkleink
Google+: Winkleink

BloodyHelm
Posts: 1
Joined: Sat Mar 16, 2013 2:43 pm

Re: Quiz buzzer lockout system

Sat Mar 16, 2013 2:48 pm

Hi there, just curious to see if you'd had any success with the buzzer system?

I'm planning on tackling this as a first project with my Pi (I'm a programmer but not an expert in electronics) so wondered if you had any major obstacles?

Any info would be much appreciated.

Cheers!

kenanbit
Posts: 1
Joined: Tue Feb 25, 2014 2:43 am

Re: Quiz buzzer lockout system

Tue Feb 25, 2014 2:49 am

This was my first pi project, though I did it to run official scholars bowl meets at my high school. While it is much more extensive than simple lockout (sounds, timing, player recognition, scoring), it certainly includes the basic mechanisms described here. The git repo is at https://github.com/kenanbit/pi-bowl. I didn't need any extra hardware other than the pi and and an old floppy ribbon cable.

Return to “Gaming”