One of the projects I spent time on during my summer internship at Electric Imp took the power of the Imp, added the pizazz of LCD screens, and resulted in a couple cool little devices. Displays are cool in any context, but being able to update them wirelessly through the Imp opens the door for tons of new and interesting devices and uses. Having a few of these nifty things around the office is good fun, too. The biggest benefit of this project, however, was the insight it gave me into the art of embedded system design.
I started off simply, with a monochrome 84×48 pixel screen from Adafruit. This screen is the same one used in the old Nokia 5110 mobile phone and was designed to work well on battery power. It’s not the prettiest display – it’s black and white and only has around four thousand pixels – but it doesn’t take very much processing power to get it running. It’s a good first project for someone jumping into display tech (like me!). After getting the basics down, I upgraded to a 160×128 16-bit color LCD to make things a bit more interesting.
When dealing with displays, there are several design decisions that need to be made before writing a single line of code. Microcontrollers excel at low cost, power sensitive applications and therefore don’t have the processing power or memory capacity of full-fledged microprocessor systems. Depending on the display, it may not be practical to process the data on the device itself. Unnecessary CPU cycles equal reduced battery life – and that translates into a worse user experience.
Fortunately for us, we can easily harness the power of the Imp Cloud. A few lines of Squirrel code allows us to use agents to do all of the heavy lifting. Agents run on our servers in the cloud, which means they have access to more memory and processing power. It’s possible to pre-format image data in the agent and then send it down to the device, which can then write it as-is to the display. The benefit of this method becomes apparent as the display size increases and the image format becomes more complex.
(Note: If you would like access to agents, which are currently in beta, you may sign up here.)
Every display has specifications for color depth and resolution that determine the size and format of the image data. For a monochrome 84×48 screen, an entire frame can be represented by a mere 504 bytes. We must also consider the time and energy it takes to convert a source file into a format usable by the display driver. In this specific case, the file must be stripped of its headers and packed into 8-pixel bytes. That involves a fair amount of bit manipulation, but the low pixel count of the screen means that the total computation time will be relatively short.
In contrast to the simple monochrome screen, the higher resolution 16-bit color display needs 40 kilobytes per frame. That’s about 80 times more! At that point, loading a full frame into memory will take up almost all of the Imp’s free RAM – leaving very little memory left for anything else. It’s a good thing we have our agent to help us out. We can use it to fetch an image from our web server, process the bitmap header, and convert the pixel data into the proper format. Then, the device can request the image in discrete chunks, writing to the screen after each chunk is downloaded and allowing it to reuse memory.
This can all happen very quickly, but if network latency is high there could be a noticeable delay between chunks. A simple solution is to buffer the image data with flash memory before writing to the screen. This method makes it possible to use the Imp with higher-resolution displays. Neat!
A few interesting examples of Imp-enabled LCD displays have been created by the Electric Imp community. One of them was devised to display weather and tide information. Check it out when you get a chance.
If you’re interested in adding one of these displays to your project, head over to our GitHub page and download the example device code and agent code for the monochrome screen or grab the driver class for the 1.8” color LCD!
Gino Miglio
Electric Imp Intern
Gino is a Computer Engineering major at the New Jersey Institute of Technology.