LCD Autoscroll input get from serial monitor

hi everyone. i have a question here. i want to display the character received from serial monitor & display it to 16x2 LCD Display. for character 1 until 16 i’m not having problem. however, i have trouble when i want to display the character after character 16. i’m intended to make the lcd scroll to the left one cursor if i key in the 17 character. the process keep repeat if i key in next character. the lcd will remain display 16 character. but, it keep updating the character if i enter new character via serial monitor. the idea supposed to be by using lcd.autoscroll. i created for loop for the counter of the lcd cursor. so, the lcd.autoscroll i put it inside the for loop counter. i already made the code. but, it is not working. i just want to ask your opinion what’s wrong with my code here. thank you.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

void setup() {
  // initialize serial:
  Serial.begin(9600);  
  lcd.begin(16, 2);
}

void loop() {
  // print the string when a newline arrives:
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    lcd.print(inChar);
    
    
    for (int positionCounter = 0; positionCounter > 15; positionCounter++) {
    // scroll one position left:
    //lcd.scrollDisplayLeft();
    lcd.autoscroll();
    // wait a bit:
    //delay(150);
    }
}

The start of the second line is 0x40

Mark

holmes4:
The start of the second line is 0x40

Mark

i'm don't want to start at the next line. but, i want to remain at the first line. it just shift the character to the left & eliminate the first character as i key in the new character.

Sounds like you are looking for the scroll functions:

yup. i already try it. but, it not working. i modified the coding like i posted above. let say i want to send ABCDEFGHIJKLMNOPQRSTUVWXYZ.
i send one by one. until letter P, which 16 character, the lcd display A until P. then, when i sent letter Q, supposed to be the lcd display BCDEFGHIJKLMNOPQ. the display scroll left one space. which the letter A no longer display at lcd display. i also try the combination of lcd.autoscroll & lcd.scrollDisplayLeft. also not working.

You need to keep track of how many characters have been sent. When that reaches 16, any further characters sent will trigger the scroll command. The commented out code simply tells it to scroll 16 times every-time you read a character.

may i know this for loop can be used as the method in order to keep the track... i i think like this way. but, it just need fine tune the coding...

for (int positionCounter = 0; positionCounter > 15; positionCounter++) {
lcd.scrollDisplayLeft();
}

mr_hacker90:
may i know this for loop can be used as the method in order to keep the track... i i think like this way. but, it just need fine tune the coding...

for (int positionCounter = 0; positionCounter > 15; positionCounter++) {
lcd.scrollDisplayLeft();
}

That for loop does absolutely nothing. positionCounter starts at 0, so it will never be greater than 15. There is nothing in your requirements to suggest that a for loop is even necessary.

i see. in that case. how the exact method for me to to track the character been sent. When that reaches 16, any further characters sent will trigger the scroll command...

mr_hacker90:
i see. in that case. how the exact method for me to to track the character been sent. When that reaches 16, any further characters sent will trigger the scroll command...

You'll need a variable that persists through loop:

static int charactersReceived = 0;

When you receive a character, you'll need to increment said variable:

if (Serial.available() > 0)
{
  charactersReceived++;
  // read and parse character
}

When that value reaches the threshold, do the shift:

if (charactersReceived() > 0)
{
  lcd.scrollDisplayLeft();
}

You’ll need a variable that persists through loop:

Is that necessary ?

According to this page http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll autocroll behaves like this

autoscroll() moves all the text one space to the left each time a letter is added

Part of the example code is as follows

 // set the cursor to (16,1):
  lcd.setCursor(16,1);
  // set the display to automatically scroll:
  lcd.autoscroll();
  // print from 0 to 9:
  for (int thisChar = 0; thisChar < 10; thisChar++) {
    lcd.print(thisChar);
    delay(500);
  }

which seems to indicate that autoscroll does what it needs with no help. I do not have an LCD display in a suitable state to try this at the moment so the description may be wrong.

The OPs code is subtly different from the example because the autoscroll is contained within the for loop which may make a difference.

    for (int positionCounter = 0; positionCounter > 15; positionCounter++) {
    // scroll one position left:
    //lcd.scrollDisplayLeft();
    lcd.autoscroll();
    // wait a bit:
    //delay(150);
    }

Arrch:

mr_hacker90:
i see. in that case. how the exact method for me to to track the character been sent. When that reaches 16, any further characters sent will trigger the scroll command…

You’ll need a variable that persists through loop:

static int charactersReceived = 0;

When you receive a character, you’ll need to increment said variable:

if (Serial.available() > 0)

{
  charactersReceived++;
  // read and parse character
}




When that value reaches the threshold, do the shift:



if (charactersReceived() > 0)
{
  lcd.scrollDisplayLeft();
}

it works. thanks by the way arrch. the coding is like this…

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

static int charactersReceived = 0;

void setup() {
  // initialize serial:
  Serial.begin(9600);  
  lcd.begin(16, 1);
}

void loop() {
  // print the string when a newline arrives:
  while (Serial.available() > 0 ) {
    char inChar = (char)Serial.read();
    lcd.print(inChar);
    
    charactersReceived++;


      if (charactersReceived > 16)
      {
        lcd.scrollDisplayLeft();
      }   
  }
}

UKHeliBob:
Is that necessary ?

Probably not, although admittedly, I haven't used the feature. The documentation doesn't give a clear indication on how it works with multiple lines, so that could be the issue.

lets say i want to upgrade the coding. so that it only display the character once it is requested. during that period, it hold the character in buffer. i seen to much way to hold the character in buffer. but, which one would simply the easy solution..