4

I have two I2C LCD screens:

  • one with 2 lines
  • one with 4 lines.

Both have 4 pins each: GND, VCC, SDA, SDL. I connect SDA and SDL to A4 and A5 respectively, and I display text on each one of them with:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,4);

But how can I use both of them at the same time?

I connected the second one's SDA and SDL to A2 and A3, but apparently I have to provide the right address for them (like 0x27), right?

However, while both are connected, using I2C_Scanner only shows one device:

Scanning...
I2C device found at address 0x27  !
done

What am I missing?

4

With the I2C backpack there are three pairs of landings, A0, A1, A2, which determine the 3 LSB of the device's address, using inverted binary.

Left alone, they generate part of the F or 7 part of the address. 0x3F is common, as is 0x27.

To use more than one device it is necessary to jumper them all uniquely.

The upper bits that generate the 0x3 are hard-wired. So is the highest bit of the lower byte. Only the three lowest-order bits can be changed.

Since these address bits are inverted, jumpering the A0 will subtract 1 from the address. 0x3F will become 0x3E, 7 will become 6.

You have control enough to make up to 7 LCD modules on the same I2C bus.

The only caveat is that if you have more than one device writing to the various LCDs you might get collisions, which can mess up the display pretty good.

There are questions on I2C collision avoidance and detection on http://RaspberryPi.StackExchange.com if that is your situation.

Jumpering one or more of them is pretty easy - just pre-tin some wire and solder it quickly then cut off the excess.

Wire the SDA and SCL wires of the LCDs in parallel and to the SDA and SCL pins on the Arduino, usually A4 and A5. (I always begin with a breadboard for this). Make sure you have discrete pull-up resistors (10K is common) on each, in only one place on the bus.

If you have a DS3231 RTC module in the system, you do not need to add pull-ups because it has them internally.

If one LCD is already working then you know you have proper pull-up voltage on the bus. (The signals are switched to the ground state to send data on the I2C bus)

So, to Summarize:

If you have two LCDs in your system you can use LCD modules that already come with different addresses, like

LiquidCrystal_I2C lcd1(0x27,....);

for the first one, then

LiquidCrystal_I2C lcd2(0x3F,.....);

for the second one.

Note that the parameters for these definitions are

LiquidCrystal_I2C lcdname(addr,en,rw,rs,d4,d5,d6,d7,bl,blpol);

0x27 and 0x3F are the most common stock addresses and 0x27 modules are getting harder to find.

If you have a 0x27 then it is very likely that if you buy a newer one it will be 0x3f. Problem solved.

The d4 and d5 in the definition specifies the pins to use for I2C.

You can run the i2cscanner program to see what it finds, once they are wired together. If you see two different addresses, say 0x27 and 0x3F, then you are good to go.

If only 2F shows, then you want to consider soldering A0 together on one module then run the scanner again to make sure it worked.

Here is how I usually do it when both come set as 0x3f:

I have a Yellow one which is a stock 0x3F and a Blue one where I jumpered A0 to make it 0x3E. They both are 20 x 4 displays.

Here are my definitions: (remember, the 4,5 define SDA, SCL pins)

LiquidCrystal lcdblue  (0x3e,2,1,0,4,5,6,7,3,POSITIVE);
LiquidCrystal lcdyellow(0x3f,2,1,0,4,5,6,7,3,POSITIVE);

Then in setup() I use this:

lcdblue.begin(20,4);
lcdblue.backlight();
delay(250);
lcdblue.nobacklight();
delay(250);
lcdblue.backlight();

lcdyellow.begin(20,4);
lcdyellow.backlight();
delay(250);
lcdyellow.nobacklight();
delay(250);
lcdyellow.backlight();

And it's good to go, using pin A4 as SDA and A5 as SCL.

You know they are working as they wink their backlights at you.

If one of yours is 20 x 2 then use lcd2.begin(20,2); of course.

If you REALLY want to use other pins for your I2C bus then just change the 4,5 in the LiquidCrystal_I2C definition to the pins you want to use. I never have met anyone who would want to do this.

Hope this helps.

0

You can't hook up I2C devices to arbitrary pins; they must either be connected to SDA and SCL and given different addresses, or you must use software I2C. Figure out how to give the second device a different address, and then instantiate another LiquidCrystal_I2C with the new address in order to be able to use it.

  • 1
    I found out that I can connect to A4, A5 up to 121 I2C devices. There aren't other ports for SDA, SCL. There must be a way to change the address, but I can't find it. Some other LCD displays have A0, A1, A2 pins: jumpering them changes their address. However, both of my display do not have them. (info at forum.arduino.cc/index.php?topic=158312.0 ) Will keep searching... – Konstantinos May 27 '15 at 23:57
  • Do you have a link to a product page? – Ignacio Vazquez-Abrams May 27 '15 at 23:58
  • Yes it's this: ebay.co.uk/itm/… The other is from a Sunfounder kit and I can't find a specific link, only that it is a "I2C LCD 1602". – Konstantinos May 28 '15 at 0:01
  • Don't waste your time on that though, I'll figure something out and let you know. :) – Konstantinos May 28 '15 at 0:04
  • 1
    Pins 1, 2, and 3 select the I2C address of the device. If you lift one of them off the board and solder a wire to ground then you can change the address. – Ignacio Vazquez-Abrams May 28 '15 at 0:32
0

You may be able to wire them in parallel, if you can hold the clock (SCL) high (for one at a time).

Put a diode in to stop the other one going high as well.

Pick a spare pin on your arduino (I will use digital pin 7 for device A, 8 for device B, but it doesn't matter which). When you want to talk to device A, make sure pin 7 is in high impedance mode, and 8 is high. Talk to device A. Stop talking to device A. Put pin 8 in high impedance mode, and pin 7 to high. Talk to device B. Wash, rinse, repeat. So long as a device sees it's clock as high, it won't listen or talk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.