2 unos 2 i2c lcd only one works

hi i have 2 unos with i2c lcds and 2 ds3231 rtcs ,both wired the same all connections good both using same sketch one lcd works as should the other worked for a while ,if i disconnect both one starts up no problem the other goes blank i have found that if i add another lcd to the same connections on the one that does not work, the extra one just flashes but if i disconnect power supply and remove the extra lcd it boots up and original lcd works fine again until disconnected again ,have tried this twice and works again, just wondered whats going on
colin

Which lcd are you using?
Did you change the i2c address on one of them?

just lcd i2c off ebay have changed address but made no difference so put it back so both the same both lcds bought from same place
colin

Did you run the i2c scanner sketch in examples?
You must change the i2c address on one or you'll have problems.

hi
yes i ran the sketch and lcd would not work ,it only started working when connected and using sketch i downloaded will give it another go tomorrow ,have ordered another lcd to see if that works any better
colin

The i2c scanner won't make the lcd work. It checks all the i2c addresses and lets you know if it finds any devices and the address it found them at.

1 Like

oh ok ill look in morning fraid off to work now nights dont you just luv em not
col

Connect one lcd at a time. Run the i2c scanner. See if it shows up.
Do the same with the other lcd. It should show a different address.

Hi
Just tested both and both works on 0x27 ,they both come up with 0x27,0x57and 0x68 have tried these other codes and both lcds freeze but puts the initial text on screen so both only work on 0x27 will keep trying turning on / off next few hrs to see what happens but at minute its working as should on 0x27 that it was set on originally so dont know why was stopping
Colin

You must change the i2c address on one.
If it was mine, I would put a small solder jumper across the A0 pads on one board only.
Connect it. Run the i2c scanner again. It should show up as 0x28.
Once you have that done, let me know by posting the library and sketch you are using to access it.

Edit: I guess it will be LiquidCrystal_I2C?

Hi sorry a jumper from a0 to were not quite sure what you meant bit new and bit thick lol
Colin

I can't see your board from here. Don't know what size it is, or what pads it has.
Most have a potentiometer for adjusting brightness. Next to it are 3 pad sets. Mine aren't labled, just 3 sets of 2 pads.
A0, A1, and A2.
I jumpered the left two with a jumper wire and it it now address 0x26.

A photo that shows all the wires will be very helpful for us.

Quickest solution for two working projects: Build a third one. Get rid of the bad one.

#include <hd44780.h>

#include <LCD_HD44780.h>

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Initialize the LCD, set the I2C address to 0x27 for a 16x2 LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define the digital pin for the relay module
const int relayPin = 7;
int led1 = 8; //green
int led2 = 6; //red
// Pump run time in milliseconds
const unsigned long pumpRunTime = 6000; // 5 seconds

// Interval between watering sessions in milliseconds
const unsigned long wateringInterval = 60000; // 1 hour

// Track the last watering time
unsigned long lastWateringTime = 0;

void setup() {
  // Initialize the LCD
  lcd.init();
  lcd.backlight();

  // Set up the relay pin as an output
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Keep the relay off initially
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
  // Print welcome message on the LCD
  lcd.setCursor(0, 0);
  lcd.print("Water Irrigation");
  lcd.setCursor(0, 1);
  lcd.print("System");
  delay(2000);
  lcd.clear();
}

void loop() {
  // Get the current time
  unsigned long currentTime = millis();

  // Check if it's time to water
  if (currentTime - lastWateringTime >= wateringInterval) {
    // Activate the relay to turn on the pump
    digitalWrite(relayPin, HIGH);
    lcd.setCursor(0, 0);
    lcd.print("Watering...");
    digitalWrite(led1, HIGH);
    digitalWrite(led2, LOW);
    // Keep the pump on for the specified run time
    unsigned long startTime = millis();
    while (millis() - startTime < pumpRunTime) {
      // Continue to display the watering message
      lcd.setCursor(0, 1);
      lcd.print("Pump On");
     // delay 80000;
    }

    // Deactivate the relay to turn off the pump
    digitalWrite(relayPin, LOW);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Watering Done");
    digitalWrite(led1, LOW);
    digitalWrite(led2, HIGH);
    // Update the last watering time
    lastWateringTime = currentTime;
  } else {
    // Display the time remaining until the next watering session
    lcd.setCursor(0, 0);
    lcd.print("Next in:");
    lcd.setCursor(0, 1);
    unsigned long timeRemaining = (wateringInterval - (currentTime - lastWateringTime)) / 1000;
    lcd.print(timeRemaining);
    lcd.print(" sec");
  }

  delay(1000); // Update every second
}
![20240605_165858|375x500](upload://731b4SxezkLBzBcKiFufozONR7N.jpeg)
![20240605_165910|666x500](upload://gV1B0iXbtX2dWnSRdfpY51J6JSr.jpeg)
![20240605_165923|666x500](upload://eS4O0MkzstXjx9rkdNZPoNoRcya.jpeg)
![20240605_170102|666x500](upload://zzI4uZwOHqggGeLn7XcCOD8k2l2.jpeg)
type or paste code here

hope this helps as said 2 seperate unos and lcds
colin

Here is the datasheet for a similar unit to mine.
This has the address encoding. It has the labels A0 A1 & A2 next to the pot. Mine doesn't have the labels but the pads work the same. Short the A0 pads and you decrement the address by one (0x26).

hi
tried shorting a0 and did not do anything on mine ,but have been starting and stopping it all day and bothj working fine with same address 0x27 they are seperate unos and lcds so would it matter if same address it was just for some reason one did not work properly but seems ok today weird
colin

Can't use them both if you can't change the address.
Well, you can if you want to go with the i2c multiplexer. Way more complex than shorting 2 pads.

ok no problem will have another go in morning many thanks for helping,ill let you know how it goes
colin

Once you get the address changed, this should do a basic test. I have 4x20 displays. You can change to a 2x16 in the LiquidCrystal_I2C declaration.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set for 2 displays with 4 rows of 20 columns
LiquidCrystal_I2C lcd1(0x27,20,4);
LiquidCrystal_I2C lcd2(0x26,20,4);

void setup() {

  lcd1.init();
  lcd2.init();
  lcd1.backlight();
  lcd2.backlight();

  lcd1.clear();
  lcd1.setCursor(0,0);
  lcd1.print("LCD 1");

  lcd2.clear();
  lcd2.setCursor(0,0);
  lcd2.print("LCD 2");
}

void loop() {

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.