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
