Pages: [1]   Go Down
Author Topic: how to make 2 rows in Serial Display?  (Read 671 times)
0 Members and 1 Guest are viewing this topic.
Malaysia
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Stay calm and call batman!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys! got a new LCD module. i am using the liquid display sketch from the arduino. However i cannot get more than 16 digits in a row. what i want is for the text to go to the second row.

Code:
// include the library 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.write(Serial.read());
    }
  }
}

anyone knows how to make the excess text to the second row? thanks!
Logged

Quebec
Offline Offline
Jr. Member
**
Karma: 3
Posts: 78
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should count the characters and when you reach 16 jump to the second line


Code:
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();
    int nbchars=0;
    // read all the available characters
    while (Serial.available() && i<16) {
      // display each character to the LCD
      lcd.write(Serial.read());
      nbchars++;
    }
    lcd.setCursor(0, 1);
    while (Serial.available()) {
      // display remaining characters on the second line
      lcd.write(Serial.read());
    }
  }
}
Logged

Malaysia
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Stay calm and call batman!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey thanks for the reply, will work on it with your help =) happy easter!
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 47
Posts: 2268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys! got a new LCD module. i am using the liquid display sketch from the arduino. However i cannot get more than 16 digits in a row. what i want is for the text to go to the second row.




anyone knows how to make the excess text to the second row? thanks!

I think yopu are looking for the cursor commands.  In the code below, a reading is put at the start of the first row (0) and then chr 11, then the same at start and chr 11 on the second row.

Code:
lcd.setCursor (0,0);
  lcd.print(InTemp);
  lcd.setCursor (11,0);
  lcd.print (OutTemp);
  lcd.setCursor(0,1);
  lcd.print(diff);
  lcd.print(" ");
  lcd.setCursor(11,1);
  lcd.print(DrainTemp);
Logged

Malaysia
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Stay calm and call batman!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello, do i add the command in void loop? because it cant compile
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 47
Posts: 2268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes. It is just a snippet and certainly won't compile by itself. It was just intended to show how the cursor command works but, if you put your own variables in, it should give you a display.
Logged

Pages: [1]   Go Up
Jump to: