Raspberry Pi Trivia Game Project

Morgan Gariepy March 20, 2018

This Raspberry Pi workshop for middle school students teaches coding and physical computing as the students build their own trivia games. This program works best with up to 12 students working in pairs.

The project progresses from a simple text input system to a game with multiple choice buttons, LED indicators, and sound effects.

The program takes 5-6 hours of instruction, plus set up and clean up. This could be done in multiple sessions.

I designed this for Teen Tech Week 2018, and was inspired by this project from Code Club.

Type: Active
Age: Middle school
Optimal size: 6-10
Estimated cost: $100+
Planning time: 2-5 hours
Frequency: One-time

Learning outcomes

  • Gain skills coding in Python
  • Learn the basics of physical computing
  • Build attention to detail, troubleshooting, problem solving, and critical thinking skills
  • Emphasizes perseverance 

Instructions

Supplies

  • 6-8 Raspberry Pis, ready to use
  • Monitor, mouse, keyboard, and cables for each Pi
  • At least 1 projector, 2 is better
  • Breadboard for each Pi
  • Mini portable speaker for each Pi (Wired, not Bluetooth. This AYL speaker is a good example.)
  • Jumper wires (male/male, female/male)
  • LEDs
  • Push buttons (tactile switches)
  • 330Ω resistors
  • Slide deck

Setup

Raspberry Pis should be set up with monitors, keyboards, etc. prior to the teens' arrival. I withheld the circuitry pieces and speakers until we got to those sections. Have these tools ready to distribute when needed.

I use two projectors. The first one is for the presentation, running off of a regular computer or laptop. The second is for my Raspberry Pi, which I use to demonstrate concepts and code in real time. If you only have one projector, the presentation has screen shots of all code needed. You can also display the presentation on the Pi using Google Drive.

The slide deck is included in the Supplements section below. Each slide includes more detailed notes for each step.

Have students test their code frequently while building their code. Allow time to troubleshoot with students at each step, and encourage more advanced students to help their classmates.

Introduction and Step 0

Begin with the learning objectives and showing students the video introducing the Pi's features and potential uses. There is also a useful disclaimer that failure will happen, that's ok, and the most important thing is to keep trying.

Now, have students power up their Raspberry Pi, open, and save a new project in Python 3 (IDLE) [NOTE: Python 2 will not work!]

Step 1 - Text as Input

We begin to build our trivia game with a simple code that allows us to type answers into the game. This section teaches the basics of Python syntax, using IF statements, creating multiple variables, and preventing false negatives. 

Step 2 - Making it Multiple Choice

Typing in complete answers can be a hastle, especially since spelling still counts. A multiple choice game would be much easier for players. The main purpose of this section is to introduce ELIF statements, which allow multiple choice outcomes.

Step 3 - Keeping Score

What's the point in a trivia game without a score? This section adds a simple counter that tracks the player's score throughout the game.

Step 4 - Physical Computing

Adding electronics is a great way to make our trivia game more engaging. But first, we need to introduce some of the components and concepts that we will be using.

This section includes an introduction to simple circuitry, LEDs, resistors, and breadboards, as well as the GPIO pins on the Raspberry Pi. The section also introduces libraries within Python.

Once students have a grasp of physical computing works with a Pi, there are step by step instructions on wiring LEDs  and coding them into your game.

Step 5 - More Interactive

So far, your game still relies on text input from the keyboard. In this section, we will replace that with a set of buttons. 

Start with an overview of how the buttons work. It is important to understand how the pins are connected in order to wire the buttons correctly.

Next, use the step by step instructions to wire the buttons.

Finally, we need to add several lines of code in order to use the buttons. The first step is to import the GPIO pin library. Next, add the code to set up the buttons to the appropriate pins. Finally, the buttons need to be included in your ELIF statements. 

It is possible that the code will be stuck in the WHILE loop. To prevent this, include breaks in your ELIF statements. Once a condition is met, it will execute your code, then proceed to the next section of your code.

Step 6 - Adding Sound

The final piece to our game is to add sound effects.

Allow students to check out freesound.org or other free sound fx sites. They should download short noises or songs to play during the game, such as applause for a correct answer or disappointed sighs for wrong answers.

To add the sounds to your code, you will need to import subprocess, which will allow your code to access the media player during the game.

Next, add subprocess.call, followed by the file path to the sound fx wherever you want there to be sound. This will cause your fx to play whenever that option in your game is selected.

Conclusion

Hooray! You and your students have created your very own trivia game. If time allows, encourage students to take it further. Are there other features they could add? Perhaps they can find ways to make their code more efficient?

Evaluation

This program requires a significant amount of set up and clean up.

Because coding and bread boarding requires absolute precision, many students may struggle with some steps. You will need to allow time to help students troubleshoot along the way. It is for this reason that I limit the program to no more than 12 students working in pairs. Having an additional instructor who can wander the room also helps.

A small, experienced group of students may be able to complete this workshop in as little as four hours. Larger groups, or inexperienced coders will stretch this to 5-6 hours.

If you have a class with mixed experience with coding, some teens will catch on very quickly, and may grow impatient with slower classmates. To help prevent this, I encourage students with stronger coding skills to partner with less experienced classmates. In addition, pairs that finish a step early are encouraged to help their peers. I struggled with this, as many of my advanced coders preferred to play Minecraft on the Pis while they waited, rather than helping others. This slowed the program even more, as it would take time to capture their attention when we were ready to move on.

Other resources

Raspberry Pi Foundation - Lots of useful resources to help you get started, or troubleshoot.

Freesound.org - Great source for free sound fx

Learning Python - A detailed reference guide to Python. It will be overkill for this project, but it will almost certainly contain the answer you're looking for.

Post a program

Post an activity that you think will be useful to others.

Related by tag