t r o n i x s t u f f

fun and learning with electronics

Tutorial: Arduino and monochrome LCDs

Please note that the tutorials are not currently compatible with Arduino IDE v1.0. Please continue to use v22 or v23 until further notice. 

This is chapter twenty-four of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe.

The first chapter is here, the complete series is detailed here. Please note from November 1, 2010 files from tutorials will be found here.

Welcome back fellow arduidans!

The purpose of this article is to summarise a range of affordable monochrome liquid-crystal display units that are available to work with our Arduino; and to replace the section about LCDs in chapter two of this series. We will first examine some fixed-character and then graphical LCD units in this article. So let’s go!

Fixed-character LCD modules

When shopping around for LCD modules, these will usually be the the most common found in retail outlets. Their size is normally measured by the number of columns and rows of characters in the display. For example, the three LCDs below are 8×2, 16×2 and 20×4 characters in size:

Currently, most LCDs should have a backlight of some sort, however you may come across some heavily-discounted models on (for example) eBay that are not. Character, background and backlight colours can vary, for example:

Interfacing these screens with our Arduino boards is very easy, and there are several ways to do so. These interface types can include four- and eight-bit parallel, three-wire,  serial, I2C and SPI interfaces; and the LCD price is usually inversely proportional to the ease of interface (that is, parallel are usually the cheapest).

Four-bit parallel interface

This is the cheapest method of interface, and our first example for this article. Your LCD will need a certain type of controller IC called a Hitachi HD44780 or compatible such as the KS0066. From a hardware perspective, there are sixteen pins on the LCD. These are usually in one row:

… or two rows of eight:

The pin labels for our example are the following:

  1. GND
  2. 5V (careful! Some LCDs use 3.3 volts – adjust according to LCD data sheet from supplier)
  3. Contrast
  4. RS
  5. RW
  6. Enable
  7. DB0 (pins DB0~DB7 are the data lines)
  8. DB1
  9. DB2
  10. DB3
  11. DB4
  12. DB5
  13. DB6
  14. DB7
  15. backlight + (unused on non-backlit LCDs) – again, check your LCD data sheet as backlight voltages can vary.
  16. backlight GND (unused on non-backlit LCDs)

As always, check your LCD’s data sheet before wiring it up.

Some LCDs may also have the pinout details on their PCB if you are lucky, however it can be hard to decipher:

Now let’s connect our example 16×2 screen to our Arduino using the following diagram.

Our LCD runs from 5V and also has a 5V backlight – yours may differ, so check the datasheet:

(Circuit layout created using Fritzing)

Notice how we have used six digital output pins on the Arduino, plus ground and 5V. The 10k ohm potentiometer connected between LCD pins 2, 3 and 5 is used to adjust the display contrast. You can use any digital out pins on your Arduino, just remember to take note of which ones are connected to the LCD as you will need to alter a function in your sketch. If your backlight is 3.3V, you can use the 3.3V pin on the Arduino.

From a software perspective, we need to use the LiquidCrystal() library. This library should be pre-installed with the Arduino IDE. So in the start of your sketch, add the following line:

#include <LiquidCrystal.h>

Next, you need to create a variable for our LCD module, and tell the sketch which pins are connected to which digital output pins. This is done with the following function:

LiquidCrystal lcd(4,5,6,7,8,9);

The parameters in the brackets define which digital output pins connect to (in order) LCD pins: RS, enable, D4, D5, D6, and D7.

Finally, in your void setup(), add the line:

lcd.begin(16,2);

This tells the sketch the dimensions in characters (columns, rows) of our LCD module defined as the variable lcd.

Example 24.1

In this example we will get started with out LCD by using the basic setup and functions. To save space the explanation of each function will be in the sketch itself. Please note that you do not have to use an Arduino Mega – it is used in this article as my usual Arduino boards are occupied elsewhere.

/*
Example 24.1 - LCD demonstration
http://tronixstuff.com/tutorials > Chapter 24
CC by-sa-nc liquidCrystal library originally added 18 Apr 2008 by David A. Mellis
library modified 5 Jul 2009   by Limor Fried (http://www.ladyada.net, http://www.adafruit.com)
*/
#include <LiquidCrystal.h> // we need this library for the LCD commands
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4,5,6,7,8,9); // define our LCD and which pins to user
int a = 63;
int d = 3000; // used for display delayfloat
float b = 3.1415926;
void setup()
{
lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit
lcd.clear();      // this clears the LCD. You can use this at any time
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
// positions starting point on LCD, column 0, row 0 (that is, the top left of our LCD)
lcd.print("Hello!");
// prints "Hello" at the LCD's cursor position defined above
lcd.setCursor(0,1);
// positions starting point on LCD, column 0, row 1 (that is, the bottom left of our LCD)
lcd.println("This is fun     ");
// note the rest of the line is padded out with spaces
delay(d);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("a = ");
lcd.print(a); // this will immediately follow "a = "
lcd.setCursor(0,1);
lcd.print("pi = ");
lcd.print(b,7);
// the 7 means 7 decimal places. You can also replace this with DEC, HEX, BIN as with
// other *.print functions, as such:
delay(d);
lcd.clear();
lcd.home(); // sets cursor back to position 0,0 - same as lcd.setCursor(0,0);
lcd.print("a (HEX) = ");
lcd.print(a, HEX); // this will immediately follow "a = "
lcd.setCursor(0,1);
lcd.print("a (BIN) = ");
lcd.print(a,BIN);
delay(d);
lcd.noDisplay(); // turns off the display, leaving currently-displayed data as is
delay(d);        // however this does not control the backlight
lcd.display();   // resumes display
delay(d);
}

And here is a quick video of the example 24.1 sketch in action:

There are also a some special effects that we can take advantage of with out display units – in that we can actually define our own characters (up to eight per sketch). That is, control the individual dots (or pixels) that make up each character. With the our character displays, each character is made up of five columns of eight rows of pixels, as illustrated in the close-up below:

In order to create our characters, we need to define which pixels are on and which are off. This is easily done with the use of an array (array? see chapter four). For example, to create a solid block character as shown in the image above, our array would look like:

byte a[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111}

Notice how we have eight elements, each representing a row (from top to bottom), and each element has five bits – representing the pixel column for each row. The next step is to reference the custom character’s array to a reference number (0~7) using the following function within void setup():

lcd.createChar(0,a);

Now when you want to display the custom character, use the following function:

lcd.write(0);

where 0 is the memory position of the character to display.

To help make things easier, there is a small website that does the array element creation for you.

Example 24.2

Now let’s display a couple of custom characters to get a feel for how they work. In the following sketch there are three defined characters:

/* Example 24.2 - LCD custom character demonstration
 http://tronixstuff.com/tutorials > Chapter 24 CC by-sa-nc
 liquidCrystal library originally added 18 Apr 2008 by David A. Mellis
 library modified 5 Jul 2009  by Limor Fried (http://www.ladyada.net, http://www.adafruit.com)
*/
#include <LiquidCrystal.h> // we need this library for the LCD commands
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4,5,6,7,8,9); // define our LCD and which pins to use
int d = 3000; // used for display delay
byte a[8] = {  B00000,  B00000,  B00000,  B00100,  B00100,    B00000,  B00000,  B00000};
byte b[8] = {  B00000,  B00000,  B10001,  B10001,  B10001,  B10001,  B00000,  B00000};
byte c[8] = {  B11111,  B10001,  B10001,  B10001,  B10001,  B10001,  B10001,  B11111};
void setup()
{
lcd.createChar(0,a); // define our characters into the sketch as variables
lcd.createChar(1,b);
lcd.createChar(2,c);
lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit
lcd.clear();      // this clears the LCD. You can use this at any time
}
void loop()
{
for (int z=0; z<16; z++)
{
lcd.setCursor(z,0);
lcd.write(0);  // write the first character
delay(250);
lcd.setCursor(z,0);
lcd.write(1);  // write the second character
delay(250);
lcd.setCursor(z,0);
lcd.write(2);  // write the third character
delay(250);
lcd.setCursor(z,0);
lcd.write(1); // write the second character
delay(250);
lcd.setCursor(z,0);
lcd.write(0);  // write the first character
delay(250);
}
delay(1000);
lcd.clear();
}

And here is a quick video of the example 24.2 sketch in action:

So there you have it – a summary of the standard parallel method of connecting an LCD to your Arduino. Now let’s look at the next type:

Three-wire LCD interface

If you cannot spare many digital output pins on your Arduino, only need basic text display and don’t want to pay for a serial or I2C LCD, this could be an option for you. A 4094 shift register IC allows use of the example HD44780 LCD with only three digital output pins from your Arduino. The hardware is connected as such:


And in real life:

From a software perspective, we need to use the LCD3Wire library, which you can download from here. To install the library, copy the folder within the .zip file to your system’s \Arduino-2x\hardware\libraries folder and restart the Arduino IDE. Then, in the start of your sketch, add the following line:

#include <LCD3Wire.h>

Next, you need to create a variable for our LCD module, and tell the sketch which of the 4094′s pins are connected to which digital output pins as well as define how many physical lines are in the LCD module. This is done with the following function:

LCD3Wire lcd = LCD3Wire(2, 11, 12, 10); The parameters in the brackets are the number of lines in the LCD and the digital output pins connected to 4094 pin numbers 2, 1 and 3.

Finally, in your void setup(), add the line:

lcd.init();

The number of available LCD functions in the LCD3wire library are few – that is the current trade-off with using this method of LCD connection … you lose LCD functions but gain Arduino output pins. In the following example, we will demonstrate all of the available functions within the LCD3Wire library.

Example 24.3

/*
Example 24.3 - 3-wire LCD demonstration
http://tronixstuff.com/tutorials > chapter 24
Contains copyleft code from http://www.arduino.cc/playground/Code/LCD3wires
and LCD3Wire library  */
#include  // we need this library for the LCD commands
LCD3Wire lcd = LCD3Wire(2, 11, 12, 10); //create object to control an LCD.
void setup()  {
lcd.init();
}
void loop()
{
lcd.printIn("LCD3Wire library"); // displays text on the LCD
lcd.cursorTo(2,0);  // rows are 1... and columns are 0...
lcd.printIn("-tronixstuff.com");
delay(1000);
lcd.leftScroll(16,500);
// scrolls the entire display 16 chars to left, 100ms per character-shift
delay(1000);
lcd.clear(); // clears the display
}  

And as always, let’s see it in action. The LCD update speed is somewhat slower than using the parallel interface, this is due to the extra handling of the data by the 4094 IC:

Now for some real fun with:

Graphic LCD modules

(Un)fortunately there are many graphic LCD modules on the market. To keep things relatively simple, we will examine two – one with a parallel data interface and one with a serial data interface.

Parallel interface

Our example in this case is a 128 by 64 pixel unit with a KS0108B parallel interface:

For the more technically-minded here is the data sheet. From a hardware perspective there are twenty interface pins, and we’re going to use all of them. For breadboard use, solder in a row of header pins to save your sanity!

This particular unit runs from 5V and also has a 5V backlight. Yours may vary, so check and reduce backlight voltage if different.

You will again need a 10k ohm potentiometer to adjust the display contrast. Looking at the image above, the pin numbering runs from left to right. For our examples, please connect the LCD pins to the following Arduino Uno/Duemilanove sockets:

  1. 5V
  2. GND
  3. centre pin of 10k ohm potentiometer
  4. D8
  5. D9
  6. D10
  7. D11
  8. D4
  9. D5
  10. D6
  11. D7
  12. A0
  13. A1
  14. RST
  15. A2
  16. A3
  17. A4
  18. outer leg of potentiometer; connect other leg to GND
  19. 5V
  20. GND

A quick measurement of current shows my TwentyTen board and LCD uses 20mA with the backlight off and 160mA with it on. The display is certainly readable with the backlight off, but it looks a lot better with it on.

From a software perspective we have another library to install. By now you should be able to install a library, so download this KS0108 library and install it as usual. Once again, there are several functions that need to be called in order to activate our LCD. The first of these being:

GLCD.Init(NON_INVERTED);

which is placed within void setup(); The parameter sets the default pixel status. That is, with NON_INVERTED, the default display is as you would expect, pixels off unless activated; whereas INVERTED causes all pixels to be on by default, and turned off when activated. Unlike the character LCDs we don’t have to create an instance of the LCD in software, nor tell the sketch which pins to use – this is already done automatically. Also please remember that whenever coordinates are involved with the display, the X-axis is 0~127 and the Y-axis is 0~63.

There are many functions available to use with the KS0108 library, so let’s try a few of them out in this first example. Once again, we will leave the explanation in the sketch, or refer to the library’s page in the Arduino website. My creative levels are not that high, so the goal is to show you how to use the functions, then you can be creative on your own time :)

Example 24.4

This example demonstrate a simpler variety of graphic display functions.

/*  Example 24.4 - KS0108 Graphic LCD demonstration
http://tronixstuff.com/tutorials > chapter 24  CC by-sa-nc
*/
#include <ks0108.h>  // library header
int xc, yc = 0;
int d=1000; // for delay use
void setup()
{
GLCD.Init(NON_INVERTED);   // initialise the library with pixel default as off
GLCD.ClearScreen();        // clear the LCD
randomSeed(analogRead(5));
}
void loop()
{
GLCD.DrawRect(0, 0, 127, 63, BLACK);
// draw an open rectangle that spans the extremties of the LCD
GLCD.DrawRect(10, 10, 117, 53, BLACK);
GLCD.DrawRect(20, 20, 107, 43, BLACK);
GLCD.DrawRect(30, 30, 97, 33, BLACK);
delay(d);
GLCD.ClearScreen();  // clear the LCD
for (int a=1; a<20; a++)
{
GLCD.DrawCircle(63,31,a,BLACK);
// draws a circle with centre at 61,31; radius of a, with black pixels
delay(d-800);
GLCD.DrawCircle(63,31,a,WHITE); // draws the same circle with the pixels off
}
delay(d);
GLCD.ClearScreen();  // clear the LCD
for (int a=0; a<128; a++)
{
GLCD.DrawVertLine(a, 0, 63, BLACK);
// draws a vertical line from xy position a, 0 of length 63
delay(d-950);
}
delay(d-800);
for (int a=0; a<128; a++)
{
GLCD.DrawVertLine(a, 0, 63, WHITE);
delay(d-950);
}
GLCD.ClearScreen();  // clear the LCD
for (int a=0; a<64; a++)
{
GLCD.DrawHoriLine(0, a, 127, BLACK);
// draws a horizontal line from xy position 0, a of length 127
delay(d-950);
}
for (int a=0; a<64; a++)
{
GLCD.DrawHoriLine(0, a, 127, WHITE);
delay(d-950);
}
GLCD.ClearScreen();  // clear the LCD
GLCD.DrawRoundRect(30, 30, 20,20, 5,BLACK);
// draw a rectangle with rounded edges: x, y, width, height, radius of rounded edge, colour
GLCD.DrawRoundRect(60, 30, 20,20, 5,BLACK);
delay(d);
GLCD.ClearScreen();  // clear the LCD
delay(d);
GLCD.FillRect(30, 30, 30, 10, BLACK);
// draws a filled rectangle: x, y, width, height, colour
delay(d);
GLCD.ClearScreen();  // clear the LCD
for (int a=0; a<1000; a++)
{
xc=random(0,127);
yc=random(0, 63);
GLCD.SetDot(xc, yc, BLACK);
// turn on a pixel at xc, yc);
delay(2);
}
GLCD.ClearScreen();
// clear the LCD
}

Now let’s see all of that in action:

You can also send normal characters to your KS0108 LCD. Doing so allows you to display much more information in a smaller physical size than using a character  LCD. Furthermore you can mix graphical functions with character text functions – with some careful display planning you can create quite professional installations. With a standard 5×7 pixel font, you can have eight rows of twenty-one characters each. Doing so is quite easy, we need to use another two #include statements which are detailed in the following example. You don’t need to install any more library files to use this example. Once again, function descriptions are in the sketch.

Example 24.5

/*  Example 24.5 - KS0108 Graphic LCD demonstration #2
http://tronixstuff.com/tutorials > chapter 24  CC by-sa-nc
*/
#include <ks0108.h> //  library for LCD
#include "SystemFont5x7.h"
// we need this for character display, included with ks0108.h download
void setup()
{
GLCD.Init(NON_INVERTED);   // load the GLCD library
GLCD.ClearScreen();
GLCD.SelectFont(System5x7);
// choose font to use (note this needs to match the #include above
}
int j = 24;
void loop()
{
GLCD.ClearScreen();
GLCD.DrawRect(0, 0, 127, 63,BLACK);
GLCD.CursorTo(1, 1);
// set cursor to top left of LCD (uses character coordinates
// not pixel coordinates
GLCD.Puts("Hello, world."); // sends strings to LCD. Does not wrap to next line!
GLCD.CursorTo(1, 2);
GLCD.Puts("I hope you are ");
GLCD.CursorTo(1, 3);
GLCD.Puts("enjoying this");
GLCD.CursorTo(1, 4);
GLCD.Puts("series of lessons. ");
GLCD.CursorTo(1, 5);
GLCD.Puts("This is from ");
GLCD.CursorTo(1, 6);
GLCD.Puts("chapter ");
GLCD.PrintNumber(j); // sends an integer to the LCD. Does not wrap to next line either
GLCD.Puts(".");
delay(3000);
GLCD.ClearScreen();
for (int xx=0; xx<21; xx++)
{
for (int yy=0; yy<8; yy++)
{
GLCD.CursorTo(xx, yy);  // position the text cursor
GLCD.Puts("#");
delay(50);
}
}
delay(1000);
GLCD.ClearScreen();
}

Again,  let’s see all of that in action:

If you’re looking for a very simple way of using character LCD modules, check this out.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

January 8, 2011 - Posted by | arduino, education, LCD, LCD-00710, learning electronics, microcontrollers, tutorial | , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

53 Comments »

  1. John – this is excellent stuff, as usual.

    I wan’t aware it was possible to use a shift register to reduce the number of pins used – I have been working on a project to create a clock and have been struggling to find a couple of free pins so this may work for me, but I have a question: I have created custom characters for alarm status and snooze – will I loose these functions using the shift register?

    Many thanks

    Russ

    Comment by Russ | January 8, 2011 | Reply

  2. Good tutorial. Thanks for sharing

    Comment by eren | January 9, 2011 | Reply

  3. Thnks. Very Good Site.

    Comment by pasha34 | January 9, 2011 | Reply

  4. John, great tutorials! I just wanted to note that I was having difficulties with 24.1 until I hooked pin 5: RW up to ground, like shown here http://arduino.cc/en/uploads/Tutorial/LCD_bb.png. Once I did that, my text displayed correctly.

    Comment by Justin W | January 20, 2011 | Reply

    • Hello Justin
      Thank you very much for pointing out the error, I really appreciate it.
      The article has now been updated.
      cheers
      john

      Comment by John Boxall | January 20, 2011 | Reply

  5. Hey! Got this working!

    Thanks a lot for the tutorial, it’s great!

    Ed

    Comment by Ed | February 20, 2011 | Reply

    • Excellent news! Thank you very much for letting me know.
      Cheers
      john

      Comment by John Boxall | February 20, 2011 | Reply

  6. Hi, have you posted a list of all the components that are required to complete all your tutorials. If not maybe you can make your own kit to go with this series. I am following it from India and would not mind buying all of the stuff required( two of each if possible,so that I can blow stuff out ) at one go.

    1) This would save a lot of time
    2) It will actually be cheaper
    3) Most importantly it will help people stay in the flow of learning for long hours at a stretch.

    As you can see your site is now very popular so it might be a venture worth trying.

    Comment by wowmir | April 1, 2011 | Reply

  7. Is it possible to scroll a single continuously line, but not effect the previously output text? I tried leftToRight() and rightToLeft(), but they don’t seem to do what I’m looking for.

    Comment by JRMN | May 11, 2011 | Reply

    • Yes, it could be done. However some work would be involved. Suggestion would be to put your text in an array of characters, then a loop would display array elements 0~15, then 1~16 etc and also track when the array ended to fill the rest of the line with characters starting again from array element zero.
      cheers
      john

      Comment by John Boxall | May 11, 2011 | Reply

  8. Thanks for the suggestion John, I’ll give that a try.

    Comment by JRMN | May 11, 2011 | Reply

  9. Hi Tronixstuff.

    Ive been following this tutorial, its fantastic. Thankyou.

    One Question….
    My LCD doesnt exactly match the pinout you have given. I can match all the pins ok except one. On the LCD data sheet I have

    Pin1= VSS, Ground, 0v
    Pin2= V0, Input voltage for LCD, “–”
    Pin3 = VDD, Supply votage for logic, 5v

    Pin2 is confusing me as it says ‘input voltage’ but then says ‘–’ in the column where the other two have 0v and 5v.

    What should I do with it?

    Data sheet-
    http://docs-europe.electrocomponents.com/webdocs/0887/0900766b80887814.pdf

    Thankyou

    Comment by Mitchell | June 1, 2011 | Reply

    • Hello
      What an odd LCD unit. According to max ratings on page 4, you can feed it between 0 and supply voltage. So try 5V, as you would already have 5V for pin 3.
      John

      Comment by John Boxall | June 1, 2011 | Reply

  10. Hi John,

    Once again, thanks for a well thought through tutorial!

    Quick question with the LiquidCrystal lcd constructor – Is it possible to pass in analog A1 & A2 pins [set as pinMode(A1, OUTPUT) etc in void setup] in place of digital 5 and 6?
    E.g. LiquidCrystal lcd(12, 8, 7, A2, A1, 4); I’d like to free up digital 5 and 6 for PWM use, don’t wish to use the 4094 & have all the other digital pins in use. (ATmega 328)

    Any hints/code appreciated-
    Cheers and thanks!
    Rich

    Comment by Rich Carthew | June 13, 2011 | Reply

    • Theoretically yes, but I haven’t tried it so cannot be sure. However a lot easier method would be to use an I2C-interface LCD, then you are only using A4/5 and 5V/GND. Adafruit sell an i2c LCD backpack (http://www.adafruit.com/products/292) which solves the problem neatly.
      cheers
      john

      Comment by John Boxall | June 13, 2011 | Reply

      • Thanks John,
        I hadn’t seen those backpack units before – interesting solution and not too bad a $10 a pop. I did try to code the analog pins to do the digital connection prior to posting, however without much success. If I do find out anything interesting, I’ll reply again here for others benefit.
        Cheers,

        Rich

        Comment by Rich Carthew | June 13, 2011

  11. Hi John.
    OK got it working via a hint from liudr on Arduino Forum- thought to post it here in case anyone else finds it useful.

    For anyone else wanting to use an analog pin or two instead of digital pins here’s a summary:
    Beginning with a tested and working LCD module set up in the standard way:
    1. Change (and pass in as arguments) the analog pin numbers you want as their respective digital pin numbers in the lcd function at the top of the sketch e.g. LiquidCrystal lcd(12, 8, 7, 16, 15, 4) where 16 = analog A2 & 15 = analog A1 respectively.
    2. Ensure you rewire correctly once you make the change! (I had the two from the LCD crossed over in error on A1 & A2 instead of the other way as determined by the numbers in 1 (long day),
    3. Set their pinMode’s as OUTPUT e.g. pinMode(15, OUTPUT); would be for Analog 1 == can use pinMode(A1, OUTPUT); as equivalent.

    [i]side note: There is no need to digitalWrite HIGH any analog pins used for this particular example (just in case it occurs for you to do so, as there is mention of doing that in some sections on using analog pins as digital outputs when reading about Arduino. digitalWrite(pin#, HIGH) would be to turn an LED or something on (via a resistor in series) etc.
    [/i]
    Cheers,

    Rich

    Comment by Rich Carthew | June 14, 2011 | Reply

  12. i have a glcd k0108 and a arduino mega, i conect all the wires and make upload of ks0180 and the lcd don´t do anything on serial monitor showm me this Serial initialized
    ——————————————————————–
    GLCD Lib Configuration: glcd ver: 3 glcd_Device ver: 1 gText ver: 1
    Panel Configuration:ks0108
    Pin Configuration:ks0108-Mega
    ——————————————————————–
    GLCD:ks0108 DisplayWidth:128 DisplayHeight:64
    Chips:2 ChipWidth:64 ChipHeight:64
    CSEL1:33(PIN_C4) CSEL2:34(PIN_C3)
    RW:35(PIN_C2) DI:36(PIN_C1) EN:37(PIN_C0)
    D0:22(PIN_A0) D1:23(PIN_A1) D2:24(PIN_A2) D3:25(PIN_A3)
    D4:26(PIN_A4) D5:27(PIN_A5) D6:28(PIN_A6) D7:29(PIN_A7)
    Delays: tDDR:320 tAS:140 tDSW:200 tWH:450 tWL:450
    ChipSelects: CHIP0:(33,0×1, 34,0×0) CHIP1:(33,0×0, 34,0×1)
    Data mode: byte
    ——————————————————————–
    Diag Loop: 1
    Initializing GLCD

    please help

    Comment by Nuno | July 15, 2011 | Reply

    • If your wiring is correct and you are happy with the sketch perhaps the screen is faulty. You should contact the people that sold it to you.
      john

      Comment by John Boxall | July 16, 2011 | Reply

  13. I had the same issue Nuno, with exactly the same readout.

    As John indicates, perhaps double check your wiring is correct- and also that the connections are actually good- that was my problem- I had it hooked up on a breadboard correctly, but one of my hookup wires was faulty when I tested them all for continuity.

    Comment by Rich Carthew | July 16, 2011 | Reply

  14. Thanks so much for these excellent tutorials, I’ve learned so much more here than anywhere else.

    Regarding parallel LCD’s, I am interested in experimenting with 8-bit mode, but am unable to find any code examples that will allow me to initialise the display in this manner. Can you point me at some tips and tricks for using 8-bit mode? Everyone seems to be phobic about using up the additional four pins, but I have a few to spare and would like to see if there are any advantages to it over 4-bit.

    Thanks, and please keep making us smarter, one tutorial at a time!

    Comment by Mr. Sharkey | December 9, 2011 | Reply

    • Hello, glad you are enjoying the site.
      8-bit mode is described in the official Arduino reference here – http://arduino.cc/en/Reference/LiquidCrystalConstructor
      Can’t say I’ve ever tried it, however you might experience a slight increase in display update speed.
      cheers
      john

      Comment by John Boxall | December 9, 2011 | Reply

      • Yes, thanks for that. I had attempted to search out that very information, but each and every 4-bit description starts out telling that 8-bit is possible, but then fails to describe the 8-bit mode setup. Made searching very frustrating, many false positive returns.

        Comment by Mr. Sharkey | December 10, 2011

      • To be honest 8-bit mode is pretty well moot, Arduino isn’t made for speed.

        Comment by John Boxall | December 10, 2011

  15. A follow-up report on 8-bit mode:

    Although the display doesn’t refresh any faster that I can see, it is more stable. Under 4-bit mode, I was seeing the individual pixels blink on and off in a scrolling pattern when the contrast was set very low (Vo controlled by a PWM pin on the Arduino) or when viewing the display from an odd angle above. Now that blinkyness is gone. I’m well satisfied, and the use of the additional pins doesn’t affect my project in the least.

    Comment by Mr. Sharkey | December 10, 2011 | Reply

  16. controlling each pixel was great, it make good graphics
    thanks, learning sth new.

    Comment by sudip | December 24, 2011 | Reply

  17. I’m having an issue with a KS0108B panel, in that adjustments to the pot make no difference to the screen, it’s always blank. I’m using a 10k pot, with the slider (middle pin) on pin 3 of the LCD, left pin of the pot to gnd, and the right pin to pin 18 of the LCD. Any idea what I may be doing wrong?

    Comment by Runes | January 5, 2012 | Reply

    • Could be another issue, sorry to be vague but all I can suggest is double-check the other wires, sketch etc.

      Comment by John Boxall | January 5, 2012 | Reply

      • Yeesh. I must have taken it apart and put it back together a half-dozen times. Took it apart, tested all the wires for connectivity, put it back on a new breadboard, and now it works. Thanks, John, sometimes it is indeed the simplest things.

        Comment by Runes | January 5, 2012

      • No worries, it happens to all of us. :)

        Comment by John Boxall | January 5, 2012

  18. Great tutorial. For those who try this out, PAY HEED TO THE COMMENT ABOUT CHECKING THE BACKLIGHT VOLTAGE. IF THE BACKLIGHT VOLTAGE IS LESS THAN 5V, DON’T MAKE A CONNECTION BETWEEN PINS 2 AND 15.

    After seeing John’s comment on Sparkfun’s LCD-00255 display, I hooked one up as shown in the first circuit diagram above. This put 5V to the backlight, which apparently fried it. Only then did I read that the max backlight voltage is 4.7 V for that display. A current-limiting resistor probably would have saved it.

    Oh well, it was worth it to learn how to use the display. They’re cheap.

    Comment by David | January 12, 2012 | Reply

  19. Update on above comment….

    The backlight on my Sparkfun LCD-00255 display was NOT fried. There must be some sort of overvoltage protection.

    A different display (a Microtivity IM161) came with a 1N4004 diode with instructions to use it to drop the voltage for the backlight. The 1N4004 has a forward voltage drop of 0.8V, bringing the backlight voltage down to 4.2V. I tried the diode with the Sparkfun display, and the backlight works. Nice.

    Comment by David | January 12, 2012 | Reply

    • Phew – glad to hear it works for you!
      Have fun
      john

      Comment by John Boxall | January 12, 2012 | Reply

  20. Thanks for your turtorial,it helps me a lot.

    Comment by Jack | March 5, 2012 | Reply

  21. Hello John!
    I find your tutorial very informative, like seeing light at the end of a tunnel. :)
    However, i have a few clarifications, which is really helpful for a school project.
    1. i want the text generation to be activated by a button. like, once i press the button, the text will be shown.
    2. i want a random number to be included as well, for example, “you are (random number from 0 to 70) years old”.
    what kind of modifications in the code should i do?

    Comment by Rain | March 14, 2012 | Reply

    • It is not a modification, you need to write your own sketch. Review the first few chapters as well as the LCD chapter and you will learn the knowledge to do what you want.

      Comment by John Boxall | March 15, 2012 | Reply

  22. Concerning the KS0108B parallel interface:

    You have one leg of the potentiometer connected to pin 18 (VEE), another leg connected to ground, and the center pin connected to pin 3 (A0) of the KS0108B. The KS0108B’s datasheet, on the other hand, shows one leg of the potentiometer connected to +5V, another connected to pin 18 (VEE), and the potentiometer’s center pin again connected to pin 3 (A0). Why did you set it up the way you did?

    Also, why do you have 5V for the LCD’s backlight when the datasheet says 4.2V?

    I’m new to electronics, so forgive me if my questions appear naive.

    Comment by Adrian Lopez | March 25, 2012 | Reply

    • If using the Sparkfun model as demonstrated it works as described. Furthermore this model has a 5V backlight. If using LCDs from other sources you may need to modify things.

      Comment by John Boxall | March 25, 2012 | Reply

      • I’m looking at the SparkFun model of the LCD (sku LCD-00710). It’s the same datasheet as the one you linked to above, with 4.2V for the backlight (see page 3) and the contrast potentiometer connected to +5V instead of ground (see page 9). I’m trying to understand the discrepancy: Does the wiring work either way or am I not reading the datasheet correctly?

        Comment by Adrian Lopez | March 25, 2012

      • OK I built it up again using my instructions and it worked. Either the screens are 5V tolerant or Sparkfun have changed the specification since I wrote the article (January 2011). If you are unsure use a resistor to drop the voltage to 4.2V.
        cheers
        john

        Comment by John Boxall | March 26, 2012

      • Thank you. I’ll try following the datasheet as best I can, as I suspect it may indeed be a different revision. This might explain not only the backlight voltage differences, but also the differences in the wiring of the contrast potentiometer (per SparkFun’s claim that the latest module “includes the negative voltage circuitry on board.”).

        Comment by Adrian Lopez | March 27, 2012

  23. Hi John,

    Thanks a lot for your great and clearly tutorial about LCD Crystal. I’m trying to make a module using HEF 4094 in the middle of Arduino and LCD. I see that in your tutorial, there’s a problem about the timing when using 4094 IC.

    I googled by myself and find an interesting forum post on how to fix this problem.
    Here’s the forum post: http://arduino.cc/forum/index.php?topic=115987.0
    And here’s the library: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

    The problem caused by the library in Arduino SDK. This library has optimized some code to boost the display performance up.

    Hope people will read this comment and don’t worry about using shift register IC to drive LCD crystal (like me).

    johnmach
    (from http://machtudong.vn)

    Comment by johnmach | November 13, 2012 | Reply

  24. I Really love these tutorials, is challenging and I learn. I think my question has been answered above but want to verify as these 2×16 LCD displays are expensive. I have a Topway LMB162ABC. It appears that the Backlight is 4.9 v if I read the spec correctly. Want to very that a 1n4001 will work as if I understand it will drop the 5v input to 4.2 v for the backlight. I appoligize in advance if my post is trivial.

    Comment by Rick | December 6, 2012 | Reply

    • Hi Rick, thanks for your feedback. The diode will give you a 0.7V voltage drop.
      cheers

      Comment by John Boxall | December 6, 2012 | Reply

      • I was able to get the tutorial done and am quite pleased and will try some other parts of the examples. Found out that the backlight on my Topway LMB162abc will work just fine with the 3.3v pin from the Arduino Uno. Did have issue with black boxes on the second line of the display at first, found that my solder job for the male 16 pin header was not good on three pins. Hope you have more tutorials planned, I would love to see a do it yourself WiFi from scratch.

        Comment by Rick | December 10, 2012

      • Nice to hear you’re enjoying it. DIY WiFi? No hope :)

        Comment by John Boxall | December 11, 2012

  25. sir how about with a password with keypad?

    Comment by Emmanuel | February 7, 2013 | Reply


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 3,839 other followers

%d bloggers like this: