LCD going to next line

I have a LiquidCrystal I2C display and i'm trying to make long scrolling text, but it just goes over to next line. What happens (lcd is 16x2)


long message tha
croll on the scre


#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

const char msg[] = "Hello, this is a long message that will scroll on the screen 1234 abcdefg !@#$%^&*()";
void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print(msg);
}
void loop() {
  lcd.setCursor(0,0);
  for (int i=0; i < sizeof(msg) + 1; i++) {
    lcd.scrollDisplayLeft();
    delay(300);
  }
}

I think i'm doing something wrong here.

[sterretje edit]
adjust formatting of text
[/sterretje end]

I've modified the formatting.

Three or more dashes (---) immediately following text has a special meaning on the forum. I've added an empty line to fix it so it looks "normal".

this call just scrolls whatever is on the display left

there is no notion of hidden characters that would be at the end of the line. it just overwrites the characters that are in column 0 with the ones from column1, those from column 1 with the ones from column 2 etc and you get an empty space in the last column.

When you position the cursor somewhere and send some text to print, you need to ensure you don't go past the end of the line otherwise the text will flow to other lines and not in sequence.

On a 2040 LCD (4 lines, 20 positions), if you try to print at (0,0)
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?;:=+/$()[]&<>@#-*";
you'll see


that is the first line overflows in the 3rd then you go to the 2nd and then the 4th.

On a 1602 LCD (2 lines, 16 positions) I think the behavior is the same and you'll write to a non existing line 3 after line 1 and come back to line 2 and then a virtual line 4

1 Like

If you really want to know how this works then go here --> LCD Addressing .

Don

1 Like

Are you trying to scroll the message across the first row only?

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

const char msg[] = "Hello, this is a long message that will scroll on the screen 1234 abcdefg !@#$%^&*()                "; // 16 blank spaces to scroll the text off the line
const int screenWidth = 16, msgSize = sizeof(msg); // chagracters in array
char page[screenWidth]; // a row of characters for the LCD

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
}

void loop() {
  for (int i = 0; i < msgSize - screenWidth; i++) { // stop one "row" before end of message
    for (int j = 0; j < screenWidth; j++) { // 16 characters
      page[j] = msg[i + j]; // create a new page (LCD line) to print
    }
    lcd.setCursor(0, 0); // cursor home
    lcd.print(page); // print new page
    delay(100);
  }
}
1 Like

in this thread you will find two examples:

one is using the LCD scroll function which will effect all lines
the second example srcolls on one line only.

yeah, i wanna have scrolling text on first line and have seperate control for second line ( is it possible to make 1 line scroll left and the other one scroll right?)

it's possible but you have to handle that yourself, not with the lcd.scrollDisplayLeft() type of functions

see what @noiasca or @xfpd have proposed

The idea from post #5 is to create "pages" the width of one LCD line starting at the character position, counting from 0 to the length of the message. I found later that I needed one screen of "spaces" to have the message scroll off the page.

For scrolling left to right (we normally read left to right, but we scroll right to left)... that's a little strange to impossible to read (coding is not impossible)... who can read a sentence from right to left (end to beginning)?

I would say you do NOT want scrolling left to right.

yes it is possible - and was linked already in post #6

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.