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

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"
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)
if (count of w) is less than 5 then
set w to w & " "
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 :)

No comments:

Post a Comment