// This is the (old) default library.
// It seems to work with a Raspberry Pi
//
// Note: In Real Life, there must be a I2C level shifter.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd( 0x27, 16, 2);
LiquidCrystal_I2C lcd2( 0x28, 16, 2);
void setup()
{
Serial.begin(115200);
while (!Serial) // wait for serial port to connect. Needed for native USB
{
delay(10);
}
Serial.println( "The sketch has started.");
Wire.begin(); // use the default, GPIO4 = SDA, GPIO5 = SCL
Serial.print( "Scanning for I2C addresses: ");
for( int i2cAddress = 1; i2cAddress <= 127; i2cAddress++)
{
Wire.beginTransmission( i2cAddress);
int error = Wire.endTransmission();
if( error == 0)
{
Serial.print( "0x");
if( i2cAddress < 0x10)
Serial.print( "0");
Serial.print( i2cAddress, HEX);
Serial.print( ", ");
}
delay( 1);
}
Serial.println( "Ready.");
// Initial text on the first display
lcd.init();
lcd.backlight(); // turn on backlight
lcd.setCursor( 0, 0);
lcd.print( "It is working");
lcd.setCursor( 0, 1);
lcd.print( "0x");
// Write something on the second display
lcd2.init();
lcd2.backlight(); // turn on backlight
lcd2.setCursor( 0, 0);
lcd2.print( "Second display");
}
void loop()
{
lcd.setCursor(2,1);
char buffer[20];
sprintf( buffer, "%08lX", millis()); // <- I did not check the format, it might be right
lcd.print( buffer);
delay( 20); // slow down the sketch
}