Programming Blog

Jeremy Morgan

Mostly Coherent Ramblings of a Silicon Forest Software Developer

The Arduino LCD Shield Kit

By: Jeremy Morgan







Raspberry Pi Newsletter


I recently picked up an Arduino LCD shield kit from Adafruit. I’ve wanted to play around with some LCD screens and since this was a self contained kit for $20, I thought I’d try it out. Here’s my thoughts on it.

For this article I’m using an Arduino Mega 2560, obtained from Newark Element 14

The Arduino LCD Shield Kit

The kit comes with the following items:

Arduino Projects - LCD Shield Kit

In the kit we have:

  • 5 Resistors
  • Potentiometer
  • Printed Circuit Board
  • Header Pins
  • Pushbuttons
  • i2c Port Expander Chip

It’s definitely a “turnkey” kit that comes with everything you need. The full assembly instructions show you how to build it, step by step.

Bust Out Your Soldering Iron!

Arduino Projects - LCD Shield Kit

For this kit you will need to do a considerable amount of soldering. Some folks aren’t a fan of this idea, but I love it. This is great for beginners so they can learn soldering techniques and get better at it. Even though this is a complete kit that could be easily shipped soldered and assembled, I think that would be cheating beginners out of the experience of assembly. Not to mention it frees you up to use only the parts you need, or even use them in something else.

You’re a hacker now, embrace it!

Assembling the Shield

For the first step you’ll want to solder on the resistors out of the kit in the following configuration:

Arduino Projects - LCD Shield Kit

An easy way to do this is pull the resistors down through the holes and cross the wires like so. Then once they are all through, solder each piece and trim off the ends.

Arduino Projects - LCD Shield Kit Next, add the buttons. You’ll have to be careful with these pins as they are very close together.

Arduino Projects - LCD Shield Kit

Now, install the IC with the notch matching, as shown in the diagram:

Arduino Projects - LCD Shield Kit

Then break apart the header pins and insert them as shown:

Arduino Projects - LCD Shield Kit

You can now place the board on the Arduino so the pins match up.

Arduino Projects - LCD Shield Kit

Now you can solder the pins in. This gives you an interface to your Arduino, but mostly it’s just to keep the sheild stable. At this point you could add risers to the header pins for stacking other devices if you want.

Finally, you then solder on the LCD screen:

Arduino Projects - LCD Shield Kit

And you’re done!

Arduino Projects - LCD Shield Kit

Next we’ll cover how to put some text on the screen.

Displaying Text

The easiest way to interact with this shield is to use Adafruit’s RGB LCD Shield Library. Download that and install it into sketch. (How to install additional Arduino libraries)

To output the message shown above, create a file with the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  // Debugging output
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // print in first row
  lcd.print("Be sure to drink");
  // set cursor to second row (row 1)
  lcd.setCursor(0, 1);
  // print in second row
  lcd.print("your Ovaltine");
  // set backlight to white 
  lcd.setBacklight(0x7);
}

void loop() {
  // do nothing for now
}

(Get this code on Github)

Pretty easy right? I hope the comments explain what’s going on. But we have some other buttons on there we want to work with. We’ll put the following in the loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
uint8_t buttons = lcd.readButtons();

  if (buttons) {
    
    lcd.clear();
    lcd.setCursor(0,0);
    
    if (buttons & BUTTON_UP) {
      lcd.print("pressed UP");
    }
    if (buttons & BUTTON_DOWN) {
      lcd.print("pressed DOWN");
    }
    if (buttons & BUTTON_LEFT) {
     lcd.print("pressed LEFT");
    }
    if (buttons & BUTTON_RIGHT) {
      lcd.print("pressed RIGHT");
    }
    if (buttons & BUTTON_SELECT) {
      lcd.print("pressed SELECT");
    }
  }

(Get this code on Github)

This code should be really straightforward. You can check to see if a button is pressed in the loop, and create code based on it. So let’s do something with that.

Turn an LED On and Off with Indicator

Here’s something to try, hook up an LED to a digital pin. I am using the Arduino Mega, and just put it in the board like this:

Arduino Projects - LCD Shield Kit

Now, create a file with the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("LED MODE:");
  lcd.setCursor(0,1);
  // off by default
  lcd.print("OFF");
  lcd.setBacklight(0x7);
  pinMode(53, OUTPUT);
}

void loop() {

  uint8_t buttons = lcd.readButtons();
  
  lcd.setCursor(0,0);
  lcd.print("LED MODE:");
  
  if (buttons) {
    
    lcd.clear();      
    
    if (buttons & BUTTON_UP) {
      // turn led on
      digitalWrite(53, HIGH);
      // display it
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    
    if (buttons & BUTTON_DOWN) {
      // turn led off
      digitalWrite(53, LOW);
      // display it
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }   
  }  
}

(Get this code on Github)

This is pretty straightforward stuff, not that we set “pinMode” to 53,OUTPUT. This is how we set up the pin to light up the LED with the digitalWrite function. By setting pin 53 to HIGH it powers it, and setting it to LOW stops it. The LCD screen then prints the status.

Arduino Projects - LCD Shield Kit Arduino Projects - LCD Shield Kit

The possibilities are endless here!


Raspberry Pi Newsletter


Summary

Overall I think this product is a fantastic value. I’ve just barely scratched the surface of what can be done here, and it’s only $19.95. It could be a very valuable display for your projects. It’s easy to assemble and works great. So pick up an Arduino (I really like the Mega 2650) and an LCD shield and start tinkering! Contact me with any cool projects you create!




My New Course: Hands on Internet of Things with the Raspberry Pi

Internet of Things

I have just released my new course titled ”Hands on Internet of Things” which is intended to be a course for people who want to get started with IoT. I’ll take you through blinking lights and reading sensors to creating YOUR own IoT endpoint and dashboard. I’m offering this special coupon for readers of my site: get %50 off this course here. Thanks for being a reader!


Like my IoT projects? Sign up here to be added to my IoT newsletter


Comments