Friday, May 11, 2012

SdcLCD: a LCD library for Arduino

It is time to talk about the LCD library. Originally it was planned to work with Mega's external interface only. But it was extended later to accomodate Uno's bit banging interface. It will be extended further to serve chipKIT Max32, which is far more capable in MIPS and in memory size as well. So you can enjoy all the functionality of the library without any limitation.


This library is open source. You can download the code here. Code itself is quite straight forward. So it is very easy to understand. It also comes with some demo projects. After download the file, you extract it and copy the contents under the directory


Then you are almost ready.

Next time, you fire up the sketch, then you can see the library and examples are there.


Before doing upload, you have to confirm that you have the right setting for your system. In other words, you have to set the #define for your board, i.e.,

#define MBOARD_UNO    1

if you have Uno and want to use bit banging interface, otherwise you have to choose

#define MBOARD_MEGA2560    1

for the Mega's memory interface. You also have to choose your LCD setting, i.e.,

#define LCD_GR2400    1


#define LCD_FGD280    1

and the orientation of the LCD

#define DIR_LANDSCAPE    1


#define DIR_PORTRAIT    1


But what if you have a different panel from the ones in the library? Do not worry too much. As I explained in the previous posts. Most of the LCD panel share almost the same controller, circuit, and panel characteristics. And if there are any differences then they are probably about the initialization of the panel. So find the

void SdcLCD::initLCD()

function in the SDCLCD.cpp file and replace the initialization data for your LCD panel. To do that, you need a data about the initialization of the panel although I think that it is not much different from the ones in the library.


Examples come with the library explain most of the information you need to use the library. More concise example you can find in the beginning of the header file (SdcLCD.h)

Programming Example
// initialization
SdcLCD lcd;
// clear screen with black background
// set pen width
// set foreground color
lcd.setForegroundColor(LCDCOLOR(200, 120, 40));
// set background color
// draw a shape
lcd.drawFilledRoundRectangle(10, 10, 200, 100, 5);
// select a font
// draw a string
lcd.drawString(20, 25, "Droid Serif 16 point");

Here is a demo video. For the font handling functions, details will be discussed in the later post.

No comments:

Post a Comment