LCD_I2C sometimes works and sometimes doesn't

I've searched and not find exactly same as my problem.

I use a simple wiring: GND-GND VDD-V5 SCL-SCL SDA-SDA. My code is following. I checked it on a mega and worked. I checked it on an uno which wired to a 4*4 keypad, nothing but white first row was seen. I rechecked it (exactly same condition) on the first board (mega) and just white row. After a while and changing codes, connecting and discontenting all thing, changing board, It worked. I checked it several times, and some times LCD works and sometimes just the white row. What do you think?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x3F, 16, 2);
 
void setup(){
  Wire.begin();
  lcd.begin();
  lcd.clear();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Digispark.ir");
  lcd.setCursor(0, 1);
  lcd.print("Check it");
  //lcd.noBacklight();
}
 
void loop(){
}

Have you checked the integrity of your connecting wires?

Don

I checked them several times. I changed them too.
I suspected to integrity of the LCD or its I2C.

Finaly I found the clue!
When I'm using 3.3 V, it's works but with very low light (at highest, and no light at lowest). with 5 volt doesn't work at all. I guess a volt between 3.3 to 5 is good. Is my soldering reason of all things?
What i must to do to fix it?

shimidan:
What i must to do to fix it?

Explain what all this nonsense about 3.3 V and 5 V is. :astonished:

Part of that would be to explain what LCD display parts you are using, how you have it wired together, give a circuit schematic drawing and a picture. However you need to have usable photos of the whole assmebly.

Unless you are a professional photographer and know what you are doing, do not attempt to take photos inside.

Take your parts outside in full daylight but not direct sun. Use a real camera able to focus in detail and if it has no "macro" function, keep at least half a metre away and use the (genuine) zoom.

It could be that your i2c bus is missing the required external pullup resistors on the SDA and SCL signals.
Some LCD i2c backpacks have the pullups on them and some don't.
The Mega boards have pullups on them and the UNO boards do not.
So if you have a backpack without pullups it would not be a problem when used on a mega board since the mega board has them but it would be an issue with an uno.

Yes, the Wire library turns on the AVR pullups on the SDA and SCL signals but those pullups are very weak - too weak.
While it can appear to "work" when no pullups are used (as in the case of an UNO with a slave with no pullups), the pullups are way out of spec and often cause issues.

My suggestion would be install the hd44780 library, and run the included I2CexpDiag sketch under the hd44780_I2Cexp i/o class.
It has a diagnostic that will test the i2c signals and then the i2c backpack and LCD.
If you are missing pullups it will report that in the output.

--- bill

bperrybap:
It could be that your i2c bus is missing the required external pullup resistors on the SDA and SCL signals.
Some LCD i2c backpacks have the pullups on them and some don't.
The Mega boards have pullups on them and the UNO boards do not.
So if you have a backpack without pullups it would not be a problem when used on a mega board since the mega board has them but it would be an issue with an uno.

Yes, the Wire library turns on the AVR pullups on the SDA and SCL signals but those pullups are very weak - too weak.
While it can appear to "work" when no pullups are used (as in the case of an UNO with a slave with no pullups), the pullups are way out of spec and often cause issues.

My suggestion would be install the hd44780 library, and run the included I2CexpDiag sketch under the hd44780_I2Cexp i/o class.
It has a diagnostic that will test the i2c signals and then the i2c backpack and LCD.
If you are missing pullups it will report that in the output.

--- bill

Actually I test on mega (but V 5 did't work).

I will test your suggestion.

Paul__B:
Explain what all this nonsense about 3.3 V and 5 V is. :astonished:

Part of that would be to explain what LCD display parts you are using, how you have it wired together, give a circuit schematic drawing and a picture. However you need to have usable photos of the whole assmebly.

Unless you are a professional photographer and know what you are doing, do not attempt to take photos inside.

Take your parts outside in full daylight but not direct sun. Use a real camera able to focus in detail and if it has no "macro" function, keep at least half a metre away and use the (genuine) zoom.

It take a while. I should test Bill suggestion first. Untill that, suppose simplest wiring: SDA to SDA, SCL to SCL, GND to GND, VDD to 5 or 3.3 V.

shimidan:
Actually I test on mega (but V 5 did't work).

Do you mean 5 volts?

I will test your suggestion.
It take a while. I should test Bill suggestion first. Untill that, suppose simplest wiring: SDA to SDA, SCL to SCL, GND to GND, VDD to 5 or 3.3 V.

I agree with Paul__B, all this 5v vs 3v talk is not making sense.

If you are running your master (Arduino) at 5v which creates & expects a 5v i2c bus, your i2c slaves also need to be powered at 5v.
Running the slaves at only 3v with a 5v master could damage the slave device.
If you do have 3v slave devices, you need to run them at 3v and use a level shifter on the SDA and SCL signals to allow the 5v master and 3v slave devices to properly talk to each other.

I would recommend to immediately stop messing around trying things until everything regarding wiring and voltages is worked out as you could end up frying something.

So show us some photos of everything you have.
In particular some clear photos of your LCD device (front and back sides).
So we can see what you've got, including your soldering.
This will help us determine any potential issues and how it should be wired up.

--- bill