Archive for July, 2010


Kill-a-Watt Meter and Computer Power Usage

Thursday, July 29th, 2010

I posted this information earlier in the year on the now defunct Google Buzz, but recently revisited it.

I bought a Kill-a-Watt P4400 power meter to check computer power usage.  You plug appliances into the meter and then plug the meter into the wall. The meter has an LCD display of various statistics. The results:

Computer Power when On (Watts) Power when Off (Watts) Monthly Cost Yearly Cost
Generic Athlon 1.6ghz Desktop 100 5 $8.74 $114
Dell PowerEdge SC1435 2x CPU Dual Core 160 13 $14 $182
SunFire X2100 1x CPU Dual Core 120 8 $10.50 $136
Sun V2 2x CPU Single Core Opteron 155 13 $14 $182
Shuttle 2ghz Athlon 65 5 $5.30 $74

While the cost difference isn’t huge, the lesson here is to size your always on machine for the tasks it needs to do. Additionally, since I bought the Shuttle case used, the cost difference versus the generic desktop case was only about $50, which is easily made up by the energy bill savings. Additionally, the Shuttle case is quieter and takes up less space.
The biggest lesson? Don’t leave 5 computers plugged in all the time even if they’re all off 99% of the time (like leaving a 75W light bulb on permanently!). I remember when I moved in to my current house, there were no fancy electronics plugged in at all; just a few chargers on a power strip which I turned off religiously. The electricity bill was usually less than $15/month. Now, there’s two occupants and I do not turn power strips off and the bill is rarely less than $100.

Energy cost source: http://www.electricity-usage.com/Electricity-Usage-Calculator.aspx

Android Bluetooth

Wednesday, July 28th, 2010

Once the Arduino board had a Bluetooth module attached, it was time to make it talk to another device.  We chose our Nexus Ones– Android 2.2 powered smart phones.  Briefly, prior to Android 2.0, Bluetooth support in the Android OS was really awful and generally not worth bothering with.  Even today, it’s still kind of weird.  Now with 2.2, it seems stable, but there are many programming pitfalls.

Although there are sample applications online to implement Bluetooth, it wasn’t easy and took several days of persistence to get it working reliably.  It’s quite easy to cause the application to lock up or crash.  You’re going to need multiple threads, so you’d better get used to that.  The Bluetooth read() function is blocking, so if you were to try and read using the same thread as your UI, the UI would appear unresponsive.  We wrote the application so that the main thread creates the UI.  This thread then spawns a communication thread which runs independently.

Managing the communications thread can be tricky.  After all sorts of experimentation, we realized that all we really needed were to handle the onResume and onPause events.  onResume fires whenever the phone wakes up (plus a big gotcha: also when the display changes orientation– though luckily you can turn this nuisance off in the manifest.xml).  onPause fires when it goes to sleep.

We set up the application so that onResume it creates the communication thread.  onPause, it stops it (both to conserve battery and because Android might shut the Bluetooth radio off on its own).

The communication thread searches all paired devices for the device with the name of our bluetooth module.  It gets its MAC address and then connects to it.  It then goes into a loop that reads data and uses inter thread to communication to send a string back to the UI thread.

The UI thread has a handler for accepting messages.  It parses the string it receives and updates the UI.

The communication thread also has a send() function which the buttons in the UI are programmed to use.

The last gotcha was that pairing & connection in Android can be weird.  Originally, we’d hard coded a MAC address into the program, and when the comm thread attempted to connect, the pair password box would sometimes appear, other times it would pop up under our application.  The only way to tell it was there was to look in the notification tray.  This wasted hours and hours of our time until we figured out the solution:  if the device isn’t paired correct already, forward the user to the built in Android OS Bluetooth settings screen with a pop up warning message to go pair from that screen.  When they’re done and they hit the back button, the application searches the list of paired devices again; if it finds it, it continues onwards.