Monday, October 22, 2012

Don't Try This at Home

It isn't dangerous, or anything, mostly just dumb. I wanted a way to know my garage got shut, after I left. Sometimes things happen, and the door doesn't shut all the way, maybe something fell while it was closing, or maybe a cat ran in or out. The optical sensors pick it up, and think it is a kid, so it reverses. I didn't always wait for the door to close, before driving away, then two blocks away, I wonder, did it close.

I used to be really interested in home automation. My previous house had most of the lights controlled by X-10. I had a Unix computer as the hub, allowing a bridge from the X10 to cron jobs, other sensors, and sprinkler controllers. I could be out on my deck, and press a button on the X-10 remote to start a sprinkler. I could turn off the sprinklers by pressing a code on the phone. The Unix machine was a Sun 3/110, mostly because it had a VME serial board, allowing 10 serial ports. The bedroom had a light that would start out low, and get brighter minute by minute, for my morning wake up. It was fun, and I tried to sell this stuff for a while.

My  Plan

I know Craftsman has a garage door opener that will talk to your smart phone and let you know the state of the door. I thought, maybe it was an add on to any craftsman or other garage door, but it wasn't so. It is only available with the specific assure link models. Thinking what I would pay for such a thing, maybe I'd be willing to go $60. The AssureLink also has an annual fee.

I thought if there was a simple board, that had some GPIO, and a WiFi link, for about $50 that would be perfect. I thought maybe there would be some ARM or Pic chip based board that would be perfect. I couldn't find one, not standalone.

To get the message to a smart phone, I thought I'd be able to use one of the free email systems, maybe use an address like or something. The smart phone would be able to subscribe to that address, and I'd know the state of the door. When the door changed states, an email would be sent out.

I asked the DPRG group about such a plan, and got a few ideas. Folks offered suggestions, but eventually what I did find was a Chumby clone, the Best Buy branded Insignia Infocast, on eBay for about $35.

The process

I got on eBay, and someone had an actual Chumby, for under $20. A closer look showed it came without a power supply. Well, it is open source hardware and software, what can be so hard about getting a power supply for it. I bid on it. Then I started looking for a power supply. Ooops, the official Chumby power supplies are $15-20 on eBay. So much for saving money, I guess I don't need the official power supply, I can use the bench supply until I can source something else. hmmmmm.....

Ok, I am still under $50, let me look around. Sure enough, I found an Insignia Infocast for about $30 so I ordered it. The chumby came, and I messed with it. Dang, my simple power supply didn't have enough current. The diagram says 2.5A, wow! This isn't a green project anymore (that is a few watts). Finally the Infocast showed up with it's power supply. Cool it works for both the Chumby and the infocast.

My kids then stole it. If you don't know what the chumby is, it is pretty cool. A little 3.5 inch LCD touch screen (resistive), and ARM processor (400MHz or something). It is Linux based, and uses webkit for the Gui. You need to be registered to get apps are for it. There are some apps that come with it, including radios both software (IE Pandora) and a true FM receiver.  Most of the inside of the case is dedicated to giving the little speaker sound good! It isn't bad, and would make an excellent bedroom alarm clock.  The kids loved the radio, I didn't try to explain Pandora or any of that back.

Eventually I was able to steal it back. I kind like it, using it for a radio, and I could see it useful for other stuff, so I didn't want to break it.

A little work with the soldering iron, and I got a ribbon cable connected to the GPIO port. I didn't think a connector would fit. The main LCD cable goes right across the GPIO port (connector for the LCD ribbon is the upper right corner).

I used to solder ribbon cables all the time. I did a bunch of keyboards when I had the old Xerox 820, and the serial cables before I found the press on ones, so I got the technique. How about this:

I thought, I'd keep things simple. I knew to control a switch, I needed ground, thinking that the GPIO pin would float high, and then I thought I would help the pin float high with a pull up. The schematic ended up being something like:
The control pin is that middle pin D3, the one across from the GND, keeping the wiring simple. +3V is on the end. I got a magnetic reed switch, like used for alarms for the switch. The magnet was stuck to the side of the door.

The Software

 I was surprised, someone said just use GCC. Nothing to it, right, I use it everyday, there are instructions to download gcc and program the chumby natively. It didn't work, not sure if the chumby folks gave up on it, or I did it wrong. I noticed there was a perl interpreter included. Why not, this won't be very complicated, read a single pin, when the state changes.

I used regutils command to read the pin. And sendmail to send the mail out. It isn't fancy, or efficient, just something that will run in the background, tests the one pin once a second. here is the code:

#  setup the chumby for reading, and read pin3.
#  tgb 10-20-12

## setup IO
`regutil -w HW_PINCTRL_MUXSEL0_SET=0x00000003`;

my $curVal="";
my $newVal="";
my $results;
my $ccmp;
my $val;

while (true) {
    $result = `regutil -r HW_PINCTRL_DIN0`;
    $result =~ m/Value at.*: (.*)/i;
    $ccmp = $1;
    $val = hex $ccmp;

    print " CMP 00 ".$ccmp." 11 $val ";

    if ($val & 0x08) {
    $newVal = "CLOSED";
    } else {
    $newVal =  "OPEN";

    print "$newVal\r";
    if ($newVal ne $curVal) {
    $curVal = $newVal;
    sleep 1;

sub sendmsg
    my $msg = shift;

    #sendmail -f  -S -au senderusername -ap senderpassword < mail.txt

    open MAILFILE,"> /tmp/mail.txt";
    print MAILFILE "from:\n";
    print MAILFILE "subject: garagedoor $msg\n";
    print MAILFILE "Garage is $msg\n";
    close MAILFILE;

    `sendmail yourgarage\ -f ""  -S < /tmp/mail.txt`

Why did I do this

Which part, do the actual project? Well that I discussed already. Wanted to know the state of my garage door. How about, why publish it. Well, I needed to show folks I actually am able to accomplish something. Yes this works, I finally completed something. Once I get around to collecting all the parts I am able to make it work.

What was dumb? Well 2.5A for a silly monitor system. It is much better than the silly Sun 3/110. It isn't doing X-10, or anything, but it doesn't need to. I still have a radio and other uses in the garage for it. Probably no one else will use it, but maybe it will inspire someone to do something similar.

Good Luck

No comments:

Post a Comment