Android Garden Monitor

Overview

One of the coolest things announced at this year’s Google I/O was the Android Open Accessory Kit, which allows Android devices to interact with accessories over USB. As an attendee, I received the Arduino-based ADK DemoKit board, which I’ve used to build an app to monitor my Aerogarden.

Hardware

Arduino and Breadboard

The garden monitor project was built with the following components:

  • Arduino-based Open Accessory Kit
  • Breadboard
  • LM34DZ temperature sensor
  • HS1101 humidity sensor
  • 0.5″ force sensing resistor
  • Analog servo

The force sensing resistor is mounted below the Aerogarden’s water tank to measure the weight of the water, and the servo is used to open and close the tank door.

Software

Nexus One running the Garden Monitor app

Arduino

The Arduino firmware reads the values from the temperature, humidity, and force sensors and sends them to the attached Android device over USB using the Open Accessory protocol. It also accepts commands over USB from the Android app to open and close the door.

Android

The Android app reads the sensor data from the Arduino and broadcasts them over the wifi network using xPL so they can be monitored by MisterHouse, which can alert me via email and text-to-speech when the water level is low. When the water level is below 20%, the app signals the Arduino to open the door as a visual indicator that the tank needs to be refilled. After the tank is filled, the app automatically closes the door again. The app also snaps a photo every hour, which I’ve used to create the time lapse video below.

Source

The source code for the Arduino sketch and the Android app are available on github.

Time Lapse

This video was created by combining the hourly snapshots taken by the Nexus One using ffmpeg and then edited in iMovie ’09.

Writing an Android Sync Provider: Part 2

One of the great new user-facing features of Android 2.0 is the is the new Facebook app, which brings your Facebook contacts and statuses into your Android contacts database:

So, how exactly does my Nexus One know that Chris is excited about the upcoming launch of his new mobile apps? The answer is a Contacts sync provider in the Facebook app. Read on to learn how to create your own!

Writing an Android Sync Provider: Part 1

One of the highlights of the Android 2.0 SDK is that you can write custom sync providers to integrate with the system contacts, calendars, etc. The only problem is that there’s very little documentation on how it all fits together. And worse, if you mess up in certain places, the Android system will crash and reboot! Always up for a challenge, I’ve navigated through the sparse documentation, vague mailing list posts, and the Android source code itself to build a sync provider for our Last.fm app. Want to know how to build your own? Read on!

Lua 5.0 in DreamZZT

ZZT-OOP is fine for simple scripts, but it’s very dated and not very powerful. Starting with DreamZZT 3.2, another scripting language will be available in addition to ZZT-OOP: Lua 5.0. Lua supports functions, variables, and file access, among other things.

Creating a Lua object using a 3rd party editor is as simple as creating a ZZT-OOP object that executes “#become lua”. DreamZZT will then run everything past that line as a Lua script instead of ZZT-OOP. Of course, if DreamZZT ever gets a text editor, or if someone adds the Lua object type to KevEdit, you’ll be able to create Lua objects directly.

Here’s a simple example of using Lua from within DreamZZT:

@Luatest
#become lua
function main()
wait_for_message("touch")
set_msg("Here, the player, have some health")
zzt.status.give_health(20)
end

And a more advanced example that handles more than one message:

@Luatest
#become lua
function main()
local msg = nil
local them = nil
while true do
while (msg == nil) do
coroutine.yield()
them,msg = pop_message(me)
end
if(msg == "shot") then
set_msg("Ouch! I was shot by a " .. them.name .. "!")
end
if(msg == "touch") then
set_msg("That's my purse! I don't know you!")
end
end
end

Note that you must call coroutine.yield() inside your loop to pass control from your script back to the game engine. The set_msg(), move() and wait_for_message() functions automatically call coroutine.yield() for you. Also note that the Lua implementation is using a message queue, so you don’t have to worry about locking and unlocking your objects like you do with ZZT-OOP.

For a more complex example, I’ve rewritten the DremZZT Tutorial in Lua, which you can view here. You can compare it to the original ZZT-OOP code to get an idea of what the new functions do. You’ll also notice that Lua has full access to the TUIWindow class, so you’ll be able to use text entry fields, check boxes, etc. from inside your games.

The Lua interpreter and updated tutorial are in the svn trunk, however saved games containing Lua objects created on PowerPC Macs are not compatible with other platforms and vice versa, due to how that CPU stores data. This issue will be resolved eventually, but right now just don’t transfer saves between PowerPC Macs and the rest of the world 🙂 For information on checking out and building DreamZZT from svn, see Building DreamZZT from Source.

MythTV Upcoming Recordings 1.0

Introducing the MythTV Upcoming Recordings widget:

This widget will connect to your MythTV backend server and display the list of upcoming scheduled recordings. It requires a MythTV backend server configured to accept network connections.

You csn download it from the MythTV Upcoming Recordings page.