Understanding LCDs better

I received an Arduino during the holidays and have started messing around with a simple 16x2 LCD.

I’ve successfully put various bits of data up on the screen with no issues. I wanted to configure it to display a message on one line longer than 16 characters so I did the following

lcd.setCursor(0,0);
 if (strlen(message) > 16) {
    for (int x = 0; x < 16; x++) {
      lcd.print(message[x]);
    }
  lcd.setCursor(16,0);
  lcd.autoscroll();
  for (int x = 16; x < strlen(message); x++) {
    lcd.print(message[x]);
    delay(1000);
  }
 }

It adds one additional character to the next column of the first row every second, but after the 40th character (it might be the 39th or 41st) it looks like it automatically drops to the second row, first column. So I see my original text on the first row, and the 41st(ish) character of my char array on the second row.

Am I just hitting the maximum columns allowed per row and it’s auto wrapping or am I missing something in the code I’ve written?

Am I just hitting the maximum columns allowed per row and it's auto wrapping

Yes. This link explains all.

http://web.alfredstate.edu/weimandn/lcd/lcd_addressing/lcd_addressing_index.html

If you shift the display you will be able to view the missing characters.

To shift the display you use what is called scrolling in Arduinoese - go figure.

Don

Thanks Cattledog, that was exactly what I was looking for.

@floresta, there weren’t any missing characters I already had autoscroll turned on :wink:

If anyone’s interested, here’s the solution I came up with so it would only scroll on the top line

/*
  LiquidCrystal Library - display() and noDisplay()
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD and uses the 
 display() and noDisplay() functions to turn on and off
 the display.
 
 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe 
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/LiquidCrystalDisplay

 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Enter a messege for it to print on the LCD
char messege[] = "hello, world! I'm curious what it will do with a long messege.";
// variable to count which position to start messege at
int iterate = 0;  

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // disable scrolling
  lcd.noAutoscroll();
}

void loop() {
  // Set cursor to first column, first row
 lcd.setCursor(0,0);
 /* If the messege is greater than sixteen characters
 print one line (16 characters) starting at the current
 iteration position*/
 if (strlen(messege) > 16) {
    for ( int x = iterate; x < iterate+16; x++) {
      lcd.print(messege[x]);
    }
    // Move to the second row, display what itteration the messege is one
    // and how long the total messege is
      lcd.setCursor(0,1);
      lcd.print(iterate);
      lcd.print("  ");
      lcd.print("Length: ");
      lcd.print(strlen(messege));
    }
    // If the messege is less than (or equal to) 16 characters, just display the messege
 else { 
 lcd.print(messege);
 }
 // increases starting posistion
 iterate++;
 
 // once the iteration is greater the messege length, start over
 if (iterate > strlen(messege)-16){
   iterate = 0;
   delay(1500);
   lcd.clear();
 }
 delay (300);
}