CSCI 255 — Raspberry Pi

Getting ready

You’ll need the following hardware for this lab.

Physical connection

To get your Pi running to the following in the specified order.

  1. Connect the Pi to the breadboard using the Adafruit Pi Cobbler. Make sure the red edge of the ribbon cable is on the same side as Pin 1 of the Raspberry Pi.
  2. Make sure your Pi has a properly inserted SD Card.
  3. Connect your Pi to the CSCI VLAN using one of the pink Ethernet cables.
  4. Make sure everyone’s Pi setups look the same.
  5. Find a power strip and plug in your Pi power supply.
  6. Connect the micro-USB connection of the power supply to your Pi.
  7. Wait for the Ethernet link lights to turn on.

IP connection

Your Pi should have a letter written on the Ethernet connection. The domain name of you Pi should be uncacsci-pi-λ.cs.unca.edu where Λ is the letter on the Pi.

Use ssh to connect to your Pi using the password revealed by the instructor.

ssh pi@uncacsci-pi-λ.cs.unca.edu

If this doesn’t work, the instructor may have to consult phone home page.

Pi activities

Pause for a minute while everyone gets connected and we start an orientation presentation. As we go through the presentation, there will be a few activities.

Trying out the command line

Execute a few of the commands on the Linux slide.

GPIO from the shell

At the Blinking LED slide, cd to your ccscse2014/examples directory and take a look at the shell script stored in ledBash.sh . Make sure that LED_1 and LED_2 are set appropriately for your board. (We know some of these boards are wired incorrectly.)

Fix, if necessary, the ledBash.sh shell script and run it. You will need to use sudo to avoid the nasty error messages.

If you get bored, put the program into an infinite loop.

Enabling I2C and checking out the wiring

Take a look at the Getting the Pi Ready slide. These task should have already been done. But move on to the Using the I2C utilities — finding the bus and execute the listed commands.

The output of the last one should like something like the following:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- 77 

Difficult temperature reading

Open the BMP180 datasheet in another browser window. Turn to the next slide, Using the I2C utilities — finding the bus and execute the listed commands. Note how these commands relate to the program found on page 15 of the BMP180 datasheet.

Put your finger on the BMP180 sensor, repeat the last two commands and see if the results changed.

Use the up-arrow key to recall previous commands.

C-based temperature reading

At the Running the simpler program, use nano to load bmp180json.c . Change the oversampling rate, OSS, for the BMP to 3.

At the command line, run the program make to recompile the program. make is a Unix command for the “smart” building of programs. It is used heavily in both NetBeans and MPLAB X.

Now run the bmp180json program.

Python-based sensor reading

Take a look at the bmp180json.py and adabmp180json.py Python programs. adabmp180json.py uses the Adafruit BMP180 library. bmp180json.py was written before the Adafruit library was available.

Now take a look at the Python code for the BMP085 object. (The BMP180 and BMP085 have the same I2C interface.) Find the method of BMP085 that returns the altitude.

Copy adabmp180json.py to altbmp180json.py and make the following changes.

When you have your altbmp180json.py program working it, delete it so that the next person has to do this on their own. You may use sftp to save your program on the CSCI server before you delete it.