The Raspberry Pi and the book monster – The working demo

So today is my last session with the children and we will be creating quality audio and enhanced lighting sequence coding for me to combine into the final code for their book monsters. I finally got the tilt mechanism working and the wiring for the lights embedded in the monster’s eyes.
This short video show the demo kit working.

A big thanks to the schools and the children involved; it has been a wonderful project to be involved in and one I thoroughly enjoyed.

Posted in Mr Scott, Raspberry Pi Coding | Leave a comment

The Raspberry Pi and the book monster – Preparing for session 5

I have been busy this week creating a circuit and code in Python to combine the code written so far by the children to be triggered by a tilt switch.

The tilt switch will be connected to a flap inside the Book Monster’s throat and will be triggered as books are posted and push the flap open.

Below is a preview of the code and tilt switch in action, you may need to turn your volume up to hear the children’s audio files created in Session 4 being activated.

 

Posted in Raspberry Pi Coding | Leave a comment

The Raspberry Pi and the book monster – Session 4

Session 4 took place at the Innovation Centre as we needed access to some quality microphones and speakers.

In this session we quickly recapped the previous session and then discussed that the Book Monster would talk to the children when books were posted. To do this we needed to create some audio files that could be randomly played and we used the free audio software Audacity to do this.

We practiced recording our voices with Audacity to make sure the sound levels were okay and then learnt how to clip the beginning and end of the clip where necessary.

audio file example

Next we drafted several phrases we wanted the monster to say and then practised them in our best Monster voices. Once we were happy with them we recorded them carefully and then exported the files as MP3 files and saved them to the SD card we used with the Raspberry Pi.

Once completed we put the SD card back in the Pi, connected it up and turned it on.

We located the files on the SD card and copied them to a folder we created on the desktop of the Pi to use in our next piece of code.

We discussed how sound could be played and the code we could use as below.

import pygame ## this is library for graphics and sound
import time ## Import ‘time’ library. Allows us to use ‘sleep’
pygame.mixer.init() ## initialises the pygame mixer
pygame.mixer.music.set_volume(20.0) ## set the maximum volume
pygame.mixer.music.load(‘your mp3 filename’) ## load your audio track
pygame.mixer.music.play() ## play your loaded audio file
time.sleep(5) ## wait 5 seconds
pygame.mixer.music.load(‘your mp3 filename’) ## load your next audio track
pygame.mixer.music.play() ## play your loaded audio file
time.sleep(5) ## wait 5 seconds

This code allowed us to play a couple of the clips we had recorded to see if it worked. It worked really well and all the groups were excited to hear their Monster Voices being used on the Pi.

Posted in Raspberry Pi Coding | Leave a comment

Raspberry Pi adventure part 3

Today was really fun because we made a light flash like a traffic light. First we  had to put in 3 bulbs instead of 1. First the red light bulb went in then the yellow at the same time then we off the both of them and off  the green like a traffic light. We were the first one as normal.(By Miguel)

Posted in Uncategorized | Leave a comment

The Raspberry Pi and the book monster – Session 3

Session 3 was going to be a challenging session as we would be introducing multiple LEDs, breadboards (we did look at breadboards briefly in session 2) and programming the LEDs to work independently.

The children quickly and confidently set up their Pi and opened their last program in Python. In session 2 we had to wire an LED to the Pi but some of the jumper leads we used did not connect to the pins very securely so we substituted this with a breadboard for ease of use. A breadboard allows several electrical components such as switches, LEDs and buzzers to be connected easily to test circuits. There are different sizes of breadboard and the one below is the breadboard we used.

breadboard

 

 

 

 

 

 

It is important to understand how the breadboard is wired and the image below shows how the pins on top of the board are connected by wires internally.

breadboard wiring

 

 

 

 

 

 

 

We used the breadboard to create a simple circuit with one LED and used our lights v2 program to make it flash.

I then asked the children to make the following circuits and predict if they would work.

series circuits

These circuits are called series circuits as each component is linked to the other in a linear way. The LEDs did not light up. Without getting too technical there is not enough voltage from the GPIO pin to light all three LEDs in this way.

I then asked the children to connect the LEDS as below. This circuit is called a parallel circuit and because each LED is connected directly to the GPIO pin there is no loss of voltage and so all 3 LEDs light up.

parallel circuit

 

The children were now able to control all 3 LEDs and we discussed if we could control the LEDs individually from the one GPIO pin. Obviously we could only program the GPIO pin connected to all 3 LEDs so the answer was no. The children then discussed how they could achieve this by using more than one GPIO pin per LED and changing their code.

 

 

They very carefully created the circuit below to control all 3 LEDs independently.

breadboard multiple gpios

 

 

 

 

 

 

 

They were then asked to alter the code in Lights v2 to utilise all 3 connected GPIO pins and save this as Lights v3.

 

The initial code changed as below

import RPi.GPIO as GPIO ## Import GPIO library
import time ## Import ‘time’ library. Allows us to use ‘sleep’
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO4 (Pin 7) to OUT
???????
???????

became

import RPi.GPIO as GPIO ## Import GPIO library
import time ## Import ‘time’ library. Allows us to use ‘sleep’
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO4 (Pin 7) to OUT
GPIO.setup(11, GPIO.OUT) ## Setup GPIO17 (Pin 11) to OUT
GPIO.setup(13, GPIO.OUT) ## Setup GPIO21 (Pin 13) to OUT

Below is an example of the finished code controlling all three LEDs.

import RPi.GPIO as GPIO ## Import GPIO library
import time ## Import ‘time’ library. Allows us to use ‘sleep’
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO4 (Pin 7) to OUT
GPIO.setup(11, GPIO.OUT) ## Setup GPIO17 (Pin 11) to OUT
GPIO.setup(13, GPIO.OUT) ## Setup GPIO21 (Pin 13) to OUT
GPIO.output(7,True) ## Turn on GPIO4 (pin 7)
time.sleep(3) ## wait 3 seconds
GPIO.output(11, True) ## Turn off GPIO17 (pin 11)
time.sleep(3) ## wait 3 seconds
GPIO.output(13,True) ## Turn on GPIO21(pin 13)
time.sleep(3) ## wait 3 seconds
GPIO.output(7, False) ## Turn off GPIO4 (pin 7)
GPIO.output(11, False) ## Turn off GPIO17 (pin 11)
GPIO.output(13, False) ## Turn off GPIO21 (pin 13)
GPIO.cleanup() ## resets GPIO pins

The children then created their own code to make their own sequences of lights.

I was very impressed on how much progress the children had made in three sessions. They were now able to set up the Pi, use a breadboard to make their own circuits, connect this to the Pi and then create original code to control the LEDs to flash to their own sequences using Python.

Posted in Mr Scott | Leave a comment

The Raspberry Pi and the book monster – Session 2

The children from all three schools seemed very excited about the second session.

We recapped session one and many of the children were able to recall several of the acronyms we discussed and were given the task of setting up the Pi independently for this session.

We revisited the GPIO pins and discussed the fact that these pins were programmable so that they could act as outputs or inputs and we discussed inputs and outputs for devices in our world such as burglar alarms, traffic lights, remote controls, etc.

second circuitWe created a similar circuit to the one we did in session one but this time we used a GPIO pin rather than the 3.3v pin. When we did this the LED did not light up and we discussed that we had to programme how the GPIO pin we were using worked.

We used the command sudo idle from the command line to launch the program Python. The sudo command is important here and means Super-User DO allowing us to directly control the GPIO pins.

We created a new python file called Lights v1 and then looked at the following code.

import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO4 (Pin 7) to OUT
GPIO.output(7,True) ## Turn on GPIO4 (pin 7)

The ## is very important when coding in Python as they do not represent any code but allow the programmer to make a comment about the code and what it does. This is very useful when the code does not work and it needs to be debugged. It is particularly useful when the code is shared with other coders as it allows them to understand what each line of code is designed to do. We have highlighted this in red here for clarity only.

  • The first line ensures the Pi can use the commands to control the GPIO pins.
  • The GPIO pins have two modes of identification. For example, GPIO4 can also be referred to as pin 7.  The second line tells the Pi the naming system we will use to identify the pins.
  • The third line tells the Pi the GPIO pin we are using (pin 7 also known as GPIO4) to act as an output
  • The fourth line turns the pin on and sends an electrical current through the pin.

The children were aware of the importance of syntax when coding and were very careful not to make any mistakes. They then saved their Python file and ran it. The LED came on and the satisfaction on the faces of the children was clear to see.

 

The last activity of the session was to try and get the LED to flash. To do this we had to use the time library and the sleep command. Below is an example of the code the children created to make a flashing LED in a file they called lights v2.

import RPi.GPIO as GPIO ## Import GPIO library
import time ## Import ‘time’ library. Allows us to use ‘sleep’
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO4 (Pin 7) to OUT
GPIO.output(7,True) ## Turn on GPIO4 (pin 7)
time.sleep(5) ## wait 5 seconds
GPIO.output(7, False) ## Turn off GPIO4 (pin 7)
time.sleep(5) ## wait 5 seconds
GPIO.output(7,True) ## Turn on GPIO4 (pin 7)
time.sleep(5) ## wait 5 seconds
GPIO.output(7, False) ## Turn off GPIO4 (pin 7)
time.sleep(5) ## wait 5 seconds
GPIO.cleanup() ## resets GPIO pins

All the groups were successful in getting their LED to flash

Posted in Mr Scott | Leave a comment

The Raspberry Pi and the book monster – Session 1

I created packs of Raspberry Pi materials for the children to utilise during our first session at St Francis with small groups of children from each of the schools.

The packs included a Raspberry Pi, a clear Pi case, power supply for the Pi, HDMI cable, a serial to HDMI converter and power lead (the monitors we were using had no HDMI input), monitor with serial cable, an LED, an SD Card with the Raspbian OS installed and some custom built jumper wires. I used the keyboard, mouse and ethernet cable from existing PCs in the ICT suite.

The session looked at understanding what a Raspberry Pi is, how to connect the kit in the box to the various ports and running the Pi from the SD card. The children were great and thoroughly enjoyed connecting the components and learning an assortment of acronyms such as LED, HDMI, USB, etc.

On start up the Pi is set to open to a command line interface not a usual desktop interface and the children had to login and use the startx command to get a more familiar desktop interface.

We discussed the settings the Pi used when booting up and decided we would change some of this for ease of use later.

From the command line interface we typed sudo raspi-config to enter the Configuration Tool and made changes so that the Pi booted to the desktop and made the default audio output the 3.5mm audio out rather than the HDMI output because we will be connecting speakers later in the project.

We were then introduced to the concept of coding and that everything the Pi can do is coded somewhere. We want on the Internet and found the default search engine was duckduckgo.com and discussed changing this to Google. The only way we could do this was to edit the code in the Raspbian OS. The children became aware very quickly of the importance of syntax and that any slight error in creating / editing code could result in the Pi not working properly. The children carefully carried out the task below and were very excited to see that they had changed the way the Pi operated the next time they used the Internet and it defaulted to Google.

Original code

<key type=”s” name=”keyword-search-url”>
<default>’https://duckduckgo.com/?q=%s&amp;t=raspberrypi'</default>
<summary>URL Search</summary>
<description>Search string for keywords entered in the URL bar.</description>
</key>

Carefully change the code in bold to the code below

<default>’https://www.google.co.uk/search?q=%s'</default>

Next we were introduced to the GPIO (general purpose input output) pins and used the jumper wires and the LED to create a simple circuit (using the Pi as a battery) to light the LED.

The children were very focused and I was impressed with their ability to work with a new device collaboratively and effectively.

Posted in Mr Scott | Leave a comment

The Raspberry Pi and the book monster

The Curriculum Innovation team was contacted by Dan Copley, the Headteacher of St Francis Catholic Primary, to discuss an idea he had on creating a man size book monster. The book monster would be located in the library and children would ‘feed’ the book monster with books when they returned the books to the library. He enlisted the help of a local model maker / special effects expert Ellie Morley to work with the children to design and build the 1.5m models.  Dan wanted the book monsters to interact with the children when they posted the books and discussed this with me (Paul Scott from the Curriculum Innovation team). Discussions included parts of the monster moving but from a technical perspective it was clear this would be prohibitively expensive to achieve so it was agreed that the monster would have eyes that lit up and it would speak to the children when fed by books.

Dan discussed the project with some partner schools and St Anthony’s Catholic Primary and St. Matthew’s Catholic Primary.

I looked at several ways to achieve this and decided that the most cost effective solution would be to use a Raspberry Pi.

 

 

 

 

 

 

 

I visited some very helpful staff at Bradford University’s Pi Nest who gave some good advice on what I would need to use the Pi to control external components such as LEDs and switches. With this information and access to on-line resources such as www.raspberrypi.org and YouTube I decided to investigate a solution coded using Python on the Pi.

 

Posted in Mr Scott | Tagged | Leave a comment

Raspberry Pi session 3

Today we learnt how to wire up multiple LED lights to a breadboard and also learnt how to write the correct code to make them light up at different times. I found it a bit difficult because of all the different code we had to do and I also found it difficult because of the wires we had to put in the breadboard.

Posted in Uncategorized | Leave a comment

My Raspberry Pi Adventure – Part 3

Today I learnt how to use the bread board using 3 LED lights. It was really fun because my group made it turn off and on like a traffic light. We made it turn red, then yellow, then green. It was yet again another really complicating challenge but one we achieved!
By Ella

Posted in Uncategorized | Leave a comment