LCD 4x20 strange line order

Hello Everyone,
Can somebody tell me why the LCD dont print the sentences in the right order?
The order now is
first row 1
second row 3
third row 2
forth row 4

I already read some things about this issue, but I still don’t understand how to fix it.
I’m using a Arduino uno and a 4x20 lcd screen. with an I2C Interface.
Thank you very much for your help!

/-----( Import needed libraries )-----/
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>

// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library “Docs” folder for possible commands etc.

/-----( Declare Constants )-----/
//none
/-----( Declare objects )-----/
// set the LCD address to 0x20 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
const int numRows = 4;
const int numCols = 20;

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

/////////////////////////////////////////////////////
char *actors=
{ “test sentence 1, test sentence 1?”,
“test sentence 2, test sentence 2?”,
“test sentence 3, test sentence 3?”,
“test sentence 4, test sentence 4?”,
“test sentence 5, test sentence 5?”,
};
long actor1;

void setup()
{
Serial.begin(9600);
randomSeed(666);
lcd.begin(20,4); // initialize the lcd for 20 chars 4 lines and turn on backlight
}

void loop()
{
actor1 = random(sizeof(actors)/sizeof(char*));
lcd.setCursor(0,1);
lcd.print(actors[actor1]);
delay(1000);
lcd.clear();
}

That's how it works.

So the rule is; it is your business in coding to write only as much as fits on one line, and use the set cursor command to pick on which line you wish to print just enough characters to fit on that line.

Can somebody tell me why the LCD dont print the sentences in the right order?

Yes. You will find a complete description if you follow the LCD Addressing link at http://web.alfredstate.edu/weimandn .

Don

Alright, Thanks. I was hoping it could be easier..

tuusje8:
Alright, Thanks. I was hoping it could be easier..

Well, no, it isn't really a matter of "could be easier".

These displays are neither intended nor particularly suitable for output of random text - for that, you want a proper computer monitor. You may perhaps be thinking of SMSs on your phone but even then you would have overlooked something subtle but important - the phone display does not simply show a stream of characters, but formats each line so that words are not "broken", because they are not properly readable that way. You then would have to do the same thing to display random text so you must always think in terms of what fits on a line.

In practice, what you are generally going to display, will be one (or two) messages per line, and you will want to constrain them to fit on that line (so that they do not interfere with any message on subsequent lines). You will be keeping track of how long each message is, and positioning it using the set cursor command. If you wish to "print" different numbers, then either you determine the size of each, or use printing commands which determine the format. A common concern is overprinting a smaller (narrower) number following a larger one and not blanking the excess digit(s) of the previous number.

So overall, it is not going to be "easier" - you are responsible for every character. This is what we call "programming". :sunglasses: