lincomatic / liquidtwi2 Goto Github PK
View Code? Open in Web Editor NEWA lean, high speed I2C LCD Library for Arduino, which supports MCP23008 and MCP23017
A lean, high speed I2C LCD Library for Arduino, which supports MCP23008 and MCP23017
LiquidTWI2 ========== A lean, high speed I2C LCD Library for Arduino, which supports MCP23008 (Adafruit LCD Backpack) and MCP23017 (Adafruit RGB LCD Shield) hacked by Sam C. Lin / http://www.lincomatic.com from LiquidTWI by Matt Falcon (FalconFour) / http://falconfour.com logic gleaned from Adafruit RGB LCD Shield library Panelolu2 support by Tony Lock / http://blog.think3dprint3d.com Panelolu2 integration by Robert F-C / https://github.com/buildrob enhancements by Nick Sayer / https://github.com/nsayer Compatible with Adafruit I2C LCD backpack (MCP23008) and Adafruit RGB LCD Shield (and optionally, Panelolu2) For more information see http://blog.lincomatic.com/?tag=LiquidTWI2 http://forums.adafruit.com/viewtopic.php?f=19&t=21586 Panelolu2 usage see http://blog.think3dprint3d.com/2012/12/mcp23017-i2c.html Version 1.2.7 Changelog: * 1.2.7 / 20190624 SCL fixed row offset issue w/ 16x4 LCD per #15 * 1.2.6 / 20140220 SCL added device detected guard to home() & buzz() * 1.2.5 / 20130725 SCL added LcdDetected() from Scott Rubin * 1.2.4 / 20130409 SCL buzz() fixes from buildrob * 1.2.3 / 20130322 SCL PANELOLU2 support cleanup and always enabled when MCP23017 by buildrob buzz() now works for Panucatt Viki as well * 1.2.2 / 20130120 SCL make setMCPType() a no-op when only one MCPxxxx defined instead of removing it * 1.2.1 / 20130102 SCL disable PANELOLU2 by default * 1.2.0 / 20130101 SCL added DETECT_DEVICE * 1.1.1 / 20121219 SCL added Tony Lock's Panelolu2 enhancements * 1.1.0 / 20121018 SCL use 8-bit GPIO for writing on MCP23017 for 25% speed increase with only 14 byte size increase * 1.0.0 / 20121016 SCL initial release Distributed with as free-will a license as is available given this code's long associative chain of licenses (LiquidCrystal -> Arduino -> Wiring -> ...?). Use it in any way you feel fit, profit or free, provided it fits in the licenses of its associated works. Installation: extract LiquidTWI2/ into <arduinosketchbook>/libraries/LiquidTWI2 To use with Panelolu2 lcd.setMCPType(LTI_TYPE_MCP23017); Panelolu2 only has encoder.. use PANELOLU_ENCODER_X bits instead of BUTTON_xxx Usage: Compatible with Arduino LiquidCrystal library except that setMCPType() MUST be called at least once before begin() is called // MCP23008 (Adafruit LCD Backpack) #include <Wire.h> #include <LiquidTWI2.h> LiquidTWI2 lcd(0x20); 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); } // MCP23017 (Adafruit RGB LCD Shield) #include <Wire.h> #include <LiquidTWI2.h> LiquidTWI2 lcd(0x20); 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 = lcd.readButtons(); } If you change the i2c address of the board, set "lcd(0x20)" to your new 3-bit address. If you have more than a 16x2 LCD, change "lcd.begin(16,2)" to reflect the columns and rows of your LCD. Normally, the code will hang if the device is not detected at the specified i2c address. If you want to compile your code for an optionally installed LCD, call the constructor with 2nd parameter deviceDetect=1. E.g: LiquidTWI2 lcd(0x20,1); When enabled, if the device is not detected at the specified address when begin() is called, then the rest of the function calls become NOOPs Note that the library can switch modes at runtime. Simply call setMCPType(), followed by begin(). This allows you to create a firmware which is compatible with either kind of LCD module, and select the type from EEPROM. For memory-constrained projects, disable the unnecessary support by commenting out the corresponding MCP230xx in LiquidTWI2.h, and DETECT_DEVICE
Issue
Unable to compile example with Library for Panelolu and MCP23017 configuration
Files
HelloWorld_i2c.pde
LiquidTWI2.cpp
LiquidTWI2.h
Settings
LiquidTWI2.h
Error
Unknown type mcpType
Suggestion correction
void setMCPType(uint8_t mcptype) { _mcpType = mcptype; }
Hello,
the row offset in "LiquidTWI2.cpp" line 347 is wrong.
Line 347 in 30aa480
when you compile it with a 16x4 LCD you get this: (im just filling all the characters with 0-15 in hex)
when you change the row offset to
int row_offsets[] = { 0x00, 0x40, 0x10, 0x50 };
you get this like expected:
i think noone has found this bug yet, because i am using a 16x4 LCD instead of a 16x2 LCD.
The class needs _backlightInverted to be declared, as well as the function prototype updated for the added argument.
Line 193 of LiquidTWI2.cpp needs to change from
#if defined(ARDUINO) && (ARDUINO >= 100)
to
#if defined(ARDUINO) && (ARDUINO > 100)
as the extra parameter to twi_writeTo seems to have been added at 1.0.1.
Browsing through LiquidTWI2.cpp I noticed that the LiquidTWI2::home function has no guard code for DETECT_DEVICE. It calls LiquidTWI2::command directly and could be a cause for hanging if a display is not present.
Would it be possible to add this function to TWI2, so it could be called like this in code LCD.setClock(100000)?
void LiquidTWI2::setClock(uint32_t frequ) {
Wire.setClock(frequ);
}
The examples included are somewhat out of date and could use some minor rework to be compatible with typical boards.
Update to the .ino format (is anyone expecting to use this library with a pre-1.0 IDE?)
The comments in both examples mention the pins to wire up, but that varies by board... per http://arduino.cc/en/Reference/Wire:
Board I2C / TWI pins
--------- --------------------------
Uno, Yun A4 (SDA), A5 (SCL)
Mega2560 20 (SDA), 21 (SCL)
Leonardo 2 (SDA), 3 (SCL)
Due 20 (SDA), 21 (SCL)
(Purposely omitting SDA1/SCL1 on the Due because they are non-trivial to use IMHO)
Also, the default address would be better to be something like 0x20 (which is a typical default base address.
Browsing through LiquidTWI2.cpp I noticed that the LiquidTWI2::buzz function has no guard code for DETECT_DEVICE. It calls Wire library functions directly and could be a cause for hanging if a display is not present.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.