lcd.clear() throwing display/code out of sync?

I have an RSS feed being displayed on my LCD. This works fine as long as I don’t use lcd.clear() to clean the screen.

When I detect the start of a new thread using “<” character, I then use lcd.clear() to clean the screen. If I do this it seems to throw the rest of the code out of sync and prints the feed onto the second line of the LCD line too soon.

int startstring = 0;
int charcount = 0;
int linetwo = 0;
int clearOnce = 0;
const int initialMarker = 1;

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void newfeed(){
    lcd.clear(); // this line seems to cause syncing problems?
    digitalWrite(10,HIGH); 
    digitalWrite(10,LOW);
    
}


void setup(){
  delay (2000);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  pinMode(13, OUTPUT); 
  pinMode(10, OUTPUT); 
  Serial.println(initialMarker); // print startMarker once
}

void loop(){
  char incomingByte = 0;
    if (Serial.available() > 0){
      digitalWrite(13,HIGH);
      incomingByte = Serial.read();
      if (incomingByte == '<') {
        newfeed(); 
      }
      if (charcount < 16) {
          lcd.print(incomingByte);
          charcount++ ;
         }
          else if ((charcount >= 16) && (charcount <=31)){
            if (linetwo == 0) {
              lcd.setCursor(0,1);
              linetwo = 1;
              
            }
            lcd.print(incomingByte);
            charcount++ ;
           }
          else if (charcount == 32){
              charcount = 0;
              lcd.setCursor(0,0);
              delay (2000);
              lcd.clear();
              lcd.print(incomingByte);
              charcount ++;
              linetwo = 0;
           }

    digitalWrite(13, LOW);
    delay(10);
       }
}

I have attached the image of what is happening.

The number of characters it prints on the 1st line before moving onto line 2 reduces with each feed.

Without the lcd.clear() line, the feeds just works as expected and fills up both lines before moving on to the second screen.

If it is required here is the Python code for the feed.

import serial
import feedparser
import time
ser = serial.Serial("\\.\COM3", 9600)


i = 1
y = 0


while i == 1:
  y = int(ser.read())
  
  while y == 1:
        
    sportFeed = feedparser.parse('http://feeds.bbci.co.uk/sport/0/football/rss.xml')

    posts = []

    for z in range(0,len(sportFeed)):
      print  sportFeed['entries'][z].title #, ' | ', sportFeed['entries'][z].updated
      ser.write (str("<"))
      ser.write (str(sportFeed['entries'][z].title))
      time.sleep(1)
      ser.write (str('>'))
      time.sleep(6)

    time.sleep(30)

Thank you

For a normal Arduino Uno/Nano/Leonardo/Micro/Pro Mini board ?

This is the library code : https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/src/LiquidCrystal.cpp
There is a delay of 2ms after calling the clear command. Perhaps you need a little more ?

lcd.clear();
delay(2);     // give my display 2 extra ms.

You should reset charcount and linetwo when you clear the LCD.

radowns82:
I have an RSS feed being displayed on my LCD. This works fine as long as I don't use lcd.clear() to clean the screen.

Thank you

Try my LiquidCrystal library. It fixes several bugs in the original one, and adds features as well (including cursor position knowledge and cursor control).

For example, you can use the newline character ("\n") to jump to the next LCD line, and printing a string longer than one line does not disappear into oblivion... it wraps to the next line.

If you want to use this library, go into your existing LiquidCrystal library, rename "LiquidCrystal.cpp" and "LiquidCrystal.h" to something else (for example, append ".old" to each name)., then copy the new ones in place of the old ones.

This should solve all of your problems.

Thank you for all the tips, I corrected it by resetting charcount and linetwo when you clearing the LCD. [oqibidipo]

Krupski - cheers I'll check out your library.