From 4a28eb7b4cbb3095e9a5d3f3cc55b1d36cdbc762 Mon Sep 17 00:00:00 2001 From: jenschr Date: Sat, 26 Aug 2017 21:20:28 +0200 Subject: [PATCH 1/2] Added a setAddress function to make it possible to scan to the correct address and then display that on the Liquidcrysta display itself --- LiquidCrystal_I2C.cpp | 4 ++ LiquidCrystal_I2C.h | 1 + .../LiquidCrystalFindAddress.ino | 54 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino diff --git a/LiquidCrystal_I2C.cpp b/LiquidCrystal_I2C.cpp index 44b7b05..bb07bb4 100644 --- a/LiquidCrystal_I2C.cpp +++ b/LiquidCrystal_I2C.cpp @@ -52,6 +52,10 @@ LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t l _backlightval = LCD_NOBACKLIGHT; } +void LiquidCrystal_I2C::setAddress(uint8_t lcd_Addr){ + _Addr = lcd_Addr; +} + void LiquidCrystal_I2C::init(){ init_priv(); } diff --git a/LiquidCrystal_I2C.h b/LiquidCrystal_I2C.h index c033f7f..fc38119 100644 --- a/LiquidCrystal_I2C.h +++ b/LiquidCrystal_I2C.h @@ -55,6 +55,7 @@ class LiquidCrystal_I2C : public Print { public: LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows); + void setAddress(uint8_t lcd_Addr); void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS ); void clear(); void home(); diff --git a/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino b/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino new file mode 100644 index 0000000..927aa15 --- /dev/null +++ b/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino @@ -0,0 +1,54 @@ +/* + * This sketch will loop through adresses until it sees an I2C device + * When an address is found, we'll assume it's an Liquidcrystal I2C + * display and show the address there as well as on Serial. + * + * written by Jens Chr Brynildsen 2017 to help test 30 screens with + * varying I2C addresses. + */ + +//Compatible with the Arduino IDE 1.0 +//Library version:1.1 +#include +#include + +LiquidCrystal_I2C lcd(0, 20, 4); +int address; +char buff[10]; + +void setup() +{ + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + Wire.begin(); + delay(2000); + + for (address = 0; address <= 119; address++) { + Wire.beginTransmission(address); + int error = Wire.endTransmission(); + + if (error == 0) { // device found + sprintf(buff, "%02x", address); + Serial.print("Address: "); + Serial.println( buff ); + lcd.addr( address ); // set the address + lcd.init(); + lcd.backlight(); + lcd.setCursor(0, 0); + lcd.print("Hello world"); + lcd.setCursor(0, 1); + lcd.print("I2C addr: 0x"); + lcd.setCursor(12, 1); + lcd.print(buff); + while (1); + } + } +} + + +void loop() +{ + // if we reach this point, nothing was found on the I2C bus + digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN) ); + delay(100); +} From 49a49810fb2819dffeb0e53a38831a6a8a15e67a Mon Sep 17 00:00:00 2001 From: Jens Chr Brynildsen Date: Tue, 26 Dec 2017 03:27:05 +0100 Subject: [PATCH 2/2] Incorrctly named method after refactoring --- examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino b/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino index 927aa15..db7f018 100644 --- a/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino +++ b/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino @@ -31,7 +31,7 @@ void setup() sprintf(buff, "%02x", address); Serial.print("Address: "); Serial.println( buff ); - lcd.addr( address ); // set the address + lcd.setAddress( address ); // set the address lcd.init(); lcd.backlight(); lcd.setCursor(0, 0);