LCD Display

Sparkfun Color LCD Shield

The Sparkfun Color LCD Shield, shown right, provides a straightforward way to add a display to the Arduino UNO or MEGA boards. The shield also includes three push button switches. The screen is 132×132 pixels and supports 12bit RGB colour.

I have developed a software driver module for this in C that works for both the UNO and MEGA boards. This code is based on the code provided in James P. Lynch’s excellent tutorial.

Download Color LCD driver C source code zip file

To define the Arduino board simply comment and uncomment the lines shown below at the top of the Color_LCD_driver.h header file

// Define Arduino Target board (Comment out)
//#define UNO // Use if using the Arduino UNO board
#define MEGA // Use if using the Arduino MEGA board

Depending the supplier of the LCD screen you may also need to toggle the comments on the next two lines as well. For more information about why you may need to do this is available here.

// Define LCD receiver chip (Philips Black connector, Epson Green connector)
#define PHILIPS
//#define EPSON

The module provides the following functions:

void LCDInit(void); This must be called first to initialise the display

LCD Coordinates

void LCDOrientation(char orient); Used to rotate the orientation of the display with the following definitions

#define STRAIGHT 0
#define INVERTED 2

The default orientation after using LCDInit is such that the three switches are at the bottom of the screen

void LCDClear(int color); Used to paint the whole display a single colour you can use the following predefined 12 bit colours definitions:

#define WHITE 0xFFF
#define BLACK 0x000
#define RED 0xF00
#define GREEN 0x0F0
#define BLUE 0x00F
#define CYAN 0x0FF
#define MAGENTA 0xF0F
#define YELLOW 0xFF0
#define BROWN 0xB22
#define ORANGE 0xFA0
#define PURPLE 0xF6A

void LCDSetPixel(int x, int y, int color); Sets the colour of a single pixel
void LCDSetLine(int x0, int y0, int x1, int y1, int color); Draws a line from (x0,y0) to (x1,y1)
void LCDSetRect(int x0, int y0, int x1, int y1, unsigned char fill, int color); Draws a rectangle
void LCDSetCircle(int x0, int y0, int radius, int color); Draws a circle
void LCD7Seg(int x0, int y0, char character, int color, int bgcolor); Emulates a seven segment display
void LCDPrintLogo(void); Prints the Sparkfun logo
void LCDPutChar(char c, int x, int y, int size, int fColor, int bColor); Writes a single ASCII character on the display. The colour of the character is defined by the fColor and the background around the character by bColor
void LCDPutStr(char *pString, int x, int y, int Size, int fColor, int bColor); Writes a string of ASCII characters on the display. Note if the string exceeds the width of the display it is truncated. The font size can be specified with the following definitions:

#define SMALL 0
#define MEDIUM 1
#define LARGE 2

The LCDInit function also initialises the IO pins that the three switches are attached to with pullups enabled. The following definitions allow you to access the appropriate bits of the PIN registers that the switches connect to.

Register   bit
PINS1      S1
PINS2      S2
PINS3      S3
//To poll switch state use
(PINS1 & (1<<S1))

Below is a Hello World Example for the Nokia LCD Display Shield. This demonstrates the display functions and the use of the three switches that are on the shield. It is necessary to unzip the Colour_LCD_driver.h and Colour_LCD_driver.c files into the directory indicated by your include statement. In the example below this would be the same directory as the main c file. If using AVR Studio it is also necessary to add these to files to the solution explorer. Right Click on the project title in the solution explorer and select Add. Then select add Existing.

 * HelloWorldLCD.c
 * Hello World Program to demonstrate the operation of the Nokia LCD Shield
 * Pressing each switch will select a different example, multiple presses of
 * the same button will rotate the image by 90 degrees
 * Created: 18/01/2013 21:02:14
 *  Author: bthomsen

#include <avr/io.h>

#include "Color_LCD_driver.h"

int main (void)
//					Main Code
int i=0;
	//Initialize microcontroller I/O pins to communicate with LCD Shield

	//Initialize the LCD
	LCDPutStr("Ready", 20, 20, SMALL, WHITE, BLUE);

		if(readpin(PINS1,S1) == 0)
			//Switch S1
			#ifdef MEGA
			LCDPrintLogo(); //Show the splash-screen (Sparkfun Logo)
			if (i > 3)
		if(readpin(PINS2,S2) == 0)
			//Switch S2
			LCDPutStr("Hello World!", 20, 20, SMALL, WHITE, BLUE);
			LCDPutStr("Hello World!", 40, 20, MEDIUM, WHITE, BLUE);
			LCDPutStr("Hello World!", 60, 20, LARGE, WHITE, BLUE);
			LCDSetRect(100, 20, 110, 70, NOFILL, YELLOW);
			LCDSetCircle(100, 90, 10, GREEN);
			if (i > 3)
		if(readpin(PINS3,S3) == 0)
			//Switch S3
			LCDSetLine(0, 40, 20, 40, WHITE);
			LCDSetLine(20, 40, 20, 50, WHITE);
			LCDSetRect(20, 50, 60, 70, FILL, YELLOW);
			LCDSetCircle(100, 100, 10, GREEN);
			LCDSetCircle(100, 30, 10, BLUE);
			if (i > 3)
    return 0;

2 thoughts on “LCD Display

  1. Benn – I am trying to help my son with his new color lcd and ArduinoUno. Your driver looks like it performs more of the features than most that I have found for him. My uneducated question is more about the Arduino 1.0 Sketches inability to recognize your .c/.h files. It has been awhile since coded in gcc environments and i thought the IDE from arduino would deal with a “.c” library. Do you have a simple example of how the environment should be set up and how to include your libraries so that he can reference them in his project. Thanks…. I have a feeling I am doing something obviously wrong ..

    • My driver was written for a C environment using avrgcc such as that provided by AVRStudio 5. You cannot use it directly with the Arduino Sketches where the Java code you write essentially calls C++ functions that then call the avrgcc libraries. The reason I adapted Peters original code for the C environment is because this allows you to interact more closely with the hardware. Whereas the rationale behind the Arduino Sketches is to hide the hardware.

      I am working now to port my library into C++ so that it can be included in the Arduino sketches and will post an update when done. Until then you should be able to use the Arduino library on the Sparkfun page

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