Introduction: Wiring and Programming the Electric Imp With an LCD Display

Attach an LCD to an Electric Imp                                                                     

Whats an Electric Imp?

It's a Wifi connected processor in a super small package. Check the website for more information - Electric Imp

I purchased the Sparkfun Serial Enabled 16x2 LCD - Black on Green 3.3V to go with the setup.

Here are the hardware and software notes on making it all work.

Parts list:



The Breakout board shown here is dubbed an "April".

Note: This Instructable assumes some basic knowledge of working with an Electric Imp. I have included links to some good resources if you are brand new to the Imp world, but the focus is on getting the LCD working, not teaching the Electric Imp from scratch.

Step 1: Powering and Commissioning Your Imp

To get your imp ready for an LCD screen, it needs power and a process called "Commissioning" that allows it to connect to a local Wifi connection. 

I chose to power this example via USB which requires the addition of a header and jumper on the April development board. Insert the Imp into the carrier and plug in the USB - he Imp should start flashing a variety of colors when the power is applied.

Follow the steps outlined on the Electric Imp website for Commissioning an imp

Once commissioned, you should get  familiar with creating nodes for your Imp and perhaps get "Hello, World!" or some other sample code working before continuing. Some basic knowledge of creating and loading a node is required.

Step 2: Sparkfun SerLCD Serial Enabled LCD Backpack

From the Sparkfun Website -
"The serial enabled LCD backpack allows you to control a parallel based LCD over a single-wire serial interface. The SerLCD backpack takes care of all the HD44780 commands allowing seamless integration with any micro that can communicate over a wide range of TTL serial baud rates. The SerLCD currently supports 16 and 20 character wide screens with 2 or 4 lines of display."

I purchased this one already attached to a 16x2 Black on Green 3.3V LCD. The power, ground and RX pins are all broken out to a 3.5mm pitch screw terminal. If needed, follow the Sparkfun instructions to attach the 3.3V LCD to the backpack.

Connect the power pin (incorrectly marked 5v on the screen. This is a 3.3v device) to the 3v3 on the Imp Breakout board. Similarly connect GND to GND and RX to Pin1 on the Imp Breakout board.

Powering up the Imp (by plugging in the USB cable in my case) generally will display the LCD splash screen (very short) and turn on the backlight.

Step 3: Create a New Node for Your Electric Imp

On your Code screen of the Electric Imp Website, click the "+" button to create a new node. Name it "LCD Examples". Paste in the following Squirrel code.

If you have a 20 Character LCD change the CharactersInLCD variable to 20.

When run on your imp, it should display similar to the picture.

// Code below this line is for your node.
// Drive 3.3v LCD Screen using a Sparkfun SerLCD backpack from an Electric IMP

hardware.uart12.configure(9600, 8, PARITY_NONE, 1, NO_RX);

CharactersInLCD     <- 16;
Message             <- "abcdefghijklm123nopqrstuvwxyz456";

//Backlight brightness values from 128 to 157
//128 - Backlight off
//140 - 40% on
//150 - 73% on
//157 - 100% on
function LCDBacklight(Brightness)
{
    if((Brightness>127)&&(Brightness<158))
    {
        hardware.uart12.write(124);
        hardware.uart12.write(Brightness); 
    }
}

//Sets the SerLCD module to the correct LCD Type.
//3 - 20 Characters wide
//4 - 16 Characters wide
//5 - 4 Lines
//6 - 2 Lines
function SerLCDTypeSetup(LCDType)
{
    if((LCDType>3)||(LCDType<4)||(LCDType<5)||(LCDType<6))
    {
        hardware.uart12.write(124);
        hardware.uart12.write(LCDType); 
    }
}

//Sets the splash screen.
function LCDSetSplash(Message)
{
    LCDClear();
    hardware.uart12.write(Message);

    imp.sleep( 1 );

    hardware.uart12.write(0x7C);
    hardware.uart12.write(0x0A);

    imp.sleep( 1 );
}

//Splash screen on/off toggle
function LCDToggleSplash()
{
    hardware.uart12.write(0x7C);
    hardware.uart12.write(0x09);
}


function LCDClear()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x01);
    hardware.uart12.write(254);
    hardware.uart12.write(128);
    LCDBoxCursorOff();
}

function LCDMoveCursorRight()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x14);
}

function LCDMoveCursorLeft()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x10);
}

function LCDScrollRight()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x1c); 
}

function LCDScrollLeft()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x18); 
}

function LCDVisualDisplayOn()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x0C);
}

function LCDVisualDisplayOff()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x08);
}

function LCDUnderlineCursorOn()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x0E);
}

function LCDUnderlineCursorOff()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x0C);
}

function LCDBoxCursorOn()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x0D);
}

function LCDBoxCursorOff()
{
    hardware.uart12.write(254);
    hardware.uart12.write(0x0C);
}

// Position is zero based
function LCDSetCursorPosition(Line,Position)
{
    local LineBaseAddress = 0;
    if(CharactersInLCD==16)
    {
        if(Line==2)
        {
            LineBaseAddress = 64;
        }
         if(Line==3)
        {
            LineBaseAddress = 16;
        }
         if(Line==4)
        {
            LineBaseAddress = 80;
        }
    }
    if(CharactersInLCD==20)
    {
         if(Line==2)
        {
            LineBaseAddress = 64;
        }
         if(Line==3)
        {
            LineBaseAddress = 20;
        }
         if(Line==4)
        {
            LineBaseAddress = 84;
        }
    }
    hardware.uart12.write(254);
    hardware.uart12.write(LineBaseAddress + Position + 128);
}

function LCDWriteMessage(LCDMessage)
{
    hardware.uart12.write(LCDMessage);
}

//Main Execution loop
function loop()
{
    //Loop Activities - executed once every Wakeup
    imp.wakeup(2.0, loop);
}


//Setup Activities - only executed once
imp.configure("LCD Examples", [], []);
LCDClear(); 
LCDWriteMessage(Message);

//Pause 2 Seconds before starting the main loop - adjust to taste
imp.wakeup(2.0, loop);

Step 4: Using the Provided Code

The first line does the setup of the SerLCD communication with the Electric Imp:

hardware.uart12.configure(9600, 8, PARITY_NONE, 1, NO_RX);

(Communication Speed, Bits, Parity, TX Pin and RX Pin - we attached the LCD to Pin 1)

//Sets the width of the LCD for the rest of the code.
CharactersInLCD     <- 16;

//Default Message
Message             <- "abcdefghijklm123nopqrstuvwxyz456";

All the supported SerLCD commands are listed on the SerLCD v2.5 Datasheet


Most of the commands have a function call in the provided code-for-the-node.

Generally you want to call:

LCDClear();
LCDWriteMessage(Message); 

Almost all of the commands supported by the SerLCD V2.5 are implemented here. Play around with a few like "Blinking Cursor On" and "Scroll Right"