I started by running the I2C address scanning (Red code)
Scanning…
I2C device found at address 0x01 !
I2C device found at address 0x02 !
I2C device found at address 0x03 !
I2C device found at address 0x04 !
I2C device found at address 0x27 !
done
Sunfounder LCD 20×4: I2C device found at address 0x27 !
Each I2C LCD screen has three pads: A0, A1, and A2. Below is the table that shows how to solder the pads to change the address. Below the table is a picture of the I2C LCD screen pads on the right side. Soldering them can be tricky to do.
A0 | A1 | A2 | Hex |
open | open | open | 0x27 |
closed | open | open | 0x26 |
open | closed | open | 0x25 |
closed | closed | open | 0x24 |
open | open | closed | 0x23 |
closed | open | closed | 0x22 |
open | closed | closed | 0x21 |
closed | closed | closed | 0x20 |
#include <LiquidCrystal_I2C.h> // Library for I2C LCD displays
#include <wire.h>
Is missing from the code below. WordPress doesn’t like the format.
// Include the required Wire library for I2C
// Include the libraries:
// LiquidCrystal_I2C.h: https://github.com/johnrickman/LiquidCrystal_I2C
#include <LiquidCrystal.h> // Library for I2C communication
#include <Wire.h> // Library for LCD
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,20,4) for 20×4 LCD.
#include
int x = 0;
int LED = 13;
void setup()
{
// Initiate the LCD:
lcd.init();
lcd.backlight();
// I2C counter for LEDs
pinMode (LED, OUTPUT);
// Start the I2C Bus as Master
Wire.begin();
// I2C counter for LEDs
/*
// I2C Scanner Code
Serial.begin(9600);
while (!Serial); // wait for serial monitor
Serial.println(“\nI2C Scanner”);
// I2C Scanner Code
*/
}
void loop() {
//LCD I2C 20X4
lcd.setCursor(3, 0); // 4th column 1st row
lcd.print(“Welcome aboard”);
lcd.setCursor(8, 1); // 9th column 2nd row
lcd.print(“the”);
lcd.setCursor(6, 2); // 7th column 3rd row
lcd.print(“Heart of”);
lcd.setCursor(2, 3); // 3rd column 4th row
lcd.print(“Stainless Steel”);
//LCD I2C 20X4
// I2C counter for LEDs
x++; // Increment x
//From Left to Right
// First UNO
Wire.beginTransmission(1); // transmit to device #1
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting
//Second UNO
Wire.beginTransmission(2); // transmit to device #2
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting
//Mega in the Middle
//Third UNO
Wire.beginTransmission(3); // transmit to device #3
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting
//Fourth UNO
Wire.beginTransmission(4); // transmit to device #4
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting
if ( (x == 3) || (x == 6)) {
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}
if (x == 7) x = 0; // `reset x once it gets 6
delay(1000);
// I2C counter for LEDs
/*
// I2C Scanner Code
byte error, address;
int nDevices;
Serial.println(“Scanning…”);
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print(“I2C device found at address 0x”);
if (address<16)
Serial.print(“0”);
Serial.print(address,HEX);
Serial.println(” !”);
nDevices++;
}
else if (error==4)
{
Serial.print(“Unknown error at address 0x”);
if (address<16)
Serial.print(“0”);
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println(“No I2C devices found\n”);
else
Serial.println(“done\n”);
delay(5000); // wait 5 seconds for next scan
// I2C Scanner Code
*/
}