The Electric Imp guys had very kindly passed Adrian a handful of Imps to evaluate. I missed the opportunity to get Shaun Myhill to walk me through using it at the IoT Howduino at DoES, but he and Antony McLoughlin worked together to create the Dirty Win-imp. I finally got my grubby hands on them yesterday to wire one up to an accelerometer.
While the experience was quite frustrating, and it felt like the product just wasn't "ready" yet, the hardware and concept are really cute, and if all the teething problems get sorted out, it's a genuinely useful idea, and rather different than developing on Arduino.
First of all, a disclaimer: this experience represents me charging into the world of Electric Imp half-cocked, without reading everything upfront. I may have missed obvious clues or explicit documentation due to my own inattention!
All the smarts of the Imp, as well as its wifi connectivity, are located in the SD card shaped microcontroller. But to get it to do anything, it has to be plugged into a board (an "Impee") which provides power, pins, and so on. The SD form factor is very cute and feels robust. The card doesn't actually work as an SD card, which is a bit odd, but using an existing form means they can take advantage of cheap components designed for it. The Impee I'm using exposes 6 GPIO pins, which isn't anywhere near as many as an Arduino, but this really isn't a problem, as we'll see.
The Impee can get power either by soldering a connection to a battery, or via USB. I connected via USB, but this only powers the device, and doesn't let you communicate to it, as it only speaks via wifi... this means you have to program it without any means to input your wifi settings ;-) The Imp team have solved this bootstrapping problem using a very clever idea called "Blinkup". They have smartphone apps for iPhone and Android which emit alternating white and black screens in a code which is then read by the Imp's light-sensor. While this is very nice (and it's so appropriate to be literally "flashing" your microcontroller), the implementation needs a little polish.
First problem: you need an iPhone or (recent-ish) Android. You're stuck if you are still using a dumb old Nokia, like both me and Adrian... Bafflingly there isn't a way of using a computer screen, such as the one on my laptop. I eventually borrowed an iPhone from John McKerrell and flashed the chip with the DoES wifi details.
After it rather unimpressively failed to do anything obvious, I looked up the diagnostics for the Imp's flashing LEDs, and here's the next problem: the documentation is fragmented and poor. The front- page of electricimp.com is nicely designed but even the "for developers" page doesn't link to the wiki. Navigating between the wiki and the "Planner" app is also confusing. Eventually I found a page on status codes and determined that it wasn't connecting to the wifi. Checking the iPhone app, it turns out though it worked out which network I was connected to, it didn't pass across the password, so you are supposed to type it in yourself. Once I'd done that, the flashing process worked very nicely.
With that done, the imp appears in my planner, and I am prompted to choose a firmware. I choose the blank firmware. You can edit the code in a rather pretty online code editor. However, the way I'd chosen the firmware, it was opened read-only... I really don't understand why this wasn't an editable copy. Eventually I figured out how to Add Node, and cargo culted some code from the examples. There aren't very many examples yet, but that will only get better as and when more people start contributing.
The Imp uses a language called Squirrel This is a
dynamic scripting language, but with a syntax derived from C. That's handy to
know, because it's sparsely documented and impossible to google, because
Squirrel is such an overloaded term. When I searched for "Squirrel Language",
my top hit was for the language of squirrels in the massively multiplayer
computer game Dofus. (In case you're wondering, the squirrel language "is
related to English, but with dominating use of letters 'i' and 'k'" --
Skiikrikik ikinknikgikinkj.)
Similarly, searching for terms like Squirrel include module
or Squirrel
trigonometry
will almost always give you completely useless results. The
documentation itself is correct but insufficient. The atan2
function belongs
to the math
library, but how do you use this library? It turns out that you
can use #include <math>
like in C, but don't need to, because it's included
by default. However you have to preface the function with the library name, so
you call it like math.atan2()
. You can guess these things if you know C-like
languages, but really it would be nice not to have to.
Pushing the code is a joy. You simply save the code, and reboot the Imp (by
ejecting it and plugging it back into its impee). The Imp recognizes which
Impee it is in, and (if it can connect to the internet) downloads the new code
automatically. At this point, you get any error messages: this shows how
dynamic the Squirrel language is... even though the process is quite fast, I
would have liked some kind of pre-flight checks, but never mind. The error
messages are shown in the editor window, as are messages output by
server.show()
-- I liked this a lot, as it made debugging so much easier than
on Arduino, where you have to use the serial console, and there is no automatic
output about runtime errors. Also, because the language is more dynamic, you
can easily coerce integers into strings, e.g.
server.show(x + "," + y + "," + z);
which also makes logging and debugging relatively pleasant.
The output of server.show()
is also sent to the planner screen, where it's
shown on the "node" box for the Impee. When you've only got the one Impee
running, this isn't especially impressive, but I can really imagine this
being useful once you develop an ecosystem of them.
I mentioned that the lack of pins wasn't a real issue. I more-or-less successfully attached my accelerometer, and ported some Arduino code to it, to convert the analog data into angles. This only leaves 3 pins and a ground left, which isn't a lot to do anything useful. But if you look at the planner, you can easily add another Impee, and pass data from one to the other. This is even more powerful when you think about "virtual Impees", which are software based nodes running on the electricimp.com servers. At the moment, the virtual nodes are hard-coded into the app, e.g. you can't write your own. But once they allow you to write your own nodes, you have an easy form of modular reusable components (and for bonus points, the server based nodes could be written in a real high-level language such as Javascript instead of Squirrel...) For example, one node could post to Twitter, or another could run a Twitter search. Connect those up to the appropriate physical Impee and you've recreated an iconic IoT device like Bubblino or Bakertweet. But connect a number of these nodes together and you're rapidly multiplying the complexity and capability of what you can do, without ever having to worry about the processing power, or I/O connectivity of a single physical node. Each physical Impee will do one thing, and do it well, in sharp contrast to the trade-offs we make when developing on Arduino, where we have to cram many pieces of functionality onto a single board, with a small amount of available memory. (I'm not being quite fair here -- much of the smarts of the WhereDial, for example, are actually located on the mapme.at servers, rather than on the Arduino. Perhaps it's more that the Planner style of the Imp actively encourages you towards this kind of modularization, by having affordances such as the easily configurable "Make HTTP Post" virtual node, or the "Push data to Cosm" node.)
Also bear in mind that the Impees don't have to be on the same network: this makes it a plausible implementation infrastructure for products such as the Good Night Lamp, or for monitoring systems over a number of locations. This is of course because the Imps don't mesh with each other, but rather with the central server. This is of course a possible counterindication for using them: do you trust them with your sourcecode? Do you trust them to continue existing? If they close, will it be possible to reconfigure the Imps to point at another provider who can host the code? If you get big, and want to configure the planning infrastructure more then the Electric Imp team want to facilitate for their general customers, will you be able to host and develop the infrastructure for yourself?
These days we are quite happy to host much of our social and business communication and storage infrastructure online with, so the idea of running the Imp code online isn't actually all that much of a stretch. The Electric Imp has great potential to find a niche that we weren't even aware existed, but at the moment it doesn't feel quite ready yet.