Search code examples
c++carduinolcd

Arduino LCD only display fisrt 16 characters on line 1 and 41 to 46 caracters in line 2


when I use <LiquidCrystal.h library and lcd-write() it only show the first 16 char in the fist row and start in the 41st char in the second row.

I started with lcd.begin(16,2).

Here an example of the code. The result of this code will be: row 1: 0123456789112345

row 2: 4123456789

#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  Serial.begin(9600);
  lcd.print("0123456789");
  lcd.print("1123456789");
  lcd.print("2123456789");
  lcd.print("3123456789");
  lcd.print("4123456789");
}
void loop() {
}

Its that the expected functionality? There are a way so I can get the 17th char be displayed in second row.


Solution

  • Yes, that is the expected behaviour. The library allows you to control HD44780-based LCD modules. This LCD controller can drive displays up to 40 character by 2 lines in size. When you use a smaller module, the lines are still stored in the same locations in the DDRAM: the first line starts at location 0, the second line starts at location 40. See the datasheet for more information:

    https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

    You can use the entire memory and scroll left and right since the 16-character wide display is a window into the DDRAM. You can use the scrollDisplayLeft and scrollDisplayRight to shift the display left and right. These functions change which DDRAM address is used for the first character on the far left of the display. Both lines scroll in unison.