June 28, 2015

After our latest Scratch game project we haven't done much coding, just played few games like Lightbot on
iPad. But since I have a Raspberry Pi, I started thinking she might like
to do some coding with physical things rather than just something
that's on the screen. And I would like to learn more about hacking with
hardware myself, since I'm not that familiar with electronics. I talked
about it with her and she got really exited and had an idea for a first
project almost instantly. She wanted to build traffic lights for lego
cars! That sounded like a great project, so I started looking what kind
of stuff would be required for a project like that.

After Googling around a bit and brushing up my knowledge of basic
electronics (that had gotten a bit rusty since I haven't done any
electrical work after high-school), I had an idea how we would do it. I
ordered various electronics bits and bobs from the net, such as LEDs,
jumper wires, resistors, few breadboards, switches, a GPIO cable etc.
You can get this stuff from pretty much any electronics shop, either
online or if you have a brick and mortar one nearby. I ordered a
shipment from Pimoroni since they have all kinds of nice accessories, for example a lego compatible breadboard, a lego compatible base plate for the Pibow case I already had, some colourful USB and HDMI cables and SD cards etc.

While waiting for the shipment to arrive, I talked to Kaisla about
electronics and tried to teach her some basic concepts. Like what is an
electric circuit, how current flows in the circuit and how we need to
adjust the current to our needs with resistors and how switches work by
breaking the circuit. She seemed to understand most of that pretty well
and even came up with some examples from real life, like the light
switches in our house. I also talked to her about how dangerous
electricity can be and that we must be cautious whenever we're
working with electronics. We also learned that it's important to plan
the electric circuits and how it's usually done by drawing a circuit
diagram and she drew a simple one with one LED and a resistor.

Robot Antenna

Before going ahead with the traffic lights project, I decided that we should try something a little more simple first. I found this nice
beginner project called Robot Antenna
in the official Raspberry Pi site that has lots of good learning
resources. It involves a very simple circuit with one LED and one
resistor and then it can be programmed using a modified version of
Scratch, called ScratchGPIO, with the same familiar user interface that
we are already used to with Scratch.

When we received the shipment, we were both excited and Kaisla was
very happy about the things I had gotten her, like a pink SD card and a
purple USB power cable. She was very pleased that she had her own memory
card and wanted to decorate it with a butterfly sticker.

Before starting with the robot antenna project, we first tried if we
could just light up a LED without any programming involved. The GPIO pins on the Rasberry Pi have different purposes, some need to be programmatically turned on
but some have constant power output (you can read more about them here
if interested). So we put together the circuit of one red LED and one
resistor (we used 330 Ohm like in the instructions for the robot
antenna) with some jumper wires and connected to the 3.3 volt power
output pin and a ground pin on the RPi. It was an exiting moment when I
plugged in the USB power cable for the first time, but the LED did light
up! We then tried all the other different coloured
LEDs I had bought, green, yellow and blue, and they all light up nicely
(even the blue did light up without changing the resistor, even though
it requires more voltage).

Next Kaisla started working on her robot. The only requirement was
that it should have an antenna, otherwise it was all left to her
imagination. She was sceptical at first whether she could draw a good enough
robot, but after some encouragement she did it and it came out really
nice and she was really pleased with it. We then cut it out and
glued it to an empty kitchen paper roll and I made hole for the LED at
the top of the antenna.

Then it was time to combine all of this. We needed to use one of the
programmable output pins now instead of the one with constant power and
we also put the RPi back into it's case so we needed to connect through
the GPIO cable now. So we changed from female-to-female jumper wires to
male-to-female wires for the ones that connect to the RPi. We put the
wires and LED inside the robot and pushed the LED through the hole and
it fit just nicely. We then booted up the Raspberry Pi (we are using the
"default" Raspbian OS on it), but ran into some troubles since the
ScratchGPIO doesn't come preinstalled on it and I hadn't configured the
WiFi on it yet so we couldn't install it right away. I had to Google a
little bit for instructions on setting up WiFi on Raspbian and Kaisla
got bored. She went on to do a puzzle (one with Elsa from Frozen) while I
got the WiFi set up and installed ScratchGPIO. After that we could
finally do the actual coding, a very simple program at first with just a
loop of 10 iterations that sets the pin on, waits one second, sets the
pin off and waits another second and executes by pressing the spacebar
key. With that, we had our very first program that interacts with
hardware we had wired ourself. It worked as expected and Kaisla was very
proud of it and wanted to show it to her mom and little sister.

All in all, it has been a very interesting first hardware project for
both of us and we have both learned a lot. Next we will start planning
the traffic lights project, and I'll write more about that later.