I2C LCD not showing sensor data or text

So my lcd was working fine even with the I2C. i printed custom text even displayed time(from the arduino). but now that i have connected an RTC1307 module to the bus and a DHT11 sensor. The lcd is not displaying anything. its just blank. i got it to work one or two times by uploading a hello world example without altering it and it worked fine but now that i upload that even that does not work.
I have established an SDA and an SCL bus on the breadboard + and - rails and placed the pins close to each other. but i have not attached pull up resistors to any of the data or scl lines. assuming that it came with an already installed pull up resistor since it came in the form of a module. and i have connected the 5v and gnd the same through rails.

I barely got the RTC set up. and that would have never happened had i not tried it with a macbook. it still gives me the same errors. i also gave up on a esp8266 module that i was trying to work with my project. tried so many libraries. but anyway. for now i would be thankful if someone could help me out with display problem.
I will be using the “-” instead of a hash sign since i dont know if it even exists on the mac(i dont use this laptop)
i will be typing the bare minimum code that i tried with the display which failed.

-include <liquidCrystal_12C.h> // i2c library... tried so many none of them but didn't work. 
-include <wire.h>  // wire library 

LiquidCrystal_I2C lcd(0x3F, 16, 2); 

void setup() {

lcd.begin();
lcd.backlight();
lcd.clear();
}

void loop() {

lcd.setCursor(0,0);
lcd.print("hello World"); // i have also tried the lcd.write() function with some libraries, didn't work. and i have also tried putting this print in the setup block.. didn't work.

}

I have double checked my connections. the sensors and clock show accurate and timed values on the serial monitor. just not on the display. and for some reason the display is not showing the text.

i just don’t get it it was working fine the other day i was displaying readings from 2 sensors. i even installed, deleted reinstalled many libraries.

Try by adding this code lcd.init(); in the setup. Also, I never used lcd.begin();; you may omit this line. Be sure that the device address is indeed 0x3F and not 0x27.

(including header file with '-' sign instead of '#' sign is something new!)

GolamMostafa:
(including header file with '-" sign instead of ‘#’ sign is something new!)

He wasn’t. He explained what the ‘-’ was about in the original post.


manhoosbilli1,
The esp8266 is 3v so you can’t hook its i2c signal pins directly to a 5v i2c bus.
Directly connecting a 3v i2c device to a 5v i2c bus can potentially damage the 3v device.
While there are some ways to cheat with some careful wiring (which can also involve removing pullup resistors),
normally, a voltage leveler is used when mixing 3v i2c and 5v i2c bus signals.

About the LCD device & library, it isn’t clear which “LiquidCrystal_I2C” library you are using, since as you noticed there are many.
My suggestion would be to use my hd44780 library package.
It can be installed directly from the IDE using the library manager. No downloading or messing with zip files is required.
The hd44780 library package includes a hd44780_I2Cexp i/o class for i2c backpacks that use i/o expander chips.
It can auto locate the i2c address, auto detect pin mapping, and detect backlight control to offer a ‘plug and play’ capability.
It also includes a diagnostic sketch I2CexpDiag which can test your i2c signals for pullup resistors and internal LCD ram to verify that the library is able to communicate with the LCD device.
You can read more about it here:

The github repository readme has full detailed instructions on how to install the library (no download or zip file should be necessary if you are using IDE version 1.6.2 or newer).
It also has a summary of the LCD API functions which are LiquidCrystal compatible, and some information about examples.
There is also a wiki with more information. I’d recommend reading that and the section on the hd44780_I2Cexp i/o class.
The library also includes a “Documentation” sketch that can be pulled up in the IDE after installation.
It contains more information about the library and where to locate the library examples for each i/o class - in your case you will be using hd44780_I2Cexp.
It also has links to additional information like Arduino board pinouts, hd44780 LCD information/datasheets, and information on i2c i/o expander chips like the PCF8574.

I would recommend that you first spend a few minutes reading the included information and documentation, then run the included diagnostic sketch I2CexpDiag to test things.
Assuming that the diagnostic tests pass, then have a look at the HelloWorld sketch to see which files need to be included and how to declare the lcd object when using the hd44780_I2Cexp i/o class.

— bill

Never mind i figured it out. When i checked out the library it already contained Wire library so i guess adding it again glitched it out. just for those who have the same problem. hope this helps. i still haven't tried displaying time from the rtc on it yet. i hope the results are good.

Thanks for the esp8266 tip i never thought about that. i did make a 3.3v voltage divider (main source taken from arduino 5v pin). and i thought that was it and that it could actually communicate to the other devices using the same sda scl bus. how foolish of me. i guess that's how forums help.
I would love to find out a way around this. maybe if someone could guide me to a post or a blog where i can learn to make something that would be a bridge to communicate between arduino and esp. however if it's a lot of work i dont mind buying a pre-built version.

For 3v masters talking to 5v slaves you have two choices:

  • use a level shifter (they are cheap)
    Just be careful as there are two different types and depending on which one you get, you won't connect the 3v line to the 3v master.
  • cheat - which is cheaper and usually works, but does violate the i2c spec and the specs for the slave devices.

To do the cheating method, you typically remove all the pullup resistors to 5v and then add a pullup resistor to 3v.
3v is typically high enough for the 5v slave to see the signal as high even though it is out of spec.

I prefer using a level shifter as they cheap, small and ensure no issues, but I've also done the cheating method.

I have used both methods on esp8266 modules talking to 5v I2C backpacks.

The issue you can (will) run into is that many 5v i2c slaves include their own pullups.
You will have to remove those to ensure that there is only your 3v pullup and no 5v pullups exist anywhere else.

---bill

Thanks for the clarification bill :slight_smile: