Get Buzzed
Making game show-style buzzers for events is easy with a Raspberry Pi. The author takes you through the process step by step.
Making game show-style buzzers for events is easy with a Raspberry Pi. The author takes you through the process step by step.
Every year, the Mayborn Science Theater hosts Geekfest, an in-house sci-fi, gaming, and geek convention. Technology plays a large part in the event, and this year the convention included game show-style buzzers to let attendees be part of the action. To implement the infrastructure, I used the GPIO [1] on a Raspberry Pi to watch five push buttons. The Pygame library [2] provided a graphical "public" screen, and curses [3] provided a simple console interface to control everything.
The Raspberry Pi runs a standard Raspbian Linux distribution with software written in Python [4]. Most of the coding was done on the Pi itself. The HDMI output connects to an LCD monitor for the contestants, and the system is controlled via an SSH connection – in my case, on an iPad.
Each button is mounted in a project box and connected to the Pi with 25 feet of wire. Figure 1 shows one of the buzzers on its podium. Construction of the buzzers took place over the course of a single evening while I watched TV.
I started by drilling all five boxes for both the button and the wire. After that, I fed the wire through both holes. I had to remember to feed the wire into the box, stop and add the mounting nut and washer, then feed the wire back out of the box. Although I could have pulled the entire 25 feet of wire through the box, I was trying to avoid that.
After the wire was fed through, I used a spring clamp to hold the wire and soldered it onto the button. My source of wire was a spool left over from the college's planetarium installation. It is 2 conductor+shield, so I think it was originally used for the sound system. I used the outside shield and the red conductor. The black wire was folded back, because it was not used in this project.
On the opposite end of the wire, I used female crimp-on socket pins on each of the red conductors (Figure 2). These plugged right onto the GPIO connector on the Raspberry Pi (Figure 3). The ground wires were all connected to a push-in wiring block once the buzzers were in place for the game. This setup allowed the system to be transported piece by piece rather than as a rat's nest of wires. Figures 4 and 5 show the button-wiring schematic and the GPIO pins used, respectively.
I will step through the entire program line by line. In some cases, function arguments are omitted for brevity, so please refer to the entire code shown in Listing 1. I will also skip around a bit. I'll start with the library imports and GPIO initialization and then jump to the end of the program where everything else is initialized. Then, I'll go back and explain the functions that the program calls to do the majority of its work.
Listing 1
Buzzers in Python
01 import pygame 02 import curses 03 import RPi.GPIO as GPIO 04 05 GPIO.setmode ( GPIO.BCM ) 06 GPIO.setup ( 4 , GPIO.IN , pull_up_down=GPIO.PUD_UP ) 07 GPIO.setup ( 18 , GPIO.IN , pull_up_down=GPIO.PUD_UP ) 08 GPIO.setup ( 22 , GPIO.IN , pull_up_down=GPIO.PUD_UP ) 09 GPIO.setup ( 23 , GPIO.IN , pull_up_down=GPIO.PUD_UP ) 10 GPIO.setup ( 25 , GPIO.IN , pull_up_down=GPIO.PUD_UP ) 11 12 def showWinner ( winner ): 13 global screen 14 global numbers 15 16 winner -= 1 17 screen.blit ( numbers [ winner ] [ 0 ] , ( numbers [ winner ] [ 1 ] , 0 ) ) 18 pygame.display.flip() 19 20 def reset(): 21 global screen 22 23 screen.fill ( ( 0 , 0 , 0 ) ) 24 pygame.display.flip() 25 26 def getBuzzers(): 27 while 1: 28 if GPIO.input ( 4 ) == GPIO.LOW: 29 return 1 30 break 31 if GPIO.input ( 18 ) == GPIO.LOW: 32 return 2 33 break 34 if GPIO.input ( 22 ) == GPIO.LOW: 35 return 3 36 break 37 if GPIO.input ( 23 ) == GPIO.LOW: 38 return 4 39 break 40 if GPIO.input ( 25 ) == GPIO.LOW: 41 return 5 42 break 43 44 45 pygame.display.init() 46 screen = pygame.display.set_mode ( ( 1680 , 1050 ) ) 47 48 terminal = curses.initscr() 49 curses.cbreak() 50 terminal.nodelay ( 1 ) 51 52 terminal.addstr ( 5 , 5 , "Trivia Buzzers and Scoring" ) 53 terminal.addstr ( 7 , 5 , " 1 - 5 -- Show team as buzzed in" ) 54 terminal.addstr ( 8 , 5 , " r -- Reset buzzers" ) 55 terminal.addstr ( 10 , 5 , " b -- enable buzzers" ) 56 terminal.addstr ( 11 , 5 , " x -- Exit (Careful, no confirmation)" ) 57 58 numbers = list() 59 left = 0 60 numbers.append ( ( pygame.image.load ( "numbers_01.jpg" ) , left ) ) 61 left += numbers [ 0 ] [ 0 ].get_width() 62 numbers.append ( ( pygame.image.load ( "numbers_02.jpg" ) , left ) ) 63 left += numbers [ 1 ] [ 0 ].get_width() 64 numbers.append ( ( pygame.image.load ( "numbers_03.jpg" ) , left ) ) 65 left += numbers [ 2 ] [ 0 ].get_width() 66 numbers.append ( ( pygame.image.load ( "numbers_04.jpg" ) , left ) ) 67 left += numbers [ 3 ] [ 0 ].get_width() 68 numbers.append ( ( pygame.image.load ( "numbers_05.jpg" ) , left ) ) 69 70 running = True 71 while running == True: 72 choice = terminal.getch ( 12 , 5 ) 73 if choice == -1: continue 74 if choice == ord ( "1" ): 75 showWinner ( 1 ) 76 elif choice == ord ( "2" ): 77 showWinner ( 2 ) 78 elif choice == ord ( "3" ): 79 showWinner ( 3 ) 80 elif choice == ord ( "4" ): 81 showWinner ( 4 ) 82 elif choice == ord ( "5" ): 83 showWinner ( 5 ) 84 85 elif choice == ord ( "b" ): 86 showWinner ( getBuzzers() ) 87 88 elif choice == ord ( "r" ): 89 reset() 90 elif choice == ord ( "x" ): 91 running = False 92 93 curses.endwin()
Pages: 8
Price $15.99
(incl. VAT)