lcd.print in Loop() help needed

Hi,

I'm having difficulty getting my 16x2 lcd to print correctly while in a loop. I can get it to work if I add a home() to a print that is <16 characters, otherwise it just fill the lcd with "testtesttest..." on both rows. My problem is I need to print a sentence so I want it to scroll. I've tried autscroll with both home() on and off. It looks like the screen is updating too fast, but maybe something else is going on. Also I can't use a delay, because I need to have the Arduino continue to read inputs while it's printing. Any suggestions?

#include <LiquidCrystal.h>
const int rs = 22, en = 24, d4 = 30, d5 = 32, d6 = 34, d7 = 36;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // put your setup code here, to run once:
 lcd.begin(20, 2);
}

void loop() {
  // put your main code here, to run repeatedly:
  //lcd.home(); //Prints correctly with home uncommented
  lcd.print("test");

  // Comment out the print above and run the print below
  // .. with home() on, it prints but if autoscroll is turned on it doesn't
  // autoscroll b/c it doesn't print the whole sentence;

  //lcd.autoscroll();
  //lcd.print("This doesn't print correctly"); 
}

my 16x2 lcd

lcd.begin(20, 2);

I think that the begin is wrong.

My problem is I need to print a sentence so I want it to scroll.

The hd44780 library has a linewrap function that will wrap long lines correctly. You would use the hd44780_pinIO class. In the [File]->Examples->hd44780->ioClass->hd44780_pinIO folder there is an example that shows how to use the lineWrap() function. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

It looks like the screen is updating too fast

You can control the update rate of the display by using millis() to time the updates. See the blink without delay example in the IDE examples. Use the lcd.setCursor() function to set where printing begins.

#include <LiquidCrystal.h>
const int rs = 22, en = 24, d4 = 30, d5 = 32, d6 = 34, d7 = 36;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

unsigned long lcdTimer = 0;
unsigned long lcdInterval = 500;

void setup()
{
   // put your setup code here, to run once:
   lcd.begin(16, 2);
}

void loop()
{
   if (millis() - lcdTimer >= lcdInterval)
   {
      lcdTimer = millis();
      lcd.setCursor(5, 0);
      lcd.print("test");
      lcd.setCursor(0, 1);
      lcd.print(millis());
   }
}

Ran your original skectch sketch both in 20,2 and 16,2 modes on a 16*2 LCD driven by an Arduino Nano,
(under LiquidCrystal lcd (12, 11, 5, 4, 3, 2):wink: and all I got was a fast repetition of (error message ?) the letters GWF7