I get each character via serial, write to the LCD screen, and increment the x,y position. Then repeat until full.
It takes about 2 seconds to write all the lines on the LCD, so I lose data if I sent too much in that time.
Are these screens just too slow to process data, or might it be the Adafruit library I'm using?
If I just echo this data out to my computer and watch it in Putty I can see its all being processed quickly, with no loss. Only when I write to the LCD is it too slow.
Better way to do what I'm doing?
Any ideas welcome!
Post your code. You won't get much help if you are secretive about it. Two seconds seems a bit unreasonable, if only because there is a limit on how much data you can send. I can send four readings and the time in one second. I doubt that the library is the villain. Maybe the problem is that you are sending redundant information as well as data.
If your display reads Temp= 15.2C
you only need to send Temp= C once as it is not data
and you send the 15.2 in the loop
You have probably deduced that lcd.clear is probably a redundant command.
There is no redundant info as I want it all displayed.
I used software SPI and I wonder how much slower that is.
This is the main loop that applies:
/* while data has been received at serial port: */
while (Serial.available())
{
char received = Serial.read();
if ((received == '\n')) //if a terminator, drop down a line and don't display it, unless that terminator is at x=0
{
if ( cursor_x != 0)
{
cursor_y = cursor_y + 8;
}
cursor_x = 0; // if it sees a return go back to x = 0
}
else // got some regular data to display, write the char to the LCD and update the x,y position for next char
{
display.setCursor(cursor_x, cursor_y);
display.print(received);
display.display();
cursor_x = cursor_x + 6;
/* check if screen has written all 14 columns */
if (cursor_x >= 84) // // 84px across, chars are 6 wide, so 14 rows at 0,6,12,18,24,30,36,42,48,54,60,66,72,78
{
cursor_x = 0;
cursor_y = cursor_y + 8;
}
}
/* check if screen has written all 6 lines */
if (cursor_y > 40) // 48px down, chars are 8 tall, so 6 lines at 0 8 16 26 32 40.
{
cursor_x = 0;
cursor_y = 0;
display.clearDisplay(); // clears the screen and buffer
}
}
}
The code not only looks like junk, but surely also incomplete. CrossRoads may have comment on how much slower software SPI is but you might be better off questioning why you would ever want to use it anyway. There is no need to even use hardware SPI. I can't tell the difference if it is on it or off it.
While I doubted the library is the problem, you might try the standard PCD8544 library. It at least has to be a hell of lot easier to use.
I would not describe your sketch as "junk". However you could let the library look after the cursor and the printing.
Which particular library are you using? e.g. "Adafruit_PCD8544"
You only need to position the cursor when you do a newline. print() should look after itself.
You can assume that it starts at 0,0 after a clearDisplay()
Yes, Hardware SPI will be faster but the software bit-bashing will not be impossible.
You should be able to receive at 9600 baud and display at full speed.
The whole thing. You should be able to send data to the LCD in essentially the same manner as you would send it to anything else. This doesn't mean that what you have won't work at all, but it might be indicative of where your problem lies.
Having said that, there is no indication in the code of what the data might be, or where it even comes from. It may be like no other, to the point where "data" is a bit of a loose term. There isn't even any indication of what "data" you send to the monitor. All we know is that the LCD is a problem while the monitor is not. Perhaps a picture of the display might help.
while (Serial.available())
{
char received = Serial.read();
SSerial_putty.print(received);
display.print(received);
display.display();
}
I get raw data in via serial. The LCD display and the display on the PC running putty write the characters slowly. Perhaps 1.5 seconds to fill the LCD screen.
Putty writes at the same speed.
If I comment out the LCD:
while (Serial.available())
{
char received = Serial.read();
SSerial_putty.print(received);
// display.print(received);
// display.display();
}
..then Putty gets and shows data MUCH faster.
I assume the LCD write is the slowdown, and this waits until it's written before serial is available again.
Does this show I need to use hardware SPI, or a faster driver, and that will speed this up, or am I not interpreting this correctly?
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
//Adafruit_PCD8544 display(13, 11, 9, 10, 8); //bit-bang
Adafruit_PCD8544 display(9, 10, 8); //hardware SPI
void setup() {
Serial.begin(9600);
display.begin();
display.clearDisplay(); // clears the screen and buffer
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0, 0);
display.println("Hello World");
display.display();
}
void loop()
{
char c;
uint8_t row = 0, col = 0;
while (1) {
while (Serial.available()) {
c = Serial.read();
display.print(c);
if (c == '\n' || ++col > 14) {
col = 0;
if (++row > 6) {
row = 0;
display.clearDisplay();
}
}
}
display.display();
}
}
I then sent a regular text file from the PC at 9600 baud. It appeared to catch and display every character. Of course, I could not possibly read it as it came so fast. And a 14x6 text display is a little small.