http://www.youtube.com/watch?v=IpwqGJwn1FY
After looking through the modified LiquidCrystal library for use with the i2c backpack and darn near crying when I saw all the faux digitalRead() and pinMode() being done on each transfer, I was bound and determined to never let that happen to another friendly Arduino user again. I first made a proof of concept modification to the library to "burst" all the "LiquidCrystal::send" bits instead of digitalWrite()'ing them out one at a time (read I2C, modify, write... read, modify, write... read, modify, write... read, modify, write - over 16 I2C commands for each single character). It worked great. I could do animation on the screen once again, and it was smooth.
OK, so the next step... package it up into something usable. I kept running into issues where Wire.h needed to be part of every program I use LiquidCrystal with. It just had to be "forked" to its own library. I'm sure C++ will allow a typedef alias for any libraries/sketches that have LiquidCrystal hard-coded into them... I just haven't had a need yet. I fully gutted LiquidCrystal of all functions relating to digitalRead/digitalWrite, and made it 100% pure i2c. What a sleek beauty... just watch the video.
Of course, next on my to-do list is a proper animation library for character LCDs.
LiquidTWI library is attached to this post, also mirrored here: http://dl.dropboxusercontent.com/u/3528 ... -1.5.1.zip
Hope it helps!
Changelog:
- 1.5.1 / 8-7-2013:
Merged with changes from Stephanie Maks which provides compatibility with old IDEs as well as new. Also has a better init sequence. Shortened init delay back down to 50ms. - 1.5 / 8-7-2013:
Finally... finally wired up the test board again and resolved problems with new 1.x Arduino IDE. write() needs to be a size_t to mesh with Print. Also increased initialization delay from 40ms to 100ms to prevent bad initialization on first power-up. - 1.1 / 6-17-2011:
Oops... initial bugchecking was done on one program (performance test). LCD_DISPLAYCONTROL functions were sending bit 7 (backlight) to the LCD as part of the command, invalidating most commands and setting the cursor to address 0 instead of doing their function. That also screwed up the initialization routine something fierce. A miracle this slipped by testing. - 1.0 / 6-12-2011:
Initial release
Usage:
Code: Select all
Attach CLK pin to ANALOG 5 pin (remember: analog pins double as digital!),
Attach DAT pin to ANALOG 4 pin,
Give it 5V using 5V pin,
Then, GND it with GND pin, and you're all set!
Replace LiquidCrystal in your sketch directly with LiquidTWI, and modify the "LiquidCrystal lcd(...)" line as follows:
LiquidTWI lcd(byte i2cAddr)
i2cAddr = the address of your backpack device (typically 0)
The rest of the commands are straight out of LiquidCrystal:
void setup() { lcd.begin(16,2); }
void loop() { lcd.print("Happy!"); delay(500); lcd.clear(); delay(500); }