Loading...
Pages: [1]   Go Down
Author Topic: [Beginer] How can I use my LCD to display the Serial.print() and Serial input  (Read 280 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 218
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good morning.

I just get a LCD with 16 col and 4 ligns

I would like to use it to display the Welcome text and all Serial input and all Serial.print().

I am woriking with Arduino Uno.

I imported the library

#include <LiquidCrystal.h>

First issue:
and at the setup() I enter this
Code:
  lcd.begin(16, 4);

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 0);
  // Print a message to the LCD.
  lcd.print("****************"); // Display 16x* at the first lign
  lcd.print("*** Wellcome ***"); // Display those 16 caracter at the lign 2
  lcd.print("*** to iBip ****"); // Display those 16 catacters at the lign 3
  lcd.print("***************"); // Display those 16 starts at the last lign

  delay(5000);
  lcd.clear(); // Clear the screen

As there is 16 col, I suppose the nect caracter will go to the second lign, but it does not goe to the 3 lign.

Then I tried to use
Code:
  lcd.setCursor(0, 1);
  lcd.print("*** Wellcome ***"); // Display those 16 caracter at the lign 2
lcd.setCursor(0, 2);
  lcd.print("*** to iBip ****"); // Display those 16 catacters at the lign 3
lcd.setCursor(0, 1); 
lcd.print("***************"); // Display those 16 starts at the last lign

But it work only for the 2nd lign. The third lign is displayed form the 7col......

Second problem

I want to diaplay the Serial input. I have that function which display in Terminal
Code:
String getMessage() {
  String s="";
  while(1) {
    if(cell.available()>0) {
      s = s+(char)cell.read();
      if (s.length()>1 && s[s.length()-2]=='\r' && s[s.length()-1]=='\n') { // if last 2 chars are \r\n
        if (s==" \r\n" || s=="\r\n") { // skip these, move on
          s="";
        }
        else { // we have a message!
          #ifdef DEBUG
          Serial.println(s.substring(0,s.length()-2));
          #endif
          lcd.print(s.substring(0,s.length()-2));
         
          return s.substring(0,s.length()-2);
        }
      }
    }
  }
}

It works but I want to have each new message in a new lign.

Third problem
When my display is full. When all lign are showing a message. I would to have the
- The Second lign displayed at the lign 1
- The third lign display at lign 2
- The last lign displaed at lign 3
- The new message at lign 4.

How can I do it??

I check autoscroll, but auto scroll display the carater after the last and not a a new lign.

In fact, I would like to have exactely what does the terminal, but in a LCD.

Could you help me for my first LCD task??
Do you know some tutorials

Many thank
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 218
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there not a function like this

Code:
lcd.println(s.substring(0,s.length()-2));

Which place the cursor to a new lign after the end of the message and move up the displayed text if it take 4 lign?
Logged

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

Part of your problem stems from the characteristics of the display and part from a deficiency in the LiquidCrystal library.

The display was not designed to replace a CRT or LCD display such as that on a computer.  It was designed to display short messages such as 'add toner' or 'fire in zone 3' and there was no real need to implement the <CR> or <LF> control codes.

Also, due to the memory implementation required by the vintage of the controller, you will find that the display will proceed from line 1 to line 3, then to line 2, and finally to line 4.  To find out more about the reasons for this you can follow the LCD Addressing link at http://web.alfredstate.edu/weimandn.

The reason for the 7 column offset on two of the lines is due to the fact that the LiquidCrystal library does not use the correct starting addresses for those lines on a 16x4 display.

Some of these problems were addressed when the LiquidCrystal440 library was developed a few years ago.  To get a copy start here:--> http://code.google.com/p/liquidcrystal440/ and follow the Downloads link to get to the latest version.

There is also a 'new' LiquidCrystal replacement library available that probably deals with at least some of these issues as well.  You can find information about that library here --> https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home <--.  

Don
Logged

Pages: [1]   Go Up
Print
 
Jump to: