serial display I2c beginner

Greetings , complete beginner here,I think I have just figured out addressing ,initializing,and library basics. I am learning by deductive reasoning and basically altering existing code to my requirements. Not really a true understanding but a partial view that works as I discover. It was a task to get the I2c 20x4 LCD to work with the uno I now have a functioning display but the lines of text resolve line 1 ,3, 2,4. Rather than 1,2,3,4,. the sketch is

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address

void setup()
lcd.init(); // initialize the lcd

Serial.begin(9600); // Used to type in characters

//-------- Write characters on the display ----------------
// NOTE: Cursor Position: CHAR, LINE) start at 0
lcd.setCursor(3,0); //Start at character 4 on line 0
lcd.print(“Hello, world!”);
lcd.print(“From pharoah”);
lcd.print(“20 by 4 Line Display”);

// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to “No Line Ending”)
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print(“Start Serial Monitor”);
lcd.print(“Type chars 2 display”);

}/–(end setup )—/

void loop() /----( LOOP: RUNS CONSTANTLY )----/
// when characters arrive over the serial port…
if (Serial.available()) {
// wait a bit for the entire message to arrive
// clear the screen
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD

}/* --(end main loop )-- */

/* ( THE END ) */

is there a particular reason why you are using both lcd.write( ) and lcd.print( )

Is the problem with the line ordering occuring in your setup( ) message, or in loop( ), or both.

You should also consider the possibility that the 4-line LCD is actually designed to work that way, for some reason.

problem occurs in loop only, thanx

quote : "You should also consider the possibility that the 4-line LCD is actually designed to work that way, for some reason."

does that explain something. I am seeking a flow of type ,20 characters per line on 4 lines, this works for the set up not the loop.

As noted I have taken known sketch code and cut and pasted it to compile and display for me , in loop if I use "lcd print() " rather than "lcd write()" all I get is a full screen of numerals , not the dedicated type as wrote in the serial monitor.

If that display is based on the 44780 driver chip, the LCD lines are in this order - 1, 3, 2, 4 . It has to do with the way the chip itself is designed and also the PCB layout for the display. Ran into this very problem many years ago with a few different Densitron 4 X 20 LCD's for a toxics monitoring system !! Just recently connected a 4 x 20 line LCD to my Arduino and that is when I remembered this - memory just not what it used to be !!!!

While I understand your back and paste method of learning, enough can't be said of doing a little reading. Those four line LCDs often have the lines numbered 1 3 2 4. I suggest you RTFM on your LCD and see if that isn't the case for this one.

So the expertise shared is "that's it, that's all". I didn't have to " do a little reading " to figure that the lcd was designed 1324. That was the question, any answers.I have the setup working sequencing a 4 line display , in the loop with the serial monitor sending to display are there logic commands that circumvent the sequence and allow a 1234 display of info sent. Should I have stayed with a 16x2 lcd with the 44780 driver.

are there logic commands that circumvent the sequence and allow a 1234 display of info sent.

You just have to take it into consideration when you write the program. You can't change it, it is a consequence of the way some LCDs are put together. Line 3 is the second line and line 2 is the third line. You'll have to write your program in such a way that it takes that into account.

I guess you could write your own functions that switch the numbers and then call the functions from the LiquidCrystal library from there.

Something like (but maybe not exactly):

void setCursor(int x, int y){
     if(x == 2) x=3;
     else if (x==3) x=2;

Then use the set of functions you write instead of making calls to the LiquidCrystal functions in the rest of your program.

I can not see the problem unless you overflow a line

lcd.setCursor(0,0); will get you on line 1

lcd.setCursor(0,1); will get you on line 2

lcd.setCursor(0,2); will get you on line 3

lcd.setCursor(0,3); will get you on line 4

if you overflow 0 then it starts again on line 3
if you overflow 3 it overflows to line 1

but as theres no plan to write move than 20 digits that really shouldn't matter

funny that my code uses

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

this sets the address and pins then


to set the display

mine was a cheap one as the ic2 interface will only allow on and off for the back light instead of accepting a number to set the level

be real careful when using lcd.clear() as it will cause the last 2 lines to fade out if you add it all over the place.
I set mine to only clear with a major change of data all other times it just over writes a set area of the screen

I use lots of those 420 LCDs, and never seen one where the lines were not properly ordered 1-2-3-4. But, if you have one that’s like that, just modify the LCD library to re-map them - it would take one line of code:

row = (row & 1) ^^ (row & 2) ? row ^ 3 : row;

Ray L.

Thank you all that has been helpful and instructive. I now have a sense of what is required.