Monday, July 21, 2014

63: Resistor Hindsight

When I realized that I'd need a variety of resistor values I bought a cheap assortment from Adafruit (that no longer appears in their on-line catalog). Here's a pic of that mess:
The only labeling that you get is the slip of paper listing the values by the number of each type in the assortment. Over time, I have penciled in the ohms numbers for ones that I looked up using the widget I installed on my Mac.

I have no idea how many hours I've spent peering though a magnifying glass trying to read the tiny colored bands. Anyway, I could have bought smarter.

Here's a possibility (haven't tried it, but labeled and for $8?):

Thursday, July 17, 2014

62: Wiring an Opto-isolated Relay

I have 3 relay devices, an 8-switch and 2 2-switches. Here's an image of my latest from

Note the convenient "ISO" labels

The picture shows that the jumpers on the lower pins have been removed. Anyway, I provide this because I've seen confusing wiring diagrams on the 'Net and some incorrect Fritzings, as well.

Tuesday, July 15, 2014

61: Philosophical thoughts about the gpio command

I think it's safe to say that the basic philosophy of UNIX (Linux) shell commands is that they do not maintain "state" information between one execution and another. (Info maintained by the shell while you are logged in doesn't break this rule -- your shell only exits when you log out). But gpio obviously ignores this convention. In my post #60 I gave these 2 examples:

$ gpio -g mode 7 in  # pin 7 is connected to an input
. . .
$ gpio -g read 7     # get a 0 or 1 from pin 7

Before I wrote my blog entry, I actually executed those 2 lines on my Pi. Then I quit SSH from my Mac (about 2 weeks ago). The Pi had not been rebooted since, so I logged in just now and repeated the gpio-read command. Surprise, surprise. It still worked (i.e., it remembered that pin 7 was "input").

A "sudo reboot" finally erased that rather dangerous information. I don't like this -- especially since gpio is a "setuid root" command. This is ugly and unnecessary. BTW: after the reboot the gpio-read command did not produce an error message -- it always  returned "1".

Advice? Better to operate relays in Python or C.


Tuesday, July 1, 2014

60: Water Sensor

I wanted an alarm on my basement sump. My AC and de-humidifier drain into the sump which is usually seeps away on its own. But then it might not. Anyway, I checked the web and found--

I'm not much good at interpreting wiring diagrams, but my 2nd try worked. Here transcribed to Fritzing.

A couple of notes: the 2 resistors (L to R) are 1K and 100K (in case the wires are shorted). Also, my first try didn't sense water: I had only stripped about 1/4" of the 22 gauge wire and the space between was also about 1/4". So I stripped back to bare another 1/4" and taped the copper ends only 1mm apart. Then it worked. 
At first I tested with an actual glass of water
but a little spit on my finger worked as well.
Note: that copper has started to tarnish within a day. 
How long before corrosion connects the wires?

The programming can be done in Linux shell.

   gpio -g mode 7 in  # BCM # 7 is my water sensing input

   gpio -g read 7     # "0" == dry, "1" == wet

And the "-g" option means that you are using BCM pin numbering.

Here's a way-too-simple shell program:

gpio -g mode 7 in  # BCM pin 7 is INPUT
if [ $? -ne 0 ]
    echo Cannot assign pin 7
exit 1

while true
    Water=`gpio -g read 7`
    if [ $Water -eq 1 ]
        sleep 5 # might be a false reading
        Water=`gpio -g read 7`
        if [ $Water -eq 1 ] # 2nd wet reading
            echo "Send dated email and/or text msg!"
            sleep 3000 # sleep a long time / don't nag
        sleep 300 # or some such