How to lcd.print to a new line every time?

So basically i’m using the Wire library as ‘Master Writer’ & ‘Slave Receiver’

every time data is received i would like the lcd to print (0, 0) and then (0, 1), and then (0, 0) and (0, 1) again instead of just printing (0, 0) and then clearing the display and displaying it (0, 0) again.

Hope that doesn’t sound so bloody confusing (bit of a newbie!)

#include <LiquidCrystal.h>
#include <Wire.h>


const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  lcd.begin(16, 2);
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop() {
  delay(100);
}
void receiveEvent(int howMany)
{

  if (Wire.available()) {
    delay(100);
    lcd.clear();

    while (Wire.available() > 0) {
      char c = Wire.read();
      lcd.print(c);
    }
  }
}

I had also experimented like this

   {
  int charcount;
  boolean secondline;
  if (Wire.available()) {
    delay(100);
    //  lcd.clear();

    charcount = 0;
    secondline = false;
    while (Wire.available() > 0) {
      if (charcount > 15 && secondline == false ) {
        lcd.setCursor(0, 1);
        secondline = true;
        lcd.write(Wire.read());
        charcount++;
    }
  }

  }

Thanks in advance for help

Read this, lcd.setCursor(col, row); https://www.arduino.cc/en/Reference/LiquidCrystalSetCursor

Here is one way: byte col = 0; . . .

lcd.setCursor(col, 1); col++; col = col % 2;

Edit The above goes from one line to the other, use the same technique to move between rows.

Pseudocode:

int whichLine = 0;


//  later in loop:

lcd.setCursor(0, whichLine);
// print your stuff

whichLine = 1 - whichLine;   // Change 0 to 1 or 1 to 0.

Next time through whichLine will be a 1 and then the next time it will be a 0 and the next time a 1...

Thankyou for your replies must appreciated.
Both of your methods seem to work in the same way but its not printing the entire line, just one number on each line from the beginning and end (trying to print “3 is 0” and then “3 is 127” - FYI)

ive tried
lcd.print(c)

and

lcd.write(c)

and

lcd.write(Wire.read());

still with no luck, where am i going wrong?!

Cheers!!

#include <LiquidCrystal.h>
#include <Wire.h>

//byte row = 0;
int whichLine = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  lcd.begin(16, 2);
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop() {
  delay(100);
}
void receiveEvent(int howMany)
{

  if (Wire.available()) {
    delay(100);

    while (Wire.available() > 0) {
      //    lcd.setCursor(0, row);
      lcd.setCursor(0, whichLine);
      char c = Wire.read();
      lcd.print(c);
      //    row++;
      //     row = row % 2;
      whichLine = 1 - whichLine;

    }
  }
}
lcd.setCursor(0, whichLine);  // set cursor to 1st character position.
     char c = Wire.read();  // read 1 character
      lcd.print(c);                 //print the 1 charcter to lcd
      //    row++;
      //     row = row % 2;
      whichLine = 1 - whichLine;  // move to next line

The methods used in Serial input basics can be adapted to I2C reading.

ok well i've tried so many different variations including the examples in serial basics which didn't seem to work. the thing is the lcd prints fine, but as soon as setCursor is involved in has a fit as doesn't print all the characters!?