##Introduction
We are going to make a talking robot using a Raspberry Pi. A Raspberry Pi is a small computer that we can use to create exciting technology. It was created in the UK by the Raspberry Pi Foundation to help young people like you learn how to code.
This small computer features amazing HD (high-definition) quality video and playback, sports high quality audio, and has the ability to play 3D games.
To use this tutorial you will need a Raspberry Pi, a few electronics components, and ScratchGPIO already installed on your SD card. See here for instructions on how to do this
First check that you have all the parts you need to get your Raspberry Pi set up and working.
- Raspberry Pi
- Micro USB power adaptor
- An SD card with Raspbian already set up through NOOBS
- USB keyboard
- USB mouse
- HDMI cable
- A monitor or TV
###Activity checklist:
-
Place the SD card into the slot of your Raspberry Pi. It will only fit one way so be careful not to break the card.
-
Next connect the HDMI cable from the monitor (or TV) to the HDMI port on the Pi and turn on your monitor.
-
Plug the USB keyboard and mouse into the USB ports on the Pi.
-
Plug in the micro USB power supply and you should see some text appear on your screen.
-
When prompted to login type:
Login: pi Password: raspberry
Let’s get hands-on with electronics! This is where the Raspberry Pi comes in handy. You will program a small light called an LED (Light Emitting Diode) to flash.
You will need a coloured LED, a straightened paper clip (not plastic-coated), a 220 ohm resistor, and 4 female to female jumper wires.
###Activity checklist:
-
The LED has a short leg and a long leg. Slot a jumper wire onto the long leg.
-
Slot the resistor into the other end of the same jumper wire.
-
Add another jumper wire on the other end of the resistor.
-
Make another jumper wire and slot one end onto the short leg of the LED, and the other end onto the unfolded paper clip.
-
Find pin 1 and pin 6 on your Raspberry Pi using the diagram below:
The general purpose input output (GPIO) pins on the Raspberry Pi speak and listen to the outside world and can be controlled or programmed. Each pin has a specific role; to make things easier the pins are numbered for reference. Pin 1 is for power and pin 6 is for grounding.
-
Plug the resistor jumper wire into pin 1 on your Raspberry Pi, and the paperclip jumper wire into pin 6.
-
Plug in the micro USB power supply and you should see some text appear on your screen.
####How the light antenna works
Now you have a circuit and the LED should be on. But why does the LED shine?
When the circuit is plugged into the Raspberry Pi GPIO pins, electricity flows through the circuit. The flow is called the current.
The LED only lights up when electric current flows from the long leg through the bulb to the short leg.
The resistor reduces the amount of electric current passing through the circuit. This protects the LED from breaking, as a high current will make the light shine more brightly and then stop working.
Now that you have an antenna that lights up and is connected to your Raspberry Pi, you can write a program to tell the LED when you want it to come on.
For this section you will need to use pin 11 rather than pin 1 to power your LED. Pin 11 is special as it can switch power on and off if you tell it to!
You will need ScratchGPIO installed (see the instructions sheet for installing ScratchGPIO).
###Activity checklist:
-
Switch off the power to the Raspberry Pi. Move your jumper wire from pin 1 to pin 11. (Use the diagram from earlier to locate pin 11.) Then switch the power back on.
-
When prompted to login type:
Login: pi Password: raspberry
-
Once you have logged in, type
startx
to load the desktop. -
The desktop should have a ScratchGPIO icon. Double-click it.
-
If prompted click OK when the remote sensor connections are enabled.
-
Right-click on the Scratch cat and choose delete from the menu.
Then click on the button for a new sprite and choose robot3 from the fantasy folder.
-
Click on control in the top left display. Drag the when Sprite1 clicked block onto the scripts area. Then click on Sound, drag the play sound block onto the scripts area and connect it to the 'control' block.
-
Click on the Sounds tab above the scripts area and then click on Import. Choose Electronic and then ComputerBeeps2. This will add it to the sounds tab.
-
Now go back to the scripts area by clicking on the scripts tab. Click on the drop-down box next to 'play sound'. Choose the sound you just imported from the menu.
-
Test that your program is working so far by clicking on the robot sprite. It should beep!
-
Save your work by clicking on File and Save As. Name your file Robot and click OK.
-
Click on the control in the blocks palette, drag a broadcast block to your scripts area and attach it to the 'play sound' block. Click on the drop-down menu on the 'broadcast' block and select new.
In the message name box type pin11on This instruction will tell the Raspberry Pi to light the LED.
-
Drag a wait 1 second block onto the scripts area and connect it to the 'broadcast' block.
-
Test your program by clicking on the robot sprite. You should see the cardboard robot’s antenna light shine and stay on.
-
Drag another broadcast block onto your scripts area and connect it to the 'wait 1 second' block. Click on the drop-down menu on the 'broadcast' block and select new.
In the message name box type pin11off. This will switch off the light on the cardboard robot’s antenna.
-
Now add another wait 1 second block to the script.
-
Test your program again by clicking on the robot sprite. You should see the light on the cardboard robot’s antenna come on for 1 second and turn off for one second.
You will now make a cardboard robot and add your light antenna.
First you need to make your robot. To do this you will need colouring pencils, A4 paper, scissors, glue or sticky tape, a cardboard tube, plasticine or blu tack, and a printer.
###Activity checklist:
-
On a sheet of A4 paper, draw or print your own robot design. It should be drawn in portrait orientation so it can be wrapped around your cardboard tube. Make sure it has an antenna!
-
Colour in the robot picture and cut it out carefully.
-
Wrap the robot around the cardboard tube lengthways.
-
Glue or tape the robot in place.
-
Stick plasticine or blu tack behind the robot’s antenna inside the cardboard tube.
-
Push a pencil into the antenna to make a hole through the cardboard tube.
-
Remove the plasticine/blu tack.
-
Put your circuit of jumper wires, LED, resistor, and paper clip inside your cardboard tube. Push your LED through the hole in the tube to make the robot’s antenna.
-
Give your robot a name and welcome it to the world.
Congratulations, your robot is complete!
- Can you make the cardboard robot’s antenna stay on for longer?
- Can you make the light flash more than once?
- Record new sounds to play when your program plays.