Getting Started with a Raspberry Pi

Student wires the breadboard attached to a Raspberry Pi.
Student wires LED’s to a circuit on a breadboard attached to a Raspberry Pi.

Raspberry Pi‘s are small computers that are remarkably easy to use if you know what you’re doing. Unfortunately, I did not quite know what I was doing. On the other hand, fortunately, I had Mr. Schmidt available to give me the kick start I needed to get going. In this post, I’ll outline, in as much detail as possible, how we got started; how we helped a student put together a synchronized LED light and digital sound project.

You should just be able to plug your Pi into a monitor using the HDMI cable that comes with the starter kit (like this kit by Adafruit) and power it up. However, we did not have a monitor that could take an HDMI cable, so we had to connect the hard way: by plugging the Pi into an ethernet cable and finding it on the local network. This is what’s called a headless setup — with no monitor and no keyboard — and I followed a lot of Robert A. Wood’s instructions on headless setups.

Install the Raspbian Operating System for remote access

First you have to make sure you have a bootable operating system on the Pi’s SD card that will allow you to connect remotely through the internet. The card that came with the starter kit had the basic NOOBS operating system installed, but NOOBS does not allow remote access by default.

I downloaded the Raspbian raw image to my computer then copied the image to the SD card using the terminal program dd. Follow this procedure with caution because you can do a lot of damage if you copy the image over your computer’s hard drive (which is remarkably easy to do with dd). The procedure follows:

1) Once you plug the SD card into your computer it should mount automatically. You need to detect where it is mounted using (on a Mac running OSX) the diskutil program:

> diskutil list

This should give you a list of all of your mounted disks. Identify the one that is the SD card. It should look something like this:

Output from 'disktuil list'.
Output from ‘disktuil list’.

It shows my 4 gigabyte disk located at ‘/dev/disk1’.

2) If you’re absolutely sure you’ve identified the SD card you need to unmount it:

> diskutil unmountDisk /dev/disk1

3) Now if you’re still absolutely sure you have the right location of the SD card copy the image. Note that in the example below the option ‘if‘ means input file, while ‘of‘ means output file:

> dd if=~/raspberry/raspi/2014-01-07-wheezy-raspbian.img of=/dev/disk1

I had the devil of a time trying to install the raw image of the Raspbian operating system. After a few hours of frustration I finally pulled an SD card from my small camera and lo-and-behold the copy went through easily. So make sure you have a good quality card.

Talking to the Pi

Plug the SD card with Raspbian installed into the Pi, plug the Pi into a power outlet, then and plug an ethernet cable into the Pi. The Pi should boot up and connect to the internet automatically. Now you just have to find it from your computer. Mr. Schmidt helped a lot with this step, but I also used Pete Taylor’s instructions as well.

The ifconfig command will tell you your computer’s IP address. Look under the section en1.

> ifconfig

My IP address turned out to be 191.163.3.218.

To find the Pi I had to download and install nmap to locate all things on the local network. Once installed I used:

> sudo nmap -sP 191.163.3.0/24

You should find something labeled ‘Raspberry Pi’ with an IP address that’s almost identical to yours except for the last of the four numbers. I found mine at 191.163.3.214.

Now, you can log in to the Raspberry Pi using the username ‘pi’ and the password ‘raspberry’:

> ssh pi@191.163.3.214

And, ‘Bam’, you’re in.

Configure and Update

I used the configuration utility ‘raspi-config’ to expand the root file system to take up the entire SD Card: expand_rootfs:

pi> raspi-config

Update the software using the two commands:

pi> sudo apt-get update
pi> sudo apt-get upgrade

You can also set up the Pi for remote window access by running a Virtual Network Computing (VNC) server and using a vnc client (like Chicken on the Mac). I installed ‘tightvnc’ and started the vnc server on the Pi with:

pi> sudo apt-get install tightvncserver
pi> vncserver :1

We never did end up using the vnc window, however.

The light circuit

We hooked up the LED circuit to the output pin GPIO 17 in series with a resistor and then back into a ground pin of the Pi, pretty much as the Gordon’s Projects page describes.

Talking to the Circuits/Pins

In order to get the Pi to operate the LED lights you have to control the pins that communicate in and out. Our starter kit came with a ribbon cable and breakout board that connects the pins from the Pi to a breadboard, which makes it easier to build circuits.

But first we have to be able to control to the Pi’s pins. I tried two different methods. The first was to use wiringPi, which is a set of command line tools, while the second was to use the Rpi.GPIO library for the Python programming language. We found it was much easier to use Python for its ease of programming.

Command line: wiringPi:

To get wiringPi, download it with ‘git‘, go to its directory, then build it (Gordon’s Projects has the instructions):

pi> git clone git://git.drogon.net/wiringPi
pi> cd wiringPi
pi> ./build

Now you can manipulate pin 0 (GPIO 17, which is labeled #17 on the breakout board) by: 1) setting to output mode; 2) turning it on, and; 3) turning it off:

pi> gpio mode 0 out
pi> gpio write 0 1
pi> gpio write 0 0

The following short script (red-light-flash.s) turns the light on and off ten times:

red-light-flash.s

#!/bin/bash
# a single blinking led light attached to gpio0
# based on 
# https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/

for i in `seq 1 10`
do
gpio write 0 1
sleep 0.5
gpio write 0 0
sleep 0.5
done

The script needs to be given execute permissions:

pi> chmod 777 red-light-flash.s

then run:

pi> ./red-light-flash.s

Python: Rpi.GPIO

As I mentioned above, it’s much easier to write programs in Python than to use shell scripts. So we’ll install the Python library, RPi.GPIO, to that allows us to communicate with the Pi. To get RPi.GPIO we first need the Python Development toolkit:

pi> sudo apt-get install python-dev

Then install Rpi.GPIO:

pi> sudo apt-get install python-rpi.gpio

To operate the GPIO-17 (turn it on and off every half second) we use the following program:

flash.py

#!/usr/bin/env python
 
from time import sleep
import RPi.GPIO as GPIO

cpr = 17  ## The GPIO Pin output number

GPIO.setmode(GPIO.BCM) ## Use board pin numbering

GPIO.setup(cpr, GPIO.OUT) ## Setup GPIO Pin 7 to OUT

for i in range(10):
	GPIO.output(cpr, True)
	sleep(0.5)
	GPIO.output(cpr, False)
	sleep(0.5)
GPIO.cleanup()

We run the program using the command:

pi> sudo python flash.py

Addendum: A Student’s Light and Sound Project

During our Creativity interim, one student chose to use the python program flash.py as a starting point to make a program to combine light and musical notes.

Snow Days

The road to school (from the west) on a snow day.
The road to school (from the west) on a snow day.

With all the cold temperatures and serial snowstorms, it has been quite the winter in Missouri. The wonderfully hilly roads around St. Albans are picturesque, but can become quite tricky with a fresh layer of snow and ice. Our head of school is understandably cautious, so we’re on our forth snow day this semester even though we’re only one month in.

Kids sledding (at home) on a snow day.
Kids sledding (at home) on a snow day.

Mars Colonization Project

My high-school biology class is taking their exam on genetics and evolution. To make the test a little more interesting, and to point out that there may be some relevance for this knowledge in the future, I made the test a questionnaire for the new head of the Mars Colonization Project. It begins like this:

Friday, January 30th, 2054.

Dear Dr. ________________ (insert your name here):

We are excited that you have accepted our offer to head the Biomedical Division of the MCP. As we are engaged in the first ever effort to colonize another planet, we know that we will face many unique challenges. Your expertise in pluripotent stem cell research and oncology will be extremely valuable to us — even though some of us administrators still don’t know what pluripotent stem cells are.

Please fill out the questions in this document to help us with our planning for the colony and to help our Human Resources department assemble your research and medical team.

Because of the sensitivity of some of the personal information included in this document, please write out, and sign, the Honor Code below before turning the page.

Yours truly,

Board of Administrators,
Martian Colonization Project

Front page of the High Schooler's Biology exam.
Front page of the High Schooler’s Biology exam.

Then I pose all of the questions in this context. For example, to get their knowledge of vocabulary I ask them to define the scientific words and phrases (which they’ve used in their scientific publications many, many times), in terms that laymen — like the people on the board of administrators — could understand.

To get at more complex concepts, like the molecular process of gene expression and regulation, I phrased the question like this:

Medical Issues Related to Ongoing Colonization Planning

The trip to Mars will take five years, so we will be placing most of the colonists into cryogenic sleep for most of that time. We are still working out some of the bugs in the cryogenic technology, and we need your help.

To put people into cryogenic sleep, we need to stop their digestion of carbohydrates. Your predecessor, Dr. Malign, told us that we could do this using RNA interference, by injecting them with engineered microRNA that would block the production of the enzyme amalyse.

Could you draw a diagram of a cell showing how proteins are expressed from DNA, and how microRNA would interfere with protein production. Are there other methods for preventing protein expression?

We’ll see how the students do on the test, however at least one student glanced at the front page and said, “This is kinda cool,” (actually, she first asked if I’d stolen the idea from the internet somewhere), which is significant praise coming from a teenager.

Using Soil pH as a Proxy for Ammonia Concentration

pH measurements from soil, bird manure, composted horse manure, and kitchen compost.
pH measurements from soil, bird manure, composted horse manure, and kitchen compost.

We’ve acquired a selection of manures and composts for revitalizing our orchard, but don’t quite know if they’re safe to add to the soil. Too much nitrogen in the manure will “burn” plants. Therefore, we tried a simple pH test as a quick-and-dirty proxy for estimating the nitrogen/ammonia concentration of the samples.

Since we’ve been working on the orchard, Dr. Sansone has contributed a pile of composted horse manure, a pile of composted kitchen scraps, and a pile of mixed compost and pigeon manure. You’re supposed to let bird manure compost for quite a while (months to years) before using it because of the high ammonia content that is produced by all the uric acid produced by birds.

The “burning” of the plants happens, primarily, when there’s too much ammonia in the manure. Ammonia becomes basic (alkaline) when dissolved in water (thanks to Dillon for looking that up for us). The ammonia (NH3) snags a hydrogen from a water molecule (H2O) making ammonium (NH4+) and hydroxide ions (OH).

NH3 + H2O <==> NH4+ + OH

The loose hydroxides make the water basic.

When excess amino acids are broken down the amine group becomes ammonia.
When excess amino acids are broken down the amine group becomes ammonia.

The ammonia, in this case, comes primarily from the breakdown of urea and uric acid in the manure. Animals produce urea (in the liver) from ammonia in the body. The ammonia in the body comes from the breakdown of excess amino acids in food. We get the amino acids from digestion of proteins (proteins are long chains of amino acids. The urea is excreted in urine, or in the case of birds as uric acid mixed in with their feces.

Experimental Procedure

  1. Weigh 100 g of soil/compost/manure.
  2. Add enough water to fill the beaker to the 300 ml level. Some of the samples absorbed significant amounts of water necessitating more water to get to the 300 ml level.
  3. Stir to thoroughly mix (and melt any ice in the soil) then let sit for 5 minutes.
  4. Pour mixture through filter (we used coffee filters).
  5. Test the pH of the filtrate (the liquid that’s passed through the filter) using pH test strips.

Important Note: We did the experiment under the hood, because the pigeon manure was quite pungent.

In addition to testing the manure and compost, we tried a soil sample from the creek bank, and a sample of fresh pigeon manure to serve as controls.

Results

The results were close to what we expected (see Table 1), with the bird manure having the highest pH.

Table 1: pH of soil, manure, and compost samples.

Sample pH
Topsoil from Creek Bank 6
Fresh Pigeon Manure 8-9
Kitchen Compost 5-6
6 Month Old Pigeon Manure/Compost Mix 6-7

Discussion/Conclusion

While the high pH of the fresh pigeon manure suggests that it probably too “hot” to directly apply, it was good to see that the composted manure had a pH much closer to neutral.

This is a simple way to test the soil, so it may be useful for students to do this as we get new types of fertilizer.

Drawing Faces: An Exercise in Heredity

A.C.'s demonstration of how to draw a face.
A.C.’s demonstration of how to draw a face.

My biology students are doing an exercise in genetics and heredity that requires them to combine the genes of two parents to see what their offspring might look like. They do the procedure twice — to create two kids — so they can see how the same parents can produce children who look similar but have distinct differences. To actually see what the kids look like, the students have to draw the faces of their “children”.

“I’m not going to claim that child as my own!”

I was walking through the class when I heard that. Apparently one student, who’d had a bit of art training, was paired with another student who had not.

Fortunately, I was able to convince the more practiced artist to give the rest of the class a lesson on how to draw faces. She did an awesome job; first drawing a female face and then adapting it a bit to make it look more male.

If nothing else, I tried to make sure that the other students registered the idea that proportion is important in drawing biological specimens — like faces — from real life. Just getting the proportions right made a huge difference in the quality of their drawings. The forehead region should be the largest (from the top of the head to the eyebrows), then the area between the eyebrows and the bottom of the nose, then the nose to lips, and then, finally, the region from lips to chin should be shortest. You can see the proportion lines in the picture above.

The adaptation stage, where she made the facial features more masculine, was also quite useful. The students had to think about what were typical male features and if there were a genetic basis to things like square chins.

Although all of the other students’ drawings improved markedly, including her simulated spouse’s, I don’t think my art-teaching student was absolutely happy with the end results after the one lesson. She ended up handing in two drawings of her own even though everyone else (including her partner) did one each.

However, having all the students on the same page, working with the same basic drawing methods, helped improve the heredity exercise because it reduced a lot of the variability in the pictures that resulted from different drawing styles and skill levels.

I also think that taking these interludes for art lessons are quite useful in a science class, since it emphasizes the importance of accurate observation, shapes student’s abilities to represent what they see in diagrams, and demonstrates that they can — and should — be applying the skills they learn in other classes to their sciences.

Instruction on how to draw a face.
Instruction on how to draw a face.

Abstract = Spoilers

Although it feels like you're giving away the whole story -- because you are -- the Abstract should be all spoilers.
Although it feels like you’re giving away the whole story — because you are — the Abstract should be all spoilers.

I was trying to explain that the abstract of a lab report was a really brief summary of everything in the report.

One of my students said, “Oh, so it’s like spoilers.”

And they were right.

If you didn’t know, spoilers are little bits of information that give away the plot. While you don’t want any spoilers if you have not seen the movie, in a lab report you what to give away the plot because since it’s a short, concise summary, it’s what most people will read.

So now my middle-schoolers are submitting lab reports with a section called “Spoilers” on the cover page.

Natural Selection by Alfred Russel Wallace

Everyone knows about Charles Darwin, but hardly anyone remembers Alfred Russel Wallace, who came up with the idea of natural selection at the same time as Darwin. Darwin’s publication of the On the Origin of Species was spurred on by Wallace. Flora Lichtman and Sharon Shattuck shed a little light on Wallace with this video:

Indeed, from the introduction of On the Origin of Species:

I have more especially been induced to [publish], as Mr. Wallace, who is now studying the natural history of the Malay archipelago, has arrived at almost exactly the same general conclusions that I have on the origin of species. Last year he sent to me a memoir on this subject, with a request that I would forward it to Sir Charles Lyell, who sent it to the Linnean Society, and it is published in the third volume of the Journal of that Society. Sir C. Lyell and Dr. Hooker, who both knew of my work—the latter having read my sketch of 1844—honoured me by thinking it advisable to publish, with Mr. Wallace’s excellent memoir, some brief extracts from my manuscripts.

— Darwin, 1859. On the Origin of Species.

The Dish