Pages: [1]   Go Down
Author Topic: Serial to LCD - How to display second line on 16 x 2  (Read 1455 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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:


Code:
#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
« Last Edit: July 16, 2012, 09:26:40 am by floresta » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
« Last Edit: July 16, 2012, 09:24:32 am by dxw00d » Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 (11.81 KB, 300x115 - viewed 16 times.)

* serialdisplay.jpg (26.46 KB, 387x272 - viewed 14 times.)
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I would call this DisplaySerial or DisplayOfSerial myself.
I agree. It is badly named.
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here is the output from my 16x2 LCD
That is absolutely normal and is just as described in my earlier link.

Quote
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: http://code.google.com/p/liquidcrystal440/


Don
Logged

Dallas, TX USA
Online Online
Edison Member
*
Karma: 47
Posts: 2326
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

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

 smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
// 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++;
}
Logged

Pages: [1]   Go Up
Jump to: