teachwithict
  • Home
  • Teaching & Learning
    • Tools for Teachers >
      • Web 2.0 >
        • Top 10 Web 2.0 Tools
        • Classroom Response Tools
      • Quiz Tools
      • Classroom Management Tools
      • Software >
        • Media Conversion Tools
        • Application Software
      • Multimedia >
        • Free Music
    • Digital Leaders >
      • Digital Leaders Blog >
        • DL Archive
      • DL Tips
      • Quotes
      • Links
    • BYOD
    • Flipped Learning >
      • Flipped Classroom vs. Blended Classroom
    • Gamification >
      • Gamification vs. Game Based Learning vs. Game Design
    • Game Based Learning >
      • Minecraft >
        • Minecraft in Education
        • Minecraft Lesson Ideas
        • Minecraft Literacy
        • Minecraft Coding Tutorials >
          • Minecraft Code Builder Setup
          • Minecraft Code: Walking on Air
          • Minecraft Code: Hello World
          • Minecraft Code: Functions
          • Minecraft Code: Rainbow
          • Minecraft Code: Skyscraper
          • Minecraft Pixel Art
    • The magic of >
      • The magic of Computing
      • The magic of Maths
      • The magic of Science
      • The magic of Literacy
    • Breakout Edu
    • PLN Challenge >
      • Covering your backside
      • Twitter Challenge >
        • Challenge 1
        • Challenge 2
        • Challenge 3
        • Tips for staying safe on Twitter
        • Tips for hosting Edu Twitter Chats
        • Tips for taking part in Twitter chats
        • How to storify a chat
        • How to schedule Tweets
        • Twitter Lists
        • It's all about the hashtag! Essential chats for educators
      • Facebook Challenge >
        • Challenge 4
        • Challenge 5
        • Challenge 6
        • Tips for staying safe on Facebook
      • Google Challenge >
        • Challenge 7
        • Challenge 8
        • Challenge 9
      • Pinterest Challenge >
        • Challenge 10
        • Challenge 11
        • Challenge 12
        • Tips for using Pinterest
      • Blog Challenge >
        • Challenge 13
        • Challenge 14
        • Challenge 15
        • How to create a classroom blog
      • Staffrm Challenge >
        • Challenge 16
        • Challenge 17
        • Challenge 18
      • Skype Challenge >
        • Challenge 19
        • Challenge 20
        • Challenge 21
      • Edmodo Challenge >
        • Challenge 22
        • Challenge 23
        • Challenge 24
      • TeachMeet Challenge >
        • Challenge 25
        • Challenge 26
        • Challenge 27
      • In-school challenge >
        • Challenge 28
        • Challenge 29
        • Challenge 30
      • 30 ways to grow your PLN
    • T&L Blog
  • Computing
    • Computing Blog >
      • GCSE Computer Science
      • General
    • CPD >
      • Blocks to Code
      • Tutorials >
        • How to embed Flash into PowerPoint
        • How to embed YouTube videos in to PowerPoint
        • How to create a wiki
        • How to create a classroom blog
    • Teaching Computer Science >
      • Schemes of Work
      • Programming Resources
      • Theory
      • Posters
    • Theory Lessons >
      • Theory Tests
      • Computer Hardware >
        • Input / Output
        • CPU
        • LMC
        • Storage Devices
        • Memory (RAM / ROM)
      • Binary Lessons >
        • Units of Data
        • Binary Representation
        • Binary Representation of Images
        • Binary Representation of Characters
        • Binary Representation of Sound
        • Binary Representation of Instructions
        • Binary Addition
        • Hexadecimal
      • Software >
        • Operating System
        • Types of Software
        • Utility Software
      • Programming >
        • Flowcharts
    • Game Design
    • App Creation
    • Digital Literacy >
      • Social Media (Good or Bad thing?)
      • Cyberbullying
      • Staying Safe Online
    • ICT Strand >
      • Spreadsheet Modelling
      • Superhero Movie Trailer
      • PowerPoint Task
      • Paint 3D Tutorial
    • Programming Lessons >
      • Microbit >
        • Magic 8 Ball
        • Harry Potter Sorting Hat
        • Music
        • Music (Festive)
        • Quick Start Guide
        • Microbit Simulator
      • TouchDevelop >
        • TouchDevelop Challenge
        • Scheme of Work
        • TouchDevelop Lessons >
          • 8 bit challenge
          • Turing Test
          • Turtle Power
          • 8 Ball
          • Under the hood
        • Tutorials
      • Raspberry Pi >
        • Networking the Pi
        • Minecraft Pi
        • Harry Potter Sorting Hat >
          • Harry Potter Sorting Hat (GPIO)
        • Raspberry Pi LTSP (Networked Classroom)
        • Astro Pi
      • Scratch
      • Python >
        • Chatbot
        • Coding Golf
        • Magic 8 ball
        • Python Mad Libs
        • Shakespearean Insult Generator >
          • Shakespearean Insult Generator Part 2
        • Sorting Hat
      • Little Man Computer
      • Hour of Code >
        • HoC 8-Bit Challenge
  • 21 Things
  • Microbit
    • Physical Computing >
      • micro:bit LEDs
  • About
  • Blog
  • Home
  • Teaching & Learning
    • Tools for Teachers >
      • Web 2.0 >
        • Top 10 Web 2.0 Tools
        • Classroom Response Tools
      • Quiz Tools
      • Classroom Management Tools
      • Software >
        • Media Conversion Tools
        • Application Software
      • Multimedia >
        • Free Music
    • Digital Leaders >
      • Digital Leaders Blog >
        • DL Archive
      • DL Tips
      • Quotes
      • Links
    • BYOD
    • Flipped Learning >
      • Flipped Classroom vs. Blended Classroom
    • Gamification >
      • Gamification vs. Game Based Learning vs. Game Design
    • Game Based Learning >
      • Minecraft >
        • Minecraft in Education
        • Minecraft Lesson Ideas
        • Minecraft Literacy
        • Minecraft Coding Tutorials >
          • Minecraft Code Builder Setup
          • Minecraft Code: Walking on Air
          • Minecraft Code: Hello World
          • Minecraft Code: Functions
          • Minecraft Code: Rainbow
          • Minecraft Code: Skyscraper
          • Minecraft Pixel Art
    • The magic of >
      • The magic of Computing
      • The magic of Maths
      • The magic of Science
      • The magic of Literacy
    • Breakout Edu
    • PLN Challenge >
      • Covering your backside
      • Twitter Challenge >
        • Challenge 1
        • Challenge 2
        • Challenge 3
        • Tips for staying safe on Twitter
        • Tips for hosting Edu Twitter Chats
        • Tips for taking part in Twitter chats
        • How to storify a chat
        • How to schedule Tweets
        • Twitter Lists
        • It's all about the hashtag! Essential chats for educators
      • Facebook Challenge >
        • Challenge 4
        • Challenge 5
        • Challenge 6
        • Tips for staying safe on Facebook
      • Google Challenge >
        • Challenge 7
        • Challenge 8
        • Challenge 9
      • Pinterest Challenge >
        • Challenge 10
        • Challenge 11
        • Challenge 12
        • Tips for using Pinterest
      • Blog Challenge >
        • Challenge 13
        • Challenge 14
        • Challenge 15
        • How to create a classroom blog
      • Staffrm Challenge >
        • Challenge 16
        • Challenge 17
        • Challenge 18
      • Skype Challenge >
        • Challenge 19
        • Challenge 20
        • Challenge 21
      • Edmodo Challenge >
        • Challenge 22
        • Challenge 23
        • Challenge 24
      • TeachMeet Challenge >
        • Challenge 25
        • Challenge 26
        • Challenge 27
      • In-school challenge >
        • Challenge 28
        • Challenge 29
        • Challenge 30
      • 30 ways to grow your PLN
    • T&L Blog
  • Computing
    • Computing Blog >
      • GCSE Computer Science
      • General
    • CPD >
      • Blocks to Code
      • Tutorials >
        • How to embed Flash into PowerPoint
        • How to embed YouTube videos in to PowerPoint
        • How to create a wiki
        • How to create a classroom blog
    • Teaching Computer Science >
      • Schemes of Work
      • Programming Resources
      • Theory
      • Posters
    • Theory Lessons >
      • Theory Tests
      • Computer Hardware >
        • Input / Output
        • CPU
        • LMC
        • Storage Devices
        • Memory (RAM / ROM)
      • Binary Lessons >
        • Units of Data
        • Binary Representation
        • Binary Representation of Images
        • Binary Representation of Characters
        • Binary Representation of Sound
        • Binary Representation of Instructions
        • Binary Addition
        • Hexadecimal
      • Software >
        • Operating System
        • Types of Software
        • Utility Software
      • Programming >
        • Flowcharts
    • Game Design
    • App Creation
    • Digital Literacy >
      • Social Media (Good or Bad thing?)
      • Cyberbullying
      • Staying Safe Online
    • ICT Strand >
      • Spreadsheet Modelling
      • Superhero Movie Trailer
      • PowerPoint Task
      • Paint 3D Tutorial
    • Programming Lessons >
      • Microbit >
        • Magic 8 Ball
        • Harry Potter Sorting Hat
        • Music
        • Music (Festive)
        • Quick Start Guide
        • Microbit Simulator
      • TouchDevelop >
        • TouchDevelop Challenge
        • Scheme of Work
        • TouchDevelop Lessons >
          • 8 bit challenge
          • Turing Test
          • Turtle Power
          • 8 Ball
          • Under the hood
        • Tutorials
      • Raspberry Pi >
        • Networking the Pi
        • Minecraft Pi
        • Harry Potter Sorting Hat >
          • Harry Potter Sorting Hat (GPIO)
        • Raspberry Pi LTSP (Networked Classroom)
        • Astro Pi
      • Scratch
      • Python >
        • Chatbot
        • Coding Golf
        • Magic 8 ball
        • Python Mad Libs
        • Shakespearean Insult Generator >
          • Shakespearean Insult Generator Part 2
        • Sorting Hat
      • Little Man Computer
      • Hour of Code >
        • HoC 8-Bit Challenge
  • 21 Things
  • Microbit
    • Physical Computing >
      • micro:bit LEDs
  • About
  • Blog
Search by typing & pressing enter

YOUR CART

How to create your very own Raspberry Pi "Harry Potter Sorting Hat" - Pibrella Version

Picture
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:

  • 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:
  • 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):

  • 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 Pibrella
  • 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:

1. Official Sorting Hat (Amazon)
Picture
Official sorting hat endorsed by Warner Brothers.

Pros: 
  • Official sorting hat
  • Includes hidden pocket in which you can store your Raspberry Pi  
Cons:
  • Expensive (Approx. £30 New)

2. Witches Hat (eBay)
Picture
Replica wizards/witches hat from ilovefancydress.com.

Pros: 
  • Cheap (Approx. £4.99)
  • Looks very similar to the official sorting hat  
Cons:
  • Very flimsy.
  • No hidden pocket to store Raspberry Pi
3. DIY (Do It Yourself) Sorting Hat
Picture

Create your very own sorting hat. (Above is the version created by team Python - Led by yours truly at PiCademy)

Pros: 
  • Very Cheap (Use whatever resources you have to hand)

Cons:
  • Time consuming

Setting up the Pi:

1. First, students must attach their Pibrella to the Raspberry Pi (See instructions here: Setting up your Pibrella)

WARNING! Always shutdown your Raspberry Pi before connecting add-ons.

2. Next, students will need to connect their push button / switch to their Pibrella.

Connect the push button / switch using two jumper cables. 
Important! Make sure you connect the leads to Input A (See below)
Picture
Tip: You can connect the switch directly to the Pibrella using a couple of paperclips (See image below)
Picture
3. 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


Installing additional libraries

In order to create the sorting hat, students will need to install some additional 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)
Picture
Students will need to install the following libraries in order for the sorting hat to work:

  • Pibrella (This allows you to communicate with the GPIO pins via the Pibrella on the Raspberry Pi)
  • mpg123 (This will allow you to play the audio files)


Tip: Before installing new libraries, it's always a good idea to update the raspbian operating system first:

To upgrade the operating system:

  • type sudo apt-get update in the command line 
  • type sudo apt-get upgrade in the command line 


Next, students must install the Pibrella library package

At the command prompt, type in:

sudo apt-get install python-pip


followed by:

sudo pip install pibrella


Finally, students need to install the the mpg123 library 

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 idle as Super User (sudo) - without this, the students will not be able to communicate with the GPIO header via the Pibrella.

1. (If students haven't already done so) Double click on LXTerminal to start a command line
Picture
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)

## Sorting Hat version 2 - Uses Pibrella
# http://www.raspberrypi.org/learning/python-picamera-setup/

import pibrella
import time
import random
import os

def randomgenerator():
    number = random.randint(1,4)
    if number == 1:
        os.system ('mpg123 Gryffindor.mp3')
        time.sleep(1)
    elif number == 2:
        os.system ('mpg123 Hufflepuff.mp3')
        time.sleep(1)
    elif number == 3:
        os.system ('mpg123 Ravenclaw.mp3')
        time.sleep(1)
    else:
        os.system ('mpg123 Slytherin.mp3')
        time.sleep(1)

while True:
    # wait for the button to be pressed
    while True:
        while pibrella.input.a.is_high():
        # Slight pause for dramatic effect
            time.sleep(0.1)
            randomgenerator()


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

Important! Students MUST also copy the following audio files into the same folder as their python script:
ravenclaw.mp3
File Size: 19 kb
File Type: mp3
Download File

slytherin.mp3
File Size: 14 kb
File Type: mp3
Download File

hufflepuff.mp3
File Size: 18 kb
File Type: mp3
Download File

gryffindor.mp3
File Size: 15 kb
File Type: mp3
Download File


Here's one I made earlier:

Troubleshooting


I can't hear any sound from the speakers.

  1. Make sure that the audio files (above) are in the same folder as the python script.
  2. 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.
  3. Make sure you have installed mpg123 (sudo apt-get install mpg123)


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:
Picture
Raspberry Pi "Sorting Hat" lesson is licenced under a Creative Commons Attribution 4.0 International License.
Powered by Create your own unique website with customizable templates.