I have released LiquidTWI2, a lean, high speed I2C LCD Library for Arduino. This library is an extension of the great work done by FalconFour on his LiquidTWI library. Notable additions to LiquidTWI:
LiquidTWI2 also supports the Adafruit I2c Backpack (MCP23008-based) in I2C mode. The library is a drop-in replacement for both the Adafruit LiquidCrystal Library (for the I2C backpack) and the Adafruit RGB LCD Shield Library. By replacing either of Adafruit’s libraries with LiquidTWI2, memory use will decrease, and writing to the LCD will become blazingly fast.
Installation:
- download LiquidTWI2 from github.
- copy the LiquidTWI2 folder to <arduinosketchbook>/libraries/LiquidTWI2
Usage:
I2C Backpack or compatible MCP23008-based module
#include <Wire.h>
#include <LiquidTWI2.h>
LiquidTWI2 lcd(0); // 0 = i2c address
void setup() {
lcd.setMCPType(LTI_TYPE_MCP23008); // must be called before begin()
lcd.begin(16,2);
lcd.setBacklight(HIGH); // only supports HIGH or LOW
}
void loop() {
lcd.print(“Hello World!”);
delay(500);
lcd.clear();
delay(500);
}
RGB LCD Shield or compatible MCP23017-based module
#include <Wire.h>
#include <LiquidTWI2.h>
LiquidTWI2 lcd(0);
void setup() {
lcd.setMCPType(LTI_TYPE_MCP23017); // must be called before begin()
lcd.begin(16,2);
lcd.setBacklight(WHITE); // see LiquidTWI2.h for color options
}
void loop() {
lcd.print(“Hello World!”);
delay(500);
lcd.clear();
delay(500);
uint8_t btns = readButtons();
}
Note that you must call setMCPType() with the correct module type prior to the first call to begin(). The module type can be switched at any time during runtime by merely calling setMCPType() and begin() again. This allows you to create a single firmware which can run with either module, and store the module type in EEPROM.
When working in a memory-constrained environment, you can save memory by disabling the unneeded support. Edit LiquidTWI2.h and comment out the #define for either MCP23008 or MCP23017.
For further speed gains, you can tweak the speed of the I2C bus. See the included i2c_perftest example sketch.
Download: https://github.com/lincomatic/LiquidTWI2/downloads
Related Post: LiquidTWI2 v1.1.0 Released