The Electric Imp is no Whimp!

Now this is a cute little devil. A wifi enabled micro controller in an SD package, with onboard support for various digital I/O. First I didn't quite get it, but after 10 minutes pondering I had an Edison moment and immediately ordered two more to toy with.

Electric imp

Bring Wifi to Everything is the motto and with the imp it's easy to do so. Just create an account on electricimp.com, put the imp in a break-out board for development (or a future ready-made thing that supports it), and power it up. First time you need to supply wifi login information and this is done with an as cute as clever solution; an iOS or Android app transfers the login information by blinking it's screen for a light sensor in the imp. As soon as it has the correct info, it will connect to the cloud service, update itself to latest firmware and pair with your account. Very neat!

To program it you use the web based applications at electricimp.com. Basically, you write one program for each imp, deploy it on the hardware and optionally connects the input and output from the imp to ready-made software modules that electric imp provides.

The system is still in early stage and there are not that many ready-made software modules yet. But it's easy to write your own software and the chosen language for the imp is Squirrel, which seems an excellent choice. It is powerful and shouldn't be hard to learn if you have some knowledge of C or C++.

# First project!

As always, I use my summer house as an excuse to test new things and I want to use the imp for remotely controlling the heating system so I can arrive to a warm and cosy cottage. The imp should enable remote control through a RESTful web service, and it shall log temperature and humidity to Cosm, or possibly to a database.

The heating control only needs an open output pin that can sink/short circuit a loop in the thermostat that talks with the radiators. The code for this is very simple, I wrote this class:

class SwitchInput extends InputPort {
    name = "Heating switch";
    type = "0 or 1";

    constructor() {
        base.constructor();
    
        // Configure pin 1 as an open drain output with internal pull up
        hardware.pin1.configure(DIGITAL_OUT_OD_PULLUP);
    }
 
    function set(value) {
        // Reflect state to the value = 1 should pull output low,
        // with switches radiators from "away" to "at home" mode. 
        hardware.pin1.write(value == 1 ? 0 : 1);
        server.show(value);
    }
}
~~~

Plus a few lines for instantiating the class and get the imp going. This defines an input to the imp and using the so called "planner" on electricimp.com I connected the input to a module for http. The module provides a unique URL over https for POSTing a switch value to the imp. When I have my sensor in place an output from the imp will be connected to [Cosm](http://cosm.com) for data logging. This is what the complete "plan" for  this imp will be:

![plan](https://dl.dropbox.com/u/2932762/images/planner.png)

The planner makes it drop-dead easy to connect your imp and it kindly reminds you to provide all needed information. In this case I haven't provided the API keys to Cosm yet.

My first idea was that temperature and humidity measurement should be done with an [RHT03 element](https://www.sparkfun.com/products/10167) which outputs readings with a single pin digital interface. It's a low cost device, easy to integrate, but it turned out that the imp is too slow for handling the sensor's digital interface. At least with the current implementation to sample input pins. So I scrapped that idea and will use an I2C-connected sensor instead. The imp has inbuilt support for I2C so that should be easy. I'll update this page when I get the new sensor.

Next up is writing an iPhone app that shows a graph of current temperature and humidity and gives you a handy way to toggle the heating between Home and Away mode.