Wednesday, April 11, 2012

EMSL Alpha Clock and XTension

I finished this terrific kit a while ago and wrote a blog post about connecting it’s serial port to an xBee radio. I meant to post code snippets and instructions but got mired up after using some of the other digital IO on the xbee for LED’s I evidently hosed something up on the breakout board. I’ve got it sorted out again so here’s the rest.

This is the wonderful Alpha Clock 5 from evilmadscience.com:


the fun part about those gigantic LED displays is that they are alpha numeric, and the clock has a serial port to which you can send text.


You could connect to this in many ways, bit I chose to use an xBee radio since I am working on support for them in XTension at the moment. The serial ports on the xBee as well as control of the IO are available to apple script in XTension and makes for easy wireless displays. The board I originally used was the plain one from sparkfun, no components other than the sockets for the xBee that bring them out to easier to manage solder pads. I must have overheated the pin to a socket or filled one with solder or shorted them internally or something as it stopped delivering any power at all to the xBee at some point while I was adding the extra display LEDs. I have now replaced it with an xBee breakout from adafruit that is working wonderfully. It also properly handles level shifting the serial port which is at 3v level from the xBee and 5v level on the clock board. I’m not sure if this is really all that important or not, SOME of the xBee documentation talks about the serial lines being 5v tolerant, but others demand that it’s vital. In any case I’ve got that working now and it has an on board 3v regulator so I was able to simplify the internal wiring and reduce some of the extra clutter of wires. (the clock throughout all this mucking about with the xBee continued to tell the time wonderfully and accurately ;)



There is the xBee on it’s new adafruit breakout board. For the serial to send messages to the clock only 3 connections are necessary. 5v, gnd and tx from the xBee connected to rx on the clock. Extra solder points for all those things are already on the clock board making it even easier.


the red black and blue wires are all thats necessary to turn it into a remote display to XTension. But now you’ve got all these unused pins on the xBee that are just going to waste! I plan to use this in the bedroom for a subtle display of alarm or other status during the night while not being too obtrusive. The clock already displays zone alarm info for me from XTension, but I wanted some bright LED’s to get my attention to various things. I added 3 bright colored led’s and one candle flicker led so that I could remote control an electric candle next to the clock just for fun ;)


The LED’s were just solder art, no boards or anything, grounds of the 3 extra bright ones are tied together and the Vcc sides have resisters under the heatshrink for the 3.3 volts that comes out of the xBee. The larger flicker led is on a long twisted pair of wire wrap wire so that it can more easily be snuck up to the candle I plan to drop it into.


Once back together I just mounted the xBee to the bottom of the case where it is quite happy to receive signals from the computer upstairs.


The LED’s I just hot glued to the back center of the case so that they would not be visible but would wall wash the wall when turned on.


There’s the clock where it lives on a shelf in my bedroom displaying an alarm zone message, and you can see the little wire running up to the candle. 


The RED alert LED while displaying the time.


The green LED and the candle flicker LED are on in this pic.

In XTension the serial port for each xBee radio is brought out to a local TCP port on the computer to which anything can connect. For myself I’m using applescripts inside of XTension that can be run in response to motion or alarm zone changes. The clock is quite capable of displaying scrolling messages if you handle that on the sender side, but I’m not bothering with that yet, sitting there while a long message scrolls across is not really conducive to getting a quick but of info about activity around the house. Though I may do something soon with a button that causes it to show outdoor temperature and perhaps scroll a short display of weather forecast.

In XTension I created a DIY interface to connect to the serial port and give me access to send data to the clock. The DIY interface is called “bedroom clock” so that I can talk to it by name elsewhere. In my Attachments Script I created some handlers to call to send messages or clear the clock. Here’s the snippet for sending a message to the clock and then having it clear after a certain amount of time:

on WriteToBedroomClock(TheMessage, TheTimeout)
--send the command init string
send data bytes {"&hFF"} interface "bedroom clock"
set s to PadClockString(TheMessage) & "     "
send data "A0" interface "bedroom clock"
send data s interface "bedroom clock"
try
suspend event “Clear Bedroom Clock" for TheTimeout
on error
execute script “Clear Bedroom Clock" in TheTimeout
end try
end WriteToBedroomClock



on PadClockString(TheString)
set w to (TheString as string)
repeat
if (count of w) is less than 5 then
set w to w & " "
else
return w
end if
end repeat
end PadClockString

You can make the call to WriteToBedroomClock( “ALARM”, 5) from anywhere else in the program or externally from anything else via a tell app block. This does not validate that only 5 characters are sent, but if fewer are sent it properly pads them out, the second parameter is the timeout or how long to show the message before it returns to showing the time.

You’ll also need to create a global script called “Clear Bedroom Clock” for this to call after the timeout period. Something like this:

send data bytes {"&hff"} interface "bedroom clock"
send data "MT          " interface "bedroom clock"


thats all thats necessary to make the Alpha Clock display messages, but it has other features as well. Here is some rather odd code to set the time from AppleScript, you have to get a unix date number which turns out to be harder in AppleScript than I imagined. There is no simple way to get the underlying date as a raw number! I searched around until I found someone who had done so by coercing it first through miles and then to a number. Go figure.

  set theNumber to (((current date) - (date ("1/1/1970")) - (time to GMT)) - (4 * hours)) as miles as string


  write log "unix date is: " & theNumber
  send data bytes {"&hFF"} interface "bedroom clock"
  send data "ST" & theNumber interface "bedroom clock"
  write log "bedroom time set"

Create that in a global script and run it whenever necessary, I run it nightly but the clock is very accurate thanks to that chronodot. Notice the end of that first line in that script -(4 * hours) I had to add as that was how many hours off the time was after running the script. I think that (time to GMT) may not be working correctly either because my computer has something setup goofy or perhaps it just doesn’t work I dont know but be prepared to change that as necessary to make it set the proper time in your zone.

More info on the serial protocol for talking to the alpha clock 5 is available on the evil mad science wiki.

Next project will be connecting up this touch sensor so that a gentle brush to the top of the clock displays temperature and weather info :)



Friday, March 16, 2012

arduino prop dropper for Halloween

Already planning for halloween around our house! Ben has his eyes set on a “prop dropper” which is 2 servos and an arduino. Haven’t decided yet how we’re going to control it, PIR or remote control or whatever, but it’s still been some fun. After the first work session on it we’ve got it basically running and now it needs a mounting bracket, a better spooky thing to actually drop and a remote.


Thursday, March 8, 2012

metering the smart meter, part: the third

Well... so far it doesn’t work ;) The IR receiver that I thought worked so well, and does SOMETIMES drops pulses other times and sends multiple pulses still other times completely messing up the reading.  I tried some filtering of it to sane levels in the arduino it’s connected to but that just wasn’t leading to anything helpful.

And after I went to all that trouble to make a nice sensor out of it too.

The next experiment was just a phototransistor which initially appeared not to work at all, but changing it from a digital pin to an analog pin seems to have solved the problem. I can definitely pick up the pulse sampling analog in a loop and it’s quite a long pulse too it seems. 

So it’s back to the drawing board to build a new sensor out of the phototransistor and then some significant software updates once that is working. 

I will post again when I’ve got it working better!

How NOT to run the 5.1 update on your iPhone...

Last night I started downloading the iOS 5.1 update. After seeing that the download alone would take an hour and a half I decided to go to bed. I disconnected the iPhone and left the download running in the background. All innocent I honestly believed that it would just save the file and let me run the update in the morning. An hour and a half later my iPhone waking up on my bedside table woke me up as it shone into the darkness, it had switched to recovery mode even without a USB connection to the computer. I wasn’t aware there was a remote command to put it into recovery mode over the air. Since it was not able to apply the update over the air it seems rather useless, and rather frustrating as I didn’t have a phone.

Once you’re in recovery mode there is no option that isn’t a hack but to restore the phone. Great, more hours wasted watching it reload and restore and put everything back. So digging into the internet I refreshed my memory on the double secret sequence of holding buttons in to get into and out of recovery mode but to no avail. The phone refused to go back to normal. I resorted to the jailbreak tool “tinyumbrella” which has buttons for “enter recovery” and “exit recovery” and it worked. Selected my phone from the list and clicked exit recovery and it came right back to life. I returned to iTunes with the intention of running the update. But the update failed...


“The iPhone could not be updated. This device isn’t eligible for the requested build.” Well.. that’s frustrating, lets start iTunes again and see...


So iTunes says both, yes, it is, and no it isn’t. So back to teh intertubes to read. I WAS behind a version of iTunes, so I ran that update. But even more importantly it turns out that upon quit, TinyUmbrella redirects a specific apple host on your machine. This is necessary if you are jailbreaking as it keeps iTunes from overwriting your new settings on the jailbroken iPhone. This was by default on, which makes sense I suppose if the tool is mostly used for jailbreaking, but my iPhone is not jailbroken. It’s in the advanced tab and is called “redirect hosts to Cydia upon quit” or something similar. After re-running tinyumbrella and turning that off and updating iTunes my phone is now happily running the update.

None of this would have been necessary if it had just not remotely put the iPhone into recovery mode in the middle of the night. At this moment it seems to be stuck at "waiting for iPhone” and seems to have now jumped to “verifying updated iPhone software” without ever actually loading anything. That doesn’t bode well. Oo, now we’ve gone back to “updating iPhone software” and it’s actually running now! The little progress bar on the phone is creeping across ever so slowly. Now iTunes is back to the Verifying message but the phone is still only about half way done with it’s little progress bar, but this is more how I remember things running. I am now more confident that it will complete and that things will go back to normal.

This blog post serves no purpose but for my own documentation of the issue so that a year from now when it does it again I’ll remember what I did to get it sorted out. Mostly I’m just venting my frustration. If you use tinyumbrella to get out of recovery mode though remember to turn off that redirect or iTunes will refuse to do anything with your phone after that.


OK, now wasn’t there something else I was supposed to accomplish today?



Friday, March 2, 2012

Metering the Smart Meter. Part: The Second

Just moments after “they” installed my new Smart Meter it became necessary to figure out how to link it into the Home Automation system. Previously I tested the IR sensor from SparkFun I had laying around to discover that it would indeed pick up the pulses. Once that was working I needed to build a sensor that I could attach to the meter housing that would survive out in the weather, not damage the meter, be easily removed if they needed to access it and not look like someone was fiddling with the meter. I decided to pot the sensor into a short length of aluminum channel.


This channel is available at every hardware and home center type place. I used this same stuff previously as the heat sink for the LED under cabinet lights I built so I had some laying around. It’s very soft and cuts and drills easily though you will have to file the edges a bit to get the sharp bits off.


The sensor is quite small, but I needed the extra space in the channel for filling to make it weather resistant and just to have some surface area to attach the mounting stuff to the meter. In that picture you can see the pins sticking out the back. Those come with it but aren’t attached when you get it. They are for pressing into a breadboard to make prototyping easier but I removed then and attached some nice stranded wire for the final build.


3 wires run to the sensor, +5v, ground and the signal output. Since the switching of the 5v is done on this board it’s possible to run the output from this much further than from just a naked IR sensor without picking up interference or without too much wire resistance getting in the way. This sensor is the earlier version of this one from spark fun. This is the easiest since you dont have to do more soldering than connect the wires, but if you know what you’re doing any IR photo transistor could probably be made to work. In the above picture it’s getting a nice dip in epoxy to seal it away from the elements.


Here it is mounted (glued ;) inside the channel. I carried the wires backwards across the back of the board so that they would be encased in the epoxy for a longer distance than if I ran them out the obvious side. 


Put a bit of tape around the 2 open sides and filled the whole thing with hot glue. Thats probably excessive and there is some danger of the glue heating up in the sun and slumping out of the thing and making a mess. I’ve used hot glue to do this here many times before and it’s never been a problem even here in the “deep south” but take your own situation into account.

  

And finally all finished and ready for mounting to the meter. I wonder if this isn’t the right sensor as it’s keyed to receive in the frequency range that IR remotes use and I dont know if the output of the LED on the meter is anything other than a strictly on/off pulse. I can’t find specific documentation on it and people are using all sorts of things to pick it up. But I would think this wouldn’t work at all if it wasn’t correct, the whole point of the module is to filter out un-mondulated or incorrectly modulated IR sources. It’s entirely possible though that this isn’t as sensitive as it could be with a proper receiver. If anybody sees specific manufacturer info about the kind of IR or it’s modulation I’d love a note about it. This is pretty picky about placement, it only works if it’s right over the LED on the meter and even small diversions make it not sense it. I’ll be using some outdoor stable velcro like stuff on either side of the hole there to attach it to the meter and be able to re-position it to get it just right. Next time software and install.

Wednesday, February 29, 2012

Metering The Smart Meter, part: the first

A subcontractor of the local electric company was banging around behind my house the other day installing a smart meter. Someday the electric company might produce a web page where I can go to look at my electric usage, but it seems that most or all of the models being rolled out in the US provide an IR led on them that pulses with each interval of electric usage. So you can count them in any given time period to measure usage and measure the time between them for an instantaneous load measurement. There are many ways to measure power load, XTension supports 2 different clamp on current meters that need to be installed inside your breaker panel but if you’re not comfortable working inside your panel or if you don’t wish to hire an electrician to do the work then you’re out of luck. As time goes on though these meters are being rolled out to practically everybody and DIY reading of these pulses doesn’t look like it’s going to be that bad.

This is just proof of concept that I know how to read them, not yet a finished project. Just flashing an LED on the sensor when I receive a pulse with an old Arduino and an IR remote receiver from SparkFun.com.



There are many other similar projects out there you can google for and some good arduino source code examples. Ultimately this will get connected to an xBee for data transmission up to XTension. The next step will be some kind of bracket/case to hold the sensor against the electric meter without looking too frightening to any meter reader that may be back out at any time in the future.

I’m pretty sure that someone will be back out, the meter isn’t really installed straight, I dont know why it should be bent up ever so slightly,but it doesn’t give me great confidence that the connections are solid inside.  I”m going to call the electric company and ask them to verify the install later on today as a matter of fact.

(part 2: making the sensor)

Friday, February 10, 2012

Wiznet Configuration Update

(Updated 6/10/12: see below)

While updating the MaxSonar driver in XTension to support connections to TCP/Serial adaptors I discovered an important error in the last version of the Wiznet Configurator for Macintosh. The documentation available on the web of the protocol for talking to these devices is actually incorrect in the settings for the client/mixed/server mode byte. If you’re thinking of working on one of these yourself you’ll want to know that the proper values are 0=client, 1=mixed and 2=server. The documentation shows server and mixed swapped which causes all the reconnection problems that some people have mentioned.

The download links to the updated versions are below.

Wiznet makes an excellent ethernet to serial board that is inexpensive and is fully supported by XTension unfortunately they never had a Mac version of their configuration utility that lets you give it an address and setup the serial port.

I noticed yesterday that they had published the specs for talking to the boards making it possible for me to throw a configuration utility for the Mac together. I could theoretically compile it for Linux and Windows too if anybody is interested let me know, I just dont have a machine handy for testing those targets so I haven't done so yet.

The program seems to work and implements all of the available fields though some of them appear to be different in the version of the firmware that I've got than what is documented. Indeed in the documentation even the length of the data packets is wrong so i'm not sure the things i haven't tested actually work.

To use it plugin a 5v power supply and ethernet to your wiznet board. It will assign itself an address or take one from your DHCP server depending on. To find it run the software and all wiznet boards found will be displayed. Double click one in the list to edit it.


To use one with XTension it needs a static IP address and be in Server mode. Then setup the serial port for whatever settings are needed for the particular device. This should work with CM11's and W800's and Weeder chains and just about every other device in XTension that supports a remote TCP connection instead of a local serial port.


I was unable to make the direct connection to the device work, so the configuration is returned via a UDP broadcast. What this will mean for having multiple devices on your local network I dont know yet, I only have the one but i've just ordered some more, and some with multiple ports to experiment with further.


This is released as freeware and AS IS. Let me know if it gives you any trouble and please feel free to make a small donation via paypal to james@sentman.com if it turns out to be useful to you.


(update: 2/8/11 added the linux compile. I haven't even tried to run it but it might help someone out, please let me know if anybody finds it useful)

(update: 2/10/12 now at version 1 because of fixes to server/client/mixed setting and the proper setting of the serial debug mode flag which is 1 for off and 0 for on, go figure)

(update: 6/10/12 new version fixes UDP/TCP setting bug please visit: here for new version)


wiznet devices can be purchased from Sparkfun as well as Saelig Electronics
.code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; max-height: 200px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; }