How to create your very own Raspberry Pi "Harry Potter Sorting Hat" - Pibrella Version
In this lesson, students will create a Raspberry Pi powered Harry Potter style sorting hat. Students will also learn how to connect a physical button to the Pibrella and program it to control the sorting hat.
Note: Although I have written this as a lesson, it would probably work better as a project for a small group / after-school club.
Learning Objectives:
Note: Although I have written this as a lesson, it would probably work better as a project for a small group / after-school club.
Learning Objectives:
- Understand and use sequence in an algorithm
- Understand and use iteration in an algorithm (FOR and WHILE loops)
- Understand and use selection in an algorithm (IF, Else and Else if)
- Understand how to control Input & Output devices
Curriculum Mapping:
KS2:
KS3:
KS2:
- Design, write and debug programs that accomplish specific goals; solve problems by breaking them into smaller parts. Select, use and combine a variety of software on a range of digital devices to design and create a range of programs.
- Use sequence, selection and repetition in programs; work with variables and various forms of input and output
- Use logical reasoning to explain how some simple algorithms work; detect and correct errors in algorithms and programs
KS3:
- Use two or more programming languages, at least one of which is textual, to solve a variety of computational problems.
What you will need (For each group of students):
Note:
* This lesson assumes that students already have some experience of using the Raspberry Pi and that they have already installed the NOOBS Operating System. To find out how, click here
** Most D&T departments will have some of these lying around and may let you borrow them if you ask nicely (I find taking a box of sweets usually helps!)
*** Obviously, you will also need a hat. Here are some ideas to get you started:
- 1 x Raspberry Pi (with monitor, keyboard and mouse)
- 1 x 8gb SD Card (With NOOBS installed *)
- 1 x Push button / switch ** (example: Large Red Push Button)
- Male-to-female jumper leads ** (example: Jumper Lead Cables for Arduino/Raspberry Pi)
- 1 x Prototype breadboard ** - Optional (example: Breadboard for Raspberry Pi/Arduino)
- 1 x speakers
- Hat *** (See options below)
Note:
* This lesson assumes that students already have some experience of using the Raspberry Pi and that they have already installed the NOOBS Operating System. To find out how, click here
** Most D&T departments will have some of these lying around and may let you borrow them if you ask nicely (I find taking a box of sweets usually helps!)
*** Obviously, you will also need a hat. Here are some ideas to get you started:
|
3. DIY (Do It Yourself) Sorting Hat
Create your very own sorting hat. (Above is the version created by team Python - Led by yours truly at PiCademy) Pros:
Cons:
|
Setting up the Pi:
1. First, students will need to connect their push button / switch to their Raspberry Pi.
Connect the Raspberry Pi to the push button / switch as shown in the diagram below.
Important! Make sure one of the pins on the push button is connected to pin 17 on the Pi and that the other is connected to gnd (ground)
Connect the Raspberry Pi to the push button / switch as shown in the diagram below.
Important! Make sure one of the pins on the push button is connected to pin 17 on the Pi and that the other is connected to gnd (ground)
Image source: RaspberryPi.org
Tip: If you don't have access to a prototype breadboard (as seen in the image above), you can connect the switch directly to the Raspberry Pi using a couple of paperclips and two jumper cables (see image below)
Insert image here
Insert image here
2. Next, students will need to start their Raspberry Pi and launch the graphical desktop environment. To launch the graphical desktop environment:
At the command prompt type the following:
startx
3. Finally, students will need to install the necessary library packages required for Python:
Start by launching LXTerminal to start a command line:
Double click on LXTerminal (You will normally find this on the desktop)
At the command prompt type the following:
startx
3. Finally, students will need to install the necessary library packages required for Python:
Start by launching LXTerminal to start a command line:
Double click on LXTerminal (You will normally find this on the desktop)
Next, install the GPIO library package (This will allow you to communicate with the GPIO pins on the Raspberry Pi).
At the command prompt, type in:
sudo apt-get install python-rpi.gpio
Finally, install the the mpg123 library (This will allow you to play audio via Python)
Whilst still at the command prompt, type in:
sudo apt-get install mpg123
At the command prompt, type in:
sudo apt-get install python-rpi.gpio
Finally, install the the mpg123 library (This will allow you to play audio via Python)
Whilst still at the command prompt, type in:
sudo apt-get install mpg123
Programming the Pi
Note: In order for the sorting hat script to work, students must launch idle3 as Super User (sudo) - without this, the students will not be able to communicate with the GPIO header.
1. (If students haven't already done so) Double click on LXTerminal to start a command line
Note: In order for the sorting hat script to work, students must launch idle3 as Super User (sudo) - without this, the students will not be able to communicate with the GPIO header.
1. (If students haven't already done so) Double click on LXTerminal to start a command line
2. Type in the following at the command line to start the Python environment:
sudo idle3 &
(Important! Make sure you add the ampersand '&' at the end)
3. Select File > New Window from the menu to start a text editor
4. Enter the code as follows (Note: Case is important)
sudo idle3 &
(Important! Make sure you add the ampersand '&' at the end)
3. Select File > New Window from the menu to start a text editor
4. Enter the code as follows (Note: Case is important)
code goes here
5. Select File > Save
Give your file a sensible name e.g. "sorting hat.py" (Note: Make sure you save )
6. Select Run > Run Module
Give your file a sensible name e.g. "sorting hat.py" (Note: Make sure you save )
6. Select Run > Run Module
Here's one I made earlier:
Troubleshooting
I can't hear any sound from the speakers
I can't hear any sound from the speakers
- Make sure that the audio files are in the same folder as the python script.
- If you use a HDMI lead to connect to your monitor, the Raspberry Pi will automatically output the sound via the HDMI and NOT the headphone jack. To find out how to change the audio output settings, click here.
Extension Task
- Connect multiple LEDs (One for each Hogwarts House / Group) and make each one flash depending on which house / group is picked
- Record your own audio (These could be houses in your school, colours or numbers)
- Add a second switch which will power up the Raspberry Pi and launch your python script on startup (Click here for help)
You may also be interested in:
- Raspberry Pi Sorting Hat (GPIO version) - Coming soon
- Raspberry Pi Sorting Hat (Scratch GPIO version) - Coming soon
Licence:
Unless otherwise specified, everything in this repository is covered by the following licence:
Unless otherwise specified, everything in this repository is covered by the following licence:
Raspberry Pi "Sorting Hat" lesson is licenced under a Creative Commons Attribution 4.0 International License.