LinkSprite LCD/Keypad Arduino Shield for Software Configuration

All of my production Arduino projects allow some sort of configuration changes. Various operational constants are maintained in EEPROM. When the Arduino is first started, I can change these settings and rewrite them into EEPROM if I have a terminal connected to the Arduino.

Generally, I am OK with connecting my laptop to one of these arduinos to make configuration changes, should the need arise. But I would like the option to be able to configure using an LCD screen and push buttons if reconfiguring were regularly necessary or if connecting a USB cable to the arduino were difficult.

I have spent a lot of time over the years configuring datacom equipment and much of it is configured using a small LCD and a couple of buttons like this ADTRAN TSU

adtran tsu

This particular device uses enter/up/down/cancel to navigate its menus. This is the kind of functionality I’d like to replicate on an arduino.

I purchased a LinkSprite LCD/Keypad shield for the arduino from Sparkfun. It looks like this:

The docs says the shield uses digital pins 4-9 and analog pin 0. The schematic indicates pin D10 is being used as well and looking at the board a trace does appear to go somewhere.

The LCD display is a normal display and can be accessed using the standard liquidCrystal library.

The buttons are a bit weird. All 5 buttons connect to a single analog port and each has a different resistor assigned to it so that when each button is pressed, the analog port returns a different value.

I started out having a lot of trouble dealing with these switches. I started at the LinkSprite site and downloaded their sample code. Well, that was for Version 2 of this board and evidently sparkfun (at the time of purchase any way) was selling V1. V2 appears to allow you to press buttons simultaneously and V1 doesn’t.

I found the correct sample code here.

This code worked fine for me; however, I found it rather difficult to follow. I wrote my own getkey function which is far clearer (at least to me)

#include                 <LiquidCrystal.h>

const int                maxDeviation    = 5;

enum                     keyNameE        {none=0, right=1, up=2, down=3, left=4, select=5};

// initialize the library with the numbers of the interface pins
LiquidCrystal           lcd(8, 9, 4, 5, 6, 7);

int getKey(
  ) {

int                        curValue;

curValue = analogRead(A0);
    if (abs(curValue-0) < maxDeviation)
        return right;
    else if (abs(curValue-143) < maxDeviation)
        return up;
    else if (abs(curValue-332) < maxDeviation)
        return down;
    else if (abs(curValue-507) < maxDeviation)
        return left;
    else if (abs(curValue-740) < maxDeviation)
        return select;
        return none;
} // getKey

void setup() {
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    lcd.print("hello, world!");

void loop() {

int                     curValue;
int                        i;
int                     lastValue       = 1023;

while (true) {
    i = getKey();
    switch(getKey()) {
        case none:
            lcd.print("NONE      ");
        case right:
            lcd.print("RIGHT     ");
        case up:
            lcd.print("UP        ");
        case down:
            lcd.print("DOWN      ");
        case left:
            lcd.print("LEFT      ");
        case select:
            lcd.print("SELECT    ");
    } // while

It is very disappointing that getKey cannot return an enumeration. I spent way too much time trying to force it. From what I gather, the Arduino IDE’s preprocessing some how messes this up such that I can only return an int. Fortunately I can still use the enum labels in the switch so clarity is maintained.

If you use this code and find that certain buttons aren’t recognized, increase the deviation constant. I found +/- 5 worked every time on my board, but if your resistors’ deviation is more than mine, you might have an issue.

Once I had the sample code running smoothly, I set out to code my reconfig function which allows configuring of the arduino via the shield. Here’s a short video of how this functions:

I’m not going to post the code here. It isn’t a simple function call. You must encode the strings into a switch statement so really it consists of a skeleton function that is hand-modified and then getKey and another function that handles the scrolling.

If someone really wants this code, drop me a line and I’ll make it available.



This entry was posted in c-arduino and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s