Sunday, February 16, 2014

Post 49: Another Problem with the  mpja Breadboard T-connector
(see post 45)

So, since I'd gone to the trouble of identifying the pin-outs, I decided to use the connector. It's a wonder I didn't burn out my Raspberry Pi!
As you can see from the image above, the connections to the breadboard power rails are reversed from every one of the 4 breadboards I own (including the one that came with the T-connector). I (foolishly) assumed that the T plug would connect Ground to Blue and voltage to Red. Nope. It's backwards. So nothing I tried worked. I wasted a couple hours and luckily I didn't harm my Pi.

Friday, February 14, 2014

48: Clone (or back up) your Raspberry Pi SD card
modified 2/7/2018

I've recently bought my 2nd Pi. This led me to try to make a copy of my Pi-1's SD card. I've been backing up that SD card by moving it to an SD reader plugged into my iMac (by USB). There, I used the Terminal "dd" command to make a literal 16gb copy of the card. When I screwed up the card (stupidly changed a GPIO connection while the Pi was powered up and running) I successfully fixed the SD from the iMac back up. But, in this case, I was copying from and to the same SD card.

When I tried to do the same thing to a different 16bg card it didn't work. The 2 cards did not have exactly the same number of data blocks -- off by 1(?).

After trying that a couple useless times, I went looking for something different. And this is it:

This is a different approach.  rpi-clone is a long-ish shell command that runs on the Pi and copies your working SD content to the second card (I moved my USB reader to the Pi).

1. It worked!
2. I didn't have to shutdown the Pi or move its SD card.
3. It was faster than the literal 16gb copy.
4. It can do partial updates to an existing card copy.

Actual rpi-clone command (assuming you named it;

% sudo sh rpi-clone [ -f ] sda

(Assuming that a list (ls command) of /dev/sd* listed "sda")

The only problem I had was that I ran it via the Mac Terminal "ssh" interface. The first time I tried rpi-clone I left it (took 25 minutes) and before I returned ssh had timed out my connection to the Pi -- and that aborted the last question from rpi-clone. The 2nd try, I stuck around.

One further advantage of rpi-clone: The last thing that the command does is unmount the SD copy. But if the copy is for a new Pi system you'll want to make a few changes first. For example: you can change /etc/hostname and /etc/network/interfaces. In another Terminal window you can --

cd /mnt/clone/etc # that's where the new card is mounted
nano hostname # change the name?
nano network/interfaces 


Note all of the above has to be run with sudo. Be careful!

Oh, and congrats to Bill Wilson for writing rpi-clone.

Sunday, February 9, 2014

About the DS18B20 Temperature Sensors

I bought my first one from Adafruit, I followed their wiring plan, and I copied their Python source code. But since the .py program just executes Shell commands I wonder why is Python needed at all? Hers's a .sh file that seems to work just as well:

if [ ! -d /sys/bus/w1/devices ]; then
sudo modprobe w1-gpio
sudo modprobe w1-therm
a=`cat /sys/bus/w1/devices/28num-a/w1_slave` 
b=`expr "$a" : ".*YES.*t=\([0-9][0-9]*\)"`
if [ $len -ge 2 ]; then
f=`expr $b \* 18 / 10000 + 32` # Note: expr only handles integers
echo $f
echo "DS18B20 Read Error"

The above seems to work every time I've tried it. The "28num-a" bit above has to match the unique serial number of your device.

A weakness of the expr command (I wrote the original version in 1975) is that it doesn't do fractional numbers. So instead of--

expr $b \* 1.8 / 1000 + 32

You have to multiply by 18 and divide by 10000 to display Fahrenheit.

The heart of the mystery, though: the Adafruit wiring layout shows GPIO pin 4 connected to the DS's data wire but there is no reference to pin 4 in the code above. Since I want to connect 3 DS18B20s to my Pi, do they each take another pin? Or does the code in "w1-therm" only support a single device?

{Since no one answered my question, I found out for myself: You can read several devices with the modprobe software.}

Another worry: those 2 "modprobe" statements obviously leave something running. You can find it by executing the terminal command "ps -ax" -- and here's the culprit process:

 2980 ?        S     16:05 [w1_bus_master1]

That thing is a relative CPU hog; 16 minutes in about a week. 

Thursday, February 6, 2014

Pi to Human Communication

If you have a Pi set up to monitor sensors then you will want to notify someone when things go (potentially) wrong. Assuming your Pi has Internet access (DSL, cable, cellular 3G/4G hotspot modem) you can program it to send out alerts from the Linux Shell, like so:

echo "Warning: Temp below 35F" | mail -s Temp

SMS (text message):
echo "Warning: Temp below 35F" | mail

To get the text message to work you have to know what carrier serves the phone number. There's a list at--

Note: In terms of speed, both the e-mail and the text got to me in under 60 seconds. But people are probably more alert to texts.

Tuesday, February 4, 2014

Irritation with the mpja breadboard I mentioned (touted?) in the previous post

Here's a photo of the T-connector:
The RED and BLUE notations are all mine. I had to buzz all the pins out to identify them (well, the left side row was guess-able, I suppose). No help from the supplier, though. This isn't the only mystery, though. The cabling is non-obvious, too.
The T-connector end of the ribbon is keyed -- but not the Pi end! Luckily, I tested the circuit all the way to the other end of the ribbon. Maybe you can make out the dim "2" (upside down) on the Pi end (meaning even-numbered pin side). I never would have guessed that cable twist.

"Other than that, how did you like the play, Mrs. Lincoln."