Go Down

Topic: LCD 12C not changing line after 16 digits (Read 1 time) previous topic - next topic


Hello everybody,

I connected a LCD 12C to my arduino uno. It is working well but I have issue with it.
After writing the first line of 16 digits,  I have to continue typing 23 more digits that don't show before it switches to the next line.  Is that a programming problem, or a problem in the LCD?
Does anybody know this problem? What could be the solution?




Does anybody know this problem?

Yes it happens all the time with LCD displays, the display locations are not contiguous.

What could be the solution?

You have to keep track of where you are printing and skip the appropriate number of locations or set the cursor at breaks.
It is a pain in the arse but that's the way life is.


This is normal.
The controller is good for 2 lines of 40 characters each.
So set your cursor to the next line if you are over character number 15.
You can do this by using the next line:

Code: [Select]

lcd.setCursor(12,0);/puts the cursor at position 12 of the first line (line 0)
 lcd.setCursor(6,1);/puts the cursor at position 6 of the second line (line 1)

Did you setup your display ?
Maybe you should post your code for us to see what could be done different.

En kijk eens onderaan in dit forum.
Daar kun je in het Nederlands communiceren.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html


Thank you Grumpy Mike,

I fixed it by adding 2 variables x and y for the lcd.setCursor(x,y)
I added on typing x = x+1 with a max of 15
y is a boolean and changes when x >15

here is the entire script:

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27,16,2);

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {6,5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10,9,8, 7}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int pbutton = A0;
const int ledPin1 = 13;
const int ledPin2 = 12;

int buttonState = 0;
int x = 0;
boolean y = false;

void setup(){
   lcd.init();                      // initialize the lcd
  pinMode(pbutton, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
void loop(){
  char key = keypad.getKey();
  if (key){
    if (x > 15) {
      y =!y;
      x = 0;
buttonState = digitalRead(pbutton);
if (buttonState == HIGH){
  digitalWrite(ledPin2, HIGH);

digitalWrite(ledPin2, LOW);


Code: [Select]
Your fix is not 100% but in the right direction:

You should make y an int too.
The reason is that all values not zero are true, but values bigger than 1 (or 3) do not make sense for the LCD screen

int x = 0;
int y = 0;


if (key){
    if (x > 15) {
      y = 1 - y;  // toggles between 1 and 0
      x = 0;

if programs get complexer it is good practice to set the position directly before the write as the x and y can be changed anywhere

2 style points:

if you press CTRL-T in the IDE your sketch will auto-indent (makes it even more readable)

if you post code please use the # button to get [ code] [/code] tags (you still can modify your post)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


After writing the first line of 16 digits,  I have to continue typing 23 more digits that don't show before it switches to the next line.  Is that a programming problem, or a problem in the LCD?

As others have mentioned that is the way the LCD controller works.  For a complete description of what is happening follow the LCD Addressing link at http://web.alfredstate.edu/weimandn.

Others have already written libraries that deal with this phenomena.  One such library is liquidcrystal440 (originally written to deal with 40x4 displays, hence the name).  
To get a copy start here:--> http://code.google.com/p/liquidcrystal440/ and follow the Downloads link to get to the latest version.

I believe that the 'new' liquid crystal library also does line wrapping as you expect.  (https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home)



I believe that the 'new' liquid crystal library also does line wrapping as you expect.  (https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home)

While fms' library handles multiple communication interfaces, it doesn't deal with wrapping or scrolling.
The LiquidCrystalFast library on Paul's site does, http://www.pjrc.com/teensy/td_libs_LiquidCrystal.html
but it doesn't support i2c.
That library handles line wrapping very nicely, including taking into consideration the direction
of printing (left to right vs right to left).

--- bill

Go Up