Why is printing to my 2x16 LCD shield so slow (up to 6 ms) ?

Hi there

I am using an LCD shield on my Arduino Mega 2560 similiar to this: LCD Shield.

Every second I call my “printLcd()” function, which takes about 5-6 milliseconds. This in turn lets my serial read buffer of 64 bytes overflow at a data-rate of 115’200 baud since the loop takes to much time to process all the incoming bytes.

Any ideas what could cause this time lag?

Here’s the critical section of my code (commenting out the content of the printLcd() function solves the problem and the loop finishes within some microseconds instead of milliseconds).

#include <WString.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {
    lcd.begin(16, 2);

void loop() {
    // ...
    printLcd("mymessage", 0);          // display message every second
    // ...

void printLcd(String message, int row) {
    lcd.setCursor(0, row);
    for (int i=message.length(); i<16; i++) lcd.print(" ");

Kind regards,

Can't see all your code.

The sketch is more than 500 lines long... As mentioned before, commenting out the 3 lines in the printLcd(...) function eliminates the 5-6ms time lag. The problem has to be within that function. Any ideas?

Any ideas?

See reply #1

I can't post the full code. I get the following error message: The message exceeds the maximum allowed length (9000 characters).

Which section do you want to focus on ?

Attach your code if you can't post it.

If sending all the characters in one go is a problem, don't do that, but send them one at a time over a longer period.

Thanks for your suggestion (I attached my sketch as zip-file). But the reason why I decided for such a high baud-rate is because I need alot of data to be transfered from the PC to the Arduino. Otherwise I could use 9600 baud and would have plenty of time to process it before the 64kB buffer is running out.

The LCD is currently only for debugging purpose. The final project doesn’t need the LCD anyway and therefore I’ll have no timing problems.

Maybe I expressed myself the wrong way when I wrote the question. I want to know if it’s normal that printing to a LCD is taking that long (5 to 6 ms for 16 characters). Since I am new to Arduino, I could be using a wrong library, having bought crappy hardware or anything else…

Could please somebody confirm that it takes 5 to 6ms to write 16 characters to a LCD?

roboctrl.zip (4.21 KB)