Hi guys I use LCD I2C library "LiquidCrystal_I2C.h"
this is my test code
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
Serial.begin(115200);
// Print a message to the LCD.
lcd.backlight();
}
void loop()
{
lcd.setCursor(0, 0);
unsigned long time_start = micros();
lcd.print("1234567890123456");
unsigned long time_end = micros();
Serial.println(time_end-time_start);
}
Test result is 20ms in my loop function , but my requirement is 5ms .
I try a method is changing the Wire.h
"TWI_FREQ 100000L " to "TWI_FREQ 10000L "
and I get 13ms performance. It's quite strange.
Are there any methods to improve LCD performance??
thanks~~
The only way is to look at the libiary, you will see it uses delays to ensure that the LCD is ready for the next step. If you change the code and use the busy output of the display you can speed things up. That will need an extra wire from the display to the I2C interface device.
lcd.print("1234567890123456");
is 16 char long :
the LCD works in 4bits mode
each char needs 2 LCD.write4bits()
each LCD.write4bits() sends 3 bytes to PCF8574 (1 byte for 4bits value, 2 bytes for pulseEnable)
each byte to PCF8574 needs 2 bytes on I2C bus (1 byte for address + r/W, 1 byte for output values) : let's say something like 20 bits, including start/stop/ack
=> 16 * 2 * 3 * 20 = 1920 bits to write on I2C Bus
100 kHz bus => 19,2 ms transmitting
pulseEnable() also contains a 0,05 ms delay * 32 = 1,5 ms delay for 16 char
Here are your 20 ms
Try to speed your I2C bus up to 400kHz.
1,5 + 19,2/4 = 6,3 ms for 16 char
I also think that delay in pulseEnable() is useless, compared to time needed for sending one byte to PCF8574
The standard liquidCrystal_I2C library contains delays as required in HD44780 datasheet, but I2C time is not considered.
Same in LCD.begin()
So maybe you could reach 5 ms performance, modifying LCD lib
Thank your reply.
Another question is how come I change frequency down to 10k I2C, but the performance greater than 100k , and LCD show is perfect. What happening??
I don't think you are, I think something is overriding your change.