Tips needed to speed up Pimoroni I2C display

I bought this display:

It is a nice display to use, but is a little slow. Is there any way to speed it up?

My test code is below. To take 340 milli seconds to write 60 characters is quite a long time.

I already tried changing the I2C speed from 100k to 400k, and deleting the twi.o and wire.o files to force a recompile, but no change, so I guess the part that takes a long time is somewhere in the display or the display library.


#include <I2C_LCD.h>

I2C_LCD LCD;

byte I2C_LCD_ADDRESS = 0x51;

String line_1;
String line_2;
String line_3;
String line_4;
String line_1234;

unsigned long start = 0;
unsigned long finish = 0;
unsigned long total = 0;

void setup() {

Wire.begin();
LCD.CleanAll(WHITE);

}

void loop() {

line_1 = String(“Time to”);

do {
line_1 = String(" " + line_1);

} while (line_1.length() < 15);

line_2 = String(“print a”);

do {
line_2 = String(" " + line_2);

} while (line_2.length() < 15);

line_3 = String(“string”);

do {
line_3 = String(" " + line_3);

} while (line_3.length() < 15);

line_4 = String(total);

line_4 = String(line_4 + " milli sec");

do {
line_4 = String(" " + line_4);

} while (line_4.length() < 15);

line_1234 = String(line_1 + line_2 + line_3 + line_4);

LCD.FontModeConf(Font_8x16_1, FM_ANL_AAA, BLACK_BAC);

LCD.CharGotoXY(0, 0);

start = millis();

LCD.println(line_1234);

finish = millis();

total = finish - start;

}``

For whatever reason when I included my test code, the include LCD library command in the first line has been automatically changed. The test code works fine in the unchanged state.

Maybe I should also mention that I am using an arduino nano.

As a guess, just before you do the test you set the font code. Check the datasheet that this is not causing the println to stall before it does it’s work. A simple test would be to wait a second before starting the timing.

I’ve never bothered to time these, they may just be slow. What the datasheet say?

If this is causing issues in another app then you may need to rethink your main loop so that you only update the text at a slower interval.

The best way to optimise is to change the algorithm.

Thanks for your reply.

I tried a delay, but unfortunately it only improved the time taken by 2-3 ms.

The data sheet doesn’t say much, apart from that it can use 100k/s or 400k/s.

By ‘change the algorithm’ do you mean change the LCD library? I wouldn’t know where to begin with that.

For now I shall concentrate on writing code that only updates values, which will save the time taken printing the units after each value on every loop.

Re: change the algorithm.

Change how you are using it, so one example is only update the display when you need to so that the time it takes does not slow down the main loop every iteration. That is instead of drawing to it every update with the same stuff only send what is changed when it changes.

Without knowing your full use case and why the speed is an issue it would be hard suggest anything better. I’m going to ask some questions and maybe I can help. BTW I’ve been a software engineer for over 20 years so I should be able to help even if the final conclusion is “the display is to slow for what you want to do”.

So, the first question is. What will you be using this display for?