20 x 4 LCD screen does not display/ use lines in order, help.

I want to know why my 20 x 4 screen will not print row,1,2,3,4 in that order.

They other sketch that I had on would print properly in that order, but the one I have on now for some reason prints row 1 first, then row 3, then 2 and then 4.

I was wondering what part of code might control this issue?

Also I will add, that in one other sketch the characters would only print up to about position 16 or 17, then it would drop down to the next line on the LCD. Would also like to know how that was controlled too.

The problem is almost certainly in the code that you have not shared with us or in the circuit you are using but have not provided. It could, perhaps, be a feature of the hardware that you are using but we don't know what that is either.

Got documentation for the LCD you're using? Some of them don't number the lines in the right order for some reason. On some of them, the lines go 0,2,1,3. If you have a link for the particular LCD you are using, it should have that information.

Take a look at the section on 20x4 lcd's in this document http://web.alfredstate.edu/weimandn/lcd/lcd_addressing/lcd_addressing_index.html

Your current display is acting normally. You will need to count characters and position the cursor when writing more than 20 characters if you want to get output in the rows 0-1-2-3.

They other sketch that I had on would print properly in that order, but the one I have on now for some reason prints row 1 first, then row 3, then 2 and then 4.

Take a look at how they managed cursor position in that sketch. I don't think it was working natively in the manner you say.

This is the code:

It was working fine at the start but , I have merged the LCD and the Keypad code together to make the keypad buttons display on the LCD. I think I may have messed something up there.

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>  
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);


const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {12, 11, 10}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  lcd.begin(20,4);
  lcd.print("Ready for numbers!");
  delay(3000);
  lcd.clear();
}
  
void loop(){
  char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    lcd.print(key);
    
  }
}

Yeah, you know what lcd.setCursor(0,3); needs to be in there…

But hang on. Where abouts does that go?

I understand how it needs to be used like this

my text
lcd.setCursor(0,3);
mytext
lcd.setCursor(0,4);
etc…

But how do I use lcd.setCursor(0,3); on this part of the code?

void loop(){
char key = keypad.getKey();

if (key){
Serial.println(key);
lcd.print(key);

}
}

Thank you

if (key){
    Serial.println(key);
    lcd.print(key);
     }

You do not manage the cursor position before printing. You start at 0,0 after the lcd.clear(), but you have no cursor management after that. When you enter more than 20 numbers you will go to line from line 0 to line 2 based on the memory structure of the lcd controller.

Edit--

But how do I use lcd.setCursor(0,3); on this part of the code?

You will have to count input keys and move the cursor when you want to be on a new line.

One of the older version of LiquidDisplay class has a function(s) to output to lines in "human" order and not in the controller order. But OF does not remember which one, so google it.