Go Down

Topic: LCD 12C not changing line after 16 digits (Read 937 times) 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?

regards

Ruud

Grumpy_Mike

Quote
Does anybody know this problem?

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

Quote
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.

MAS3

Hi.
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] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
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
  lcd.backlight();
  lcd.setCursor(x,y);
  Serial.begin(9600);
  pinMode(pbutton, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
 
}
 
void loop(){
  char key = keypad.getKey();
 
  if (key){
    lcd.write(key);
    x=x+1;
    if (x > 15) {
      y =!y;
      x = 0;
    }
  }
  lcd.setCursor(x,y);
 
buttonState = digitalRead(pbutton);
if (buttonState == HIGH){
   lcd.clear();
  digitalWrite(ledPin1,LOW);
  digitalWrite(ledPin2, HIGH);

  }
  else{
    digitalWrite(ledPin1,HIGH);
digitalWrite(ledPin2, LOW);
}
  }


robtillaart

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

[code]
int x = 0;
int y = 0;

....

if (key){
    lcd.write(key);
    x=x+1;
    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)

floresta

Quote
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)


Don

bperrybap



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

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