I just finished prototype work on a device to display the power usage in real time. I took an Arduino, Wishield, serial display and some LEDs and cobbled them together and added a ton of code. This device interrogates my power monitor and puts the value up on the LCD display. It also forwards the data to Pachube to take the load off my laptop and returns it to its real purpose, surfing the web. I always wanted an accurate clock so I hit the NIST servers and get the time response back and put it up on the second line of my display. Now I have a clock to set the rest of the house up with. Then, because it would be fun, I added a three color LED and code to go from green to red to give an immediate visual indication of the relative power level.
Here it is with a green indicator:
May 19, 2011: I had problems with the WiShield and AsyncLabs has stopped producing them. Shucks, but fortunately I have already implemented a couple of devices with XBee communications. Naturally, I went straight for the XBee craft box and implemented an XBee solution for the Power Display. The ability to update my Pachube feed was already incorporated in the House Controller and time is provided by my House Clock, so who needs the internet?
Since the start of this project I have learned a lot and discovered a bunch of shortcuts and techniques. The TimeAlarm library that is not mentioned or used very much is especially useful. Those things that take a few seconds (or hours) to do can be set up and checked on with timers and alarms. For example, to blink an LED, turn it on and then set a timer for a second from now to turn it off. One can update a display with a recurring timer set for 5 seconds to update a display and send messages every 30 seconds to update data. Just set the timer, write the call back routine and away you go. No counting milliseconds or confusing code wrapped around counters, it just works the way you would expect it to. You have the benefit of being able to set an alarm a month away if you want. So, the new code for the Power Display relies heavily on the alarms. I also rely heavily on NewSoftSerial. This code just isn't properly understood and used. I still don't know all the things I can do with it, but I have my XBee connected to a software serial port as well as the serial LCD display. They work great.
I also discovered tabs in the Arduino IDE. Yes, I knew they were there, but it seemed like an unnecessary complication when I was writing code. Then, when working on the House Controller, the script got so long I couldn't find things, I added a tab. Then another one, etc. I can separate sections nicely and switch from one to the other when chasing bugs. So, the Power Display uses tabs, that's why there are two sections of code below; one for the main section and one for XBee handling.
The new sketch is below and I'm keeping the old one above both for a comparison and because it has some cool stuff in it regarding Wifi updates to Pachube, overcoming weak network problems and such. I like the new XBee enabled Power Display a lot more and I can display the inside and outside temperature using the various sensors around the house. I repurposed the LEDs that used to indicate ethernet activity to report the incoming data from the XBee network. The top LED shows a power level packet, the middle a time packet and the bottom one a packet from the House Controller. There were a few reasons for this. There needs to be something to show activity to let you know it's alive. Troubleshooting. And I had the darn things mounted and taking them out would leave holes!
Update Sept 10, 2011: I found out that NewsoftSerial uses interrupts and that conflicts with the led indicator that goes from red to green depending on usage. It wasn't much of a problem, but I wanted to redo that code anyway since I wasn't sure I had done it correctly. I used the map() function to calculate the values and moved one of the XBee pins. Works nicely now; at least, until the next bug or change. The newest sketch is shown below