Two I²C displays simultaneously on the Arduino

FunduinoPublished on

I²C-Adressen verstehen, ändern und zwei Displays getrennt beschreiben

Zwei I²C-LCDs an denselben zwei Leitungen, und jedes zeigt einen anderen Text: Damit das klappt, braucht jedes Display seine eigene Adresse.

In dieser Anleitung liest du die Adresse mit einem Scanner-Sketch aus, änderst sie über eine Lötbrücke und steuerst anschließend beide Displays getrennt an.

Two I²C LCDs on an Arduino UNO with different text

You need this

1602 I2C LCD Module - 2x16 Characters, HD44780, Blue 1602 I2C LCD Module - 2x16 Characters, HD44780, Blue 3,02 € *Item no. FUN-1010568About the product — 1602 I2C LCD Module - 2x16 Characters, HD44780, Blue
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino 830-point Breadboard - solderless breadboard for Arduino 2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
LED 5 mm - 100 Pieces, 5 Colors, 2 V LED 5 mm - 100 Pieces, 5 Colors, 2 V 1,97 € *Item no. F23107316About the product — LED 5 mm - 100 Pieces, 5 Colors, 2 V
Breadboard cables male-female - 40 pieces, 20 cm Breadboard cables male-female - 40 pieces, 20 cm 1,74 € *Item no. FUN-1010554About the product — Breadboard cables male-female - 40 pieces, 20 cm

All 6 parts together 22,49 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

Two displays on one bus

Multiple modules can be connected to the same two wires on the I²C bus. To distinguish between them, the Arduino uses each module’s own address, usually specified as a hexadecimal number. A module only responds to data sent to its specific address.

Many I²C LCDs come from the factory with the same address. If you connect two of them, both respond to the same data, so displaying different text on each is not possible. Before using two displays at the same time, you must change the address on one of them.

Two I²C LCDs on an Arduino UNO with different text

Change the address using solder bridges

This only works with displays whose I²C module has solder pads A0, A1 and A2, marked in red in the image. By default, all three are open. Depending on which ones you bridge with a drop of solder, you get eight different addresses.

The default address depends on the module and is usually 0x27 or 0x3F. The table shows which address corresponds to each combination (I = connected, : = not connected).

Back of an I²C LCD with solder pads A0, A1, and A2 marked in red
Table of I²C addresses based on bridged solder pads
1 / 2

Read the address using the I²C scanner

You can find out which address your display actually has with a small scanner sketch. Connect the display as follows:

  • VCC to 5V
  • GND to GND
  • SDA to A4
  • SCL to A5

Upload the scanner, open the Serial Monitor, and set the baud rate to 115200. The sketch tries all the addresses and outputs each one that a module responds on.

The serial monitor displays the detected I²C address.
I²C scanner
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#include <Wire.h>
void setup() {
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning …");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}

Install the library

You need the “LiquidCrystal I2C” library for the I²C LCD. It isn’t preinstalled; you can find it in the Arduino IDE Library Manager under the name “LiquidCrystal I2C by Marco Schwartz”. The instructions show you exactly how to install it Hardware and Software.

The LiquidCrystal I2C library by Marco Schwartz in the Library Manager

Connect and program two displays

In the example, solder jumper A1 is bridged on one of the two displays. From now on, this display is called Display 2, and the unchanged display is called Display 1. It’s best to check the new address again with the scanner.

Both displays are connected in parallel to the same four wires: SDA to A4, SCL to A5, VCC to 5V, and GND to GND.

In the sketch, create a separate object for each display using its address - lcd1 and lcd2 - and then write to them separately. Enter the two addresses shown by the scanner.

For a module with base address 0x3F, the A1 jumper sets the address to 0x3D. Enter 0x3F and 0x3D in the sketch. Turn off the backlight with noBacklight().

Circuit diagram: two I²C LCDs connected in parallel to SDA, SCL, 5V, and GND on the Arduino UNO
Two displays with different text
#include <Wire.h>  // Include the Wire library
#include <LiquidCrystal_I2C.h> // Include the previously added LiquidCrystal_I2C library
LiquidCrystal_I2C lcd1(0x27, 16, 2);  //Here the first display is named (address/characters per line/number of lines). In our case, “lcd1”. The address of the I²C display may vary depending on the module.
LiquidCrystal_I2C lcd2(0x3F, 16, 2);  //Here the second LCD is named, here "lcd2".
void setup()
{
lcd1.init(); //In setup, LCD1 is started
lcd2.init(); //In setup, LCD2 is started
lcd1.backlight(); //Turn on LCD1's backlight (0 turns the backlight off).
lcd2.backlight(); //Turn on LCD2's backlight (0 turns the backlight off).
}
void loop()
{
lcd1.setCursor(0,0); //The following text should start at the first character in the first line on LCD1.
lcd1.print("Display1 Zeile 1"); //The text “Display1 Zeile 1” should be displayed on the first line
lcd1.setCursor(0,1); //The following text should start at the first character in the second line on LCD1.
lcd1.print("Display1 Zeile 2"); //The text “Display1 Zeile 2” should be displayed on the second line
lcd2.setCursor(0,0); //The following text should start at the first character in the first line on LCD2.
lcd2.print("Display2 Zeile 1"); //The text “Display2 Zeile 1” should be displayed on the first line
lcd2.setCursor(0,1); //The following text should start at the first character in the second line on LCD2.
lcd2.print("Display2 Zeile 2"); //The text “Display2 Zeile 2” should be displayed on the second line
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.