how to use the 2 lines in the LCD Serial input tutorial

Hello ,

I did this tutorial http://arduino.cc/en/Tutorial/LiquidCrystalSerial

but the problem is that when I type more than 16 characters , the LCD displays the 1st 16 in the 1st line while there is nothing in the 2nd line . I tried using if conditions and setting the courser but that didnt work .

Does anyone know how to make it display all the charters in both lines when I type more than 16 ?

Copy the code from your IDE window of the program you are loading and post it along with information about your particular lcd. We want to see the actual code from your program , not a link. We know that may not make sense to you but we have our reasons. If you can post a link to the vendor where you got your lcd that would be great. We need to know your lcd specs , (# OF CHARACTERS,# OF LINES)

Does anyone know how to make it display all the charters in both lines when I type more than 8 ?

You haven't mentioned what display you are using but this implies that you have an 8x2 display.

So, did you change the lcd.begin(16, 2); statement to lcd.begin(8, 2);?

That alone won't fix anything since the LiquidCrystal library does not do automatic line feeds at the end of a line so, as you have indicated, you must do your own cursor positioning after the eighth character.

Since your cursor positioning didn't work there may be a problem with the library as there is with the 16x4 but I doubt that this is the problem since the initial addresses for the 8x2 are probably 'standard' whereas those for the 16x4 definitely are not. To check out the addressing we will have to see the datasheet for your display and to check out your your cursor positioning implementation we will have to see your code as the previous post indicates.

Don

sorry I meant
Does anyone know how to make it display all the charters in both lines when I type more than 16

Here is the code

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
    // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
}

void loop()
{
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD

     // lcd.setCursor(0, 0); I added this line to see if it can allow me to write in 2 line but it results in only displaying the 1st character i enter I also tried  lcd.setCursor(0,1)

// what im thinking of doing but I dont know how is to say if all column in row one have characters , then continue with the 1st column in row 2 
// or if the  no of charecters >8 then print the 1st 8 characters in row one and the rest in row 2  
      lcd.write(Serial.read());
    }
  }
}

the LCD is a Hitachi HD44780 compatible LCD 16 by 2 .
I just want to know how to make it write on both lines ( rows ) when the fist line is fully occupied :slight_smile:

I just want to know how to make it write on both lines ( rows ) when the fist line is fully occupied

As I mentioned earlier the LiquidCrystal library does not do automatic line feeds at the end of a line so you must do your own cursor positioning when appropriate.

You accomplish the cursor positioning with the 'set cursor' command (http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor).

Don

Thanks Don . As I said I tried to use the cursor positioning but I'm not able to get how to do the if condition for that . Like I got the 1st if statement which is

if Serial.available() >16 {

// print the 1st 16 in the 1st line starting from lcd.setCursor(0, 0);  and print the rest staring from lcd.setCursor(0, 1) 

}

The commented part is the part that I dont know how to write , I would be grateful if u can help me with that

The commented part is the part that I dont know how to write , I would be grateful if u can help me with that

I don’t normally program in C so it would take me a while to figure out how to implement the solution.

This particular example, like many others that I have seen, seems to have been chosen mainly for it’s brevity rather that for it’s ability to be modified for other uses.

Is there any reason why you have chosen this particular example to implement. If you want a simple example that shows how to use two lines on the LCD take a look at this one:

#include <LiquidCrystal.h>

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);      // put your pin numbers here

void setup()
  {
  lcd.begin(16, 2);                          // put your LCD parameters here
  lcd.print("hello, world!");
  lcd.setCursor(0,1)
  lcd.print("it works!");
  }

void loop()
  {
  }

Don

This may prove annoying, but try this code that was derived from another thread of similar concern.

Note that it requires a tilde character (~) to initialise the message display. If it basically works, re-do it to your satisfaction. Good luck!

/* text printer demo

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int startstring = 0;      // recognition of beginning of new string
int charcount = 0;        // keeps track of total chars on screen

void setup () {

  Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
  lcd.begin(16,2);        // initialize the lcd as 20x4 (16,2 for 16x2)
  lcd.home ();            // go home to character 0 on line 0 (1st line)
  lcd.print(" Text Printer   ");  
  lcd.setCursor(0,1);     // character 0 on line 1 (2nd line)
  lcd.print ("   Version 02 ");

  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);  

  lcd.setCursor(0,0);     // Set cursor position to top left corner
  delay(3000);
  //  Serial.println("Hello, Hello");

}  

void loop() {
  char incomingByte = 0;                             // for incoming serial data

  if (Serial.available() )
  {                                                  // Check for incoming Serial Data
    digitalWrite(13, HIGH);
    incomingByte = Serial.read();
    if ((incomingByte == '~') && (startstring == 1)) // Check for closing '~' to end printing of serial data      
    {
      startstring = 0;                               // Set the printing to off
      delay(5000);                                   // Wait 5 seconds
      lcd.clear();                                   // Wipe the screen
      charcount = 0;                                 // reset the character count to 0
      lcd.setCursor(0,0);                            // reset the cursor to 0,0
    }

    if (startstring == 1){                           // check if the string has begun if first '~' has been read
      if (charcount <= 30){                          // check if charcount is under or equal to 30
        lcd.print(incomingByte);                     // Print the current byte in the serial
        charcount++;                                 // Increment charcount
      }
    }

    if (charcount == 16){                            // if the charcount is equal to 16 aka end first line
      lcd.setCursor(0,1);                            // set cursor to second line
    }

    if (charcount == 31){                            // if the charcount is equal to 31 aka the screen is full
      delay(500);
      lcd.clear();                                   // clear screen
      lcd.setCursor(0,0);                            // set cursor to 0,0
      lcd.print(incomingByte);                       // continue printing data
      charcount = 1;                                 // set charcount back to 1
    }

    if (incomingByte == '~'){                        // Check if byte is marker ~ to start the printing
      startstring = 1;                               // start printing
    }  
  }
  digitalWrite(13, LOW);
  delay(10);                                         // 10ms delay for stability
}