Serial to LCD - How to display second line on 16 x 2

I am using the standard serial display example in arduino to write a string on lcd. However if the string is longer then 16 chars, the rest seems truncated. Also it does not wrap to second line.

Can anyone suggest.

Arduino V 1.0.1 | Arduino UNO | Standard LCD library

I am using the standard serial display example in arduino ....

To my knowledge the Arduino IDE does not come with any serial display example. The reason for this is that there is no standardization among the various vendors of serial LCD adapters. On the other hand virtually every parallel interface uses the defacto standard established by Hitachi with its HD44780U controller and this is the one supported by the Arduino IDE.

However if the string is longer then 16 chars, the rest seems truncated. Also it does not wrap to second line.

This is quite normal. You can find an explanation of what is supposed to be happening by following the LCD Addressing link at http://web.alfredstate.edu/weimandn.

Try writing a string of 80 characters and see what happens. Here is a sample sketch for the parallel interface, you will have to modify it for your particular serial setup:

#include <LiquidCrystal.h>

//LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);       // put your pin numbers here

void setup()
  {
    lcd.begin(20, 4);                          // put your LCD parameters here 
    for (char i=47; i<127; i++)                // send 80 consecutive displayable characters to the LCD
      {
        lcd.print(i);
        delay(100);                            // this delay allows you to observe the addressing sequence
      }
  }


void loop()
  {  
  }

Don

To my knowledge the Arduino IDE does not come with any serial display example.

The LiquidCrystal library is supplied with the IDE, and contains a number of example sketches, including SerialDisplay, which reads from serial input, and writes to the LCD.

The LiquidCrystal library is supplied with the IDE, and contains a number of example sketches, including SerialDisplay, which reads from serial input, and writes to the LCD.

Thanks for the clarification. All I can say is that the Arduino version of the English language is infinitely better than my version of the Italian language.

The SerialDisplay example in question forwards data that is received on the serial port of the Arduino to a generic parallel LCD. I would call this DisplaySerial or DisplayOfSerial myself.

My answer to his question (aside from the mention of modifying the code) still stands.

Don

Hello Don,

Thanks you for your suggestion. Here is the output from my 16x2 LCD ( Sorry of bad camera quality of my blackberry)

I think i got the idea of how it can be done when sending data from my arduino. But when i am sending data from my serial port the thing get truncated. Anyways i will try this code in that as well and will post the result.
Thanks again.

IMG-20120718-00649.jpg

serialdisplay.jpg

I would call this DisplaySerial or DisplayOfSerial myself.

I agree. It is badly named.

Here is the output from my 16x2 LCD

That is absolutely normal and is just as described in my earlier link.

I think i got the idea of how it can be done when sending data from my arduino. But when i am sending data from my serial port the thing get truncated. Anyways i will try this code in that as well and will post the result.

The information is not being truncated. It is being stored in the part of the LCD controller RAM that does not correspond to one of the visible locations on your display. The display RAM can accommodate 80 characters but your LCD can only display 32 of them. You would see all of the characters if you had a 40x2 or a 20x4 display although you wouldn't be happy with how they progress from one row to the next on the 20x4.

These displays were not designed to display long strings of information but that shortcoming can be handled by software. You might want to look into the LiquidCrystal440 library (now called LiquidCrystal1.0). It was written to handle 40x4 displays but I believe it also deals with the 'missing' characters on displays such as yours. Start here: Google Code Archive - Long-term storage for Google Code Project Hosting.

Don

Abhisheik,
The IDE supplied LiquidCrystal library does not support line wrapping.
You can switch to the LiquidCrystalFast library which does support line wrapping.
If you send more characters than fit on a line it will wrap to the line below.
When at the bottom, it wraps back to the top.
Here is link to Paul's teensy page where you find the link to it and a bit more about it:
http://www.pjrc.com/teensy/td_libs_LiquidCrystal.html

--- bill

Hello,

Wow! Thanks for the info. I will try that and will let you know how it worked. :slight_smile:

:slight_smile:

HI, I had the same problem and I solved it:

// include the library code:
#include <LiquidCrystal.h>

char inKey;  // Character received from Serial input
uint8_t Cursor = 0;  // Position of cursor, 0 is top left, (rows*columns)-1 is bottom right
uint8_t rows = 2;  // Number rows, will be either 2 or 4
uint8_t columns = 16; // Number of columns, will be 16 or 20
uint8_t characters; // rows * columns

// 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();
    Cursor = 0;
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      inKey = Serial.read();
      LCDDisplay(inKey);
    }
  }
}

void LCDDisplay(char character)
{
  int currentRow = 0;
  characters = rows * columns;
  
  // If Cursor is beyond screen size, get it right
  while (Cursor >= characters)
    Cursor -= characters;
  while (Cursor < 0)
    Cursor += characters;
  
  if (Cursor >= columns)
    currentRow = Cursor/columns;
    
  lcd.setCursor(Cursor%columns, currentRow);
  lcd.write(character);
  
  Cursor++;
}
1 Like

The lcd.print(" "); command will only output up to 16 characters to the first line of the 16 x 2 lcd display.

To output to the second line, use the following command
lcd.setCursor(0, 1);

Then use the lcd.print(" ") command containing the 16 character maximum string for the 2nd line.

No reset or other commands are necessary between the two commands.

// example:
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a 2 line message to the LCD.
lcd.print("Money Talks!");
lcd.setCursor(0, 1);
lcd.print("B S Walks!");
}

Do you have access to a DeLorean or a TARDUS?

You could use one of these to get in touch with the previous posters as they haven't been around for a few years.

Don

What does it have to do with US?

OK, so he's a bit tardy. :grinning:

I knew it wasn't a good idea to steal your line . . .

Don