I'm using a standard HDD4780 (or something like that, i forget the exact model) compliant LCD for this project, and it does work with simpler programs. My problem is that it seems to overwrite itself sometimes. I assume its my code, but I can't be sure. Here's the code:
#include <LCD4Bit.h>
LCD4Bit lcd = LCD4Bit(2);
int x = 0;
int i =0;
int button = 13;
char g[53]="";
char u[25]="";
char ut[25]="";
char l[25]="";
char lt[25]="";
char b[25]=" ";
int scrolled=0;
void setup()
{
lcd.init();
Serial.begin(19200);
}
void loop()
{
// Serial data waiting?
if (Serial.available())
{
delay(100);
// Read in the serial data to g
while(Serial.available()>0)
{
g[x]=Serial.read();
x++;
}
x=0;
char ch = g[x];
// Begin filling the upper temp, until the % character
while (g[x] != '%')
{
ut[x-1]=g[x];
x++;
}
// Was that actually wanted data?
if (g[0] != '
This works in the way that data can be sent, 2 lines at a time in 1 string. The first character has to be $ to get first line data, the % character denotes the end of the first line, and ^ is the endline character. Each line is held to 25 characters, while the input buffer (g) is 53, to account for 50 characters and 3 delimiters. The b string is for blanking a line when I want to write new data, in case the new data is shorter than the old (it overwrites, so I have to make sure nothing is left over to screw up what i see).
The problem is this: when I first send data, it all displays, but scrolls. That i can live with, but the second (and ever after) data send does not display correctly. The first line seems to get blanked, first 8 characters then 16 then probably 32, but I dont go that high anyway. It is supposed to be able to write a single line (top if send $(text)%^, bottom is sent %(text)^), but wont do it. The bottom always writes correctly, the top is giving me real problems. Any ideas?
[edit]
Many of the delays are probably not needed, I was just trying before to see if it was overwriting itself on a timing problem or something.
[/edit])
{
// If not, clear the upper temp
for(int i = 0; i < 25; i++)
{
ut[i]=' ';
}
}
// Fill the rest to the lower temp until ^ character
while(g[x+1] != '^')
{
x++;
lt[i]=g[x];
i++;
}
x=0;
i=0;
// Clear g
for(int i = 0; i < 53; i++)
{
g[i]=' ';
}
// Upper temp not empty?
if (ut[0] != ' ')
{
// Clear upper line
lcd.cursorTo(1,0);
delay(1);
lcd.printIn(b);
delay(10);
// Print new data
lcd.cursorTo(1,0);
delay(1);
lcd.printIn(ut);
delay(10);
// Save temp
for(int i = 0; i < 25; i++)
{
u[i]=ut[i];
ut[i]=' ';
}
}
// Lower temp not empty?
if (lt[0] != ' ')
{
// Clear lower line
lcd.cursorTo(2,0);
delay(1);
lcd.printIn(b);
delay(10);
// Print new data
lcd.cursorTo(2,0);
delay(1);
lcd.printIn(lt);
delay(10);
// Save temp
for(int i = 0; i < 25; i++)
{
l[i]=lt[i];
lt[i]=' ';
}
}
}
// Otherwise, check if we should be scrolling
while(!(Serial.available() > 0))
{
delay(1500);
// Scroll if the string is off the screen
if((u[16] != ' ')||(u[17] != ' ')||(l[16] != ' ')||(l[17] != ' '))
{
lcd.leftScroll(10,750);
scrolled=1;
}
// If scrolled, redraw the text
if (scrolled == 1)
{
lcd.clear();
lcd.cursorTo(1,0);
lcd.printIn(u);
delay(1);
lcd.cursorTo(2,0);
lcd.printIn(l);
scrolled=0;
}
}
}
This works in the way that data can be sent, 2 lines at a time in 1 string. The first character has to be $ to get first line data, the % character denotes the end of the first line, and ^ is the endline character. Each line is held to 25 characters, while the input buffer (g) is 53, to account for 50 characters and 3 delimiters. The b string is for blanking a line when I want to write new data, in case the new data is shorter than the old (it overwrites, so I have to make sure nothing is left over to screw up what i see).
The problem is this: when I first send data, it all displays, but scrolls. That i can live with, but the second (and ever after) data send does not display correctly. The first line seems to get blanked, first 8 characters then 16 then probably 32, but I dont go that high anyway. It is supposed to be able to write a single line (top if send $(text)%^, bottom is sent %(text)^), but wont do it. The bottom always writes correctly, the top is giving me real problems. Any ideas?
[edit]
Many of the delays are probably not needed, I was just trying before to see if it was overwriting itself on a timing problem or something.
[/edit]