Sunday, May 26, 2013

My RaspBerry Pi

(Hint: if you are new to the Raspberry Pi you might want to review my earlier posts)

Since an early disaster with the Pi's Linux filesystem I have been pretty careful about backing up any programming work over WIFI to my iMac. The last time I downloaded the full Linux image I also retained the file on the Mac. The one thing I had not done was to back the whole SD card. It turns out that my original stuff only took up about 2GB on my 16GB SD. But since then I have downloaded a lot of new software. This includes the the latest Linux updates, GPIO libraries, drivers for devices, and most recently, software to read weather reports as text from the Internet.

This AM when I booted the Pi up, my usual SSH (secure shell) from my iMac didn't work. Scary! Also, the activity light on my USB wifi dongle wasn't blinking. So I pulled the SD card out of the Pi, plugged it into a flash card hub on the Mac and immediately made a literal copy with the old UNIX DD command. I'm going to do that regularly from now on. Anyway, after I moved the wifi dongle to a different port on the USB hub everything worked again. So, no big deal. But now I'm fully insured against disaster.

I'm now waiting for some spring-clip connectors for breadboarding. Much less trouble than soldering pins on to flimsy wiring.

Saturday, May 25, 2013

If you are new to the Raspberry Pi you might want to start back to my earlier posts.

Got 3 things from Adafruit today:

  1. Many more assorted M/M jumper wires (you really want lots of lengths and colors).
  2. A DHT22 temperature/humidity sensor.
  3. A POS-type motion sensor.
In a mere hour I have the DHT working. I'm getting better at this! However, there were some wrinkles to work out.
  • The best info on how to use the Adafruit wiring plan and code was in French at -- luckily I still remember enough francais from 60 years ago to get by.
  • The sample program did the hard part of reading the DHT22, but it didn't suit me otherwise. More luck: that program was written in C Language. While at the old Bell Labs and Clemson U. I programmed mostly in C from 1972 to the late '90s. I simplified the program down to what I needed and fixed a small bug: the code as I found it returned success even when the DHT22 was read incorrectly. 
I still have the motion sensor to conquer. But who's worried.

I'm still working toward a vegetable farm automation system. While pawing through Raspi references I found--

Ray (assuming it's a person, probably male) has developed an add-on interface board for the Raspi that can control an 8-station irrigation setup. It costs about $150, plus the Pi, plus the irrigation parts. For another $50 you get 8 more hose valve controls. There is even code for controlling every valve from the Internet. Or -- it can be operated from a Google calendar. 

Here's my messy setup du jour:

Thursday, May 23, 2013

Things I've got working so far (Python programs):

  1. LEDs (probably always the first try).
  2. Buttons, button to turn LED on.
  3. Read the CPU temperature (and Halt the processor if it gets over 80C).
  4. Read an MD80C20 temperature sensor. This gave me some trouble because the waterproof version connected by a 30" cable came with no clues about which of the three colored wires corresponded with the pins on the bare MD80... I finally found it: red=3.3V, black=Ground, white=Data. Probably obvious to most Rpi users. Also, I had trouble connecting the 3 wires to the breadboard. The ends of the wires were tinned but only stripped back about 1/8". I stripped another 1/4" back but the wire was too flexible to make a decent connection to either the breadboard or to the female end of a jumper. So I cannibalized wire bits off an LED and soldered them to the flimsy MD80 wires. Voila, it worked.
I'm waiting for motion and humidity sensors. Also getting a larger selection of jumper wires. To keep sane you need a variety of colors and lengths. In addition, I ordered several multi-wire spring-clip connector blocks -- would have saved me some soldering on the MD80.

What next to buy?
  • Rpi camera board: $30
  • A stepper motor: $5 and up
  • A "power tail switch" to switch 110V/500W: $26
  • Controls for turning on garden/farm irrigation pipes.

Wednesday, May 22, 2013

6: Electricity?

My only exposure to electrical theory was 60+ years ago in 10th grade physics. My practical experience did not run to breadboards, jumpers, LEDs (see my previous post), etc. Internet content is great for ease of access but can occasionally be wrong. The breadboard images below make things pretty clear. The left side is less interesting than how the holes are really interconnected underneath.
The bad info I got stated that the vertical outer columns were NOT connected across the gaps that occur every 5 rows. I did some really dumb jumper-ing while I momentarily believed that.
I had not sprung for a DC voltmeter which could easily tested from top to bottom of a column. But then I realized I could make my own:
In around 1956 I bought a cheap soldering iron so I could assemble a Heathkit amplifier. It has been (literally) gathering dust in my workshop since then. The image above shows my crudely soldered voltage tester (cheap LED and matching resistor, pretty useful). This gimmick immediately disproved the false info I mentioned above. The underside breadboard diagram shows that the left and right sides of the board are a) totally separate, b) the outer 2 columns run the length of the board (and could care less which one is positive or negative), and c) the center 5-pin rows are horizontally connected. The red lines I drew on the left breadboard image above are to suggest that it might be cool to connect Pi GPIO pin 1 (3.3V) to the left-most column and GPIO pin 2 (5V) to the "+" column on the right side. I also drew a blue line to the left side minus column (from GPIO pin 6). This I also jumper on over to the "-" side of right edge. Just my way of keeping sane (-ish).

Because of age-related presbyopia I could really use a "large print" version of the breadboard. But that's never going to happen so I keep the magnifying glass close.

Friday, May 10, 2013

5: I have added some gear:
1. a full-sized breadboard
2. some F/M jumper wires
3. some LEDs (with matching resisters) and button switches

I added the GPIO software to my Pi (via the dangerous "sudo apt-get install ..." method, but this time backing everything up).

My first attempt was the obvious "make an LED blink" program. My first four attempts didn't work. Guess why-- nobody told me that LEDs care which wire is positive. Four tries and I never guessed right! Finally got the hint from a Youtube lesson. The longer wire on the LED has to be the positive side. Duh.

I got some button switches too. They work (sort of) with my Python code but not reliably. I've tried testing button depressed, button edge down, button edge up. Also, different sleeps between tests. Not reliable yet.

Here's a confusion: GPIO pin numbering. There are at least 3 schemes. Two are shown below.

If your Python shows:
import RPi.GPIO as GPIO
. . .

You will use actual pin numbers (they aren't numbered on the 26-pin connector, you have to count). Those numbers are in the 2 center columns, above. But if you replace the 2nd line of code above with:

Then you are using the"GPIO" numbers shown in the outer 2 columns. I'm not getting into the third scheme, yet.

In the meanwhile, I've ordered more jumpers (can't get by with M/F) a wide assortment of resisters, plus temperature and motion sensors.

Sunday, May 5, 2013

4: Since my last post:

I tried adding software by the--

  sudo apt-get ...

method. And I learned (again) that doing things as super-user (i.e., "sudo") is inherently dangerous. The last such download (wish I remembered what it was, exactly) corrupted my flash filesystem. I only found out when I rebooted. Anyway, it was back to downloading a new copy of the OS. This time I am doing a better job of backing up the Pi to a folder on my Mac.

When I initialized the system, this time I set up the US keyboard the easy way and added SSH at the same time. Now my Pi sessions go as follows:

1. Power up the Pi.
2. Start SSH from my iMac Terminal app:
      ssh pi@192.168....
3. Mount the Pi "Home Folder" on the iMac.
4. Play with the Pi
5. Copy any new Python code to a backup folder on the iMac. 
6. Shutting down:
      sudo shutdown 1
7. Pull the power plug.

Here's a little Python program that prints the CPU temperature:
import commands
import re

str = commands.getoutput('/opt/vc/bin/vcgencmd measure_temp')

r = re.match(r'.*=(\d+\.\d)', str)
c =
c = float(c)
f = int(( c * 1.8) + 32.0)

print "Pi CPU temp=", f, "F, ", c, "C"
if c >= 80.0:
    print("Don't fry your Pi -- 80C is the max. safe CPU temp!")

My Pi runs at a little over 40C in its plastic case.