loading

Wiring and programming the Electric Imp with an LCD display

Featured
Picture of Wiring and programming the Electric Imp with an LCD display
DSC_0278.jpg
DSC_0274.jpg
DSC_0275.jpg
DSC_0276.jpg
DSC_0283.jpg
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.
 
Remove these adsRemove these ads by Signing Up

Step 1: Powering and Commissioning your Imp

Picture of 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

Picture of Sparkfun SerLCD Serial Enabled LCD Backpack
DSC_0283.jpg
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

Picture of 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

Picture of 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"
pabell1 year ago

ive purchased this version of the sparkfun LCD from Microcenter. Sparkfun informed me that was similar etc. I found that this is actually a 5v Version. When I Hook it up to the imp per your instructions, but using a dedicated power supply I get the sparkfun splash screen, but nothing else. I am wondering if the programming for my model would be different than what you have provided, if so what would i need to tweak in order to make it work

http://www.microcenter.com/product/389835/Serial_L...

https://www.sparkfun.com/tutorials/289

try using pin5 and change the code to uart57

Coolioxi took your suggestion but no change.

how fast is the imp?
Kev_MacD (author)  amandaghassaei2 years ago
It connects to the Wifi very quickly when configured and powered up. I believe it has an 802.11b/g/n WiFi transceiver, so that part should be good. I haven't run any speed tests on the processor itself, which is a Cortex-M3. I seems to rock along, but I haven't had to deal with lots of data.

I will publish an Instructable on the device I am building too, so watch for that, however I don't plan to move large amounts of data in this project either.
can I hook the lcd to another pin for RX? ill be using pin 1 for something else.

http://arduino.cc/en/Reference/SoftwareSerial

amandaghassaei this is for Arduino, I am using the electric imp, it's my limited understanding that the 2 aren't the same. Rather than posting a link could you provide some context for why and how softwareserial will work on electric imp.

oh sorry, I saw that comment out of context. Yes they are different.

Hello,
If I just copy-paste the full code you write, the only thing I'm getting are two vertical lines in each character...

Do you have an idea of what might be wrong?

Thank you
Kev_MacD (author)  joaoaccarvalho2 years ago
Sounds like the Imp hasn't connected properly to your WiFi.