Normal LCD to I2C LCD


I’m working on this file and I’m trying to change the code so that it will work with the I2C LCD. The code is fully functioning with the LCD without the I2C. Can someone help me to change the code so it will work on the I2C LCD? Thanks

pulse_sensor.ino (10.4 KB)

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

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)

This is the my LCD and libraries that I’m using but doesn’t work when I input them

"doesn't work" is very vague and does not explain what the problem you are experiencing is. It could be that the code does not compile, or it could be that the code compiles and uploads but does not work or it could be that the compile worked, and the code is good but there is an issue with the LCD backpack or its soldering. Since you have not shown us the exact code you are running, or photos of the backpack, or any error messages (if any) we can't know how to help.

But, when first getting an i2c backpack up and running it is best to use one of the examples that is included with the library rather than your own code.

Keep in mind that all i2c backpacks are not made the same way so the library must not only know the i2c address but must know how the PCF8475 is wired up to the LCD module. (different manufactures wire them up differently) Some i2c backpack libraries hard code the pin mappings and some like the one you seem to be referencing allows the pin mappings to be configured. If the pin mappings and the i2c address being used by the library are not correct, it will not work.

Making things a bit more difficult, there are several libraries named "LiquidCrystal_I2C" and they work differently. The one you appear to be referencing is LiquidCrystal_I2C i/o class fm's new LiquidCrystal library as it allows configuring the pin mappings. When creating the LCD object, the constructor with the pin mapping numbers must be correct, so make sure to look closely at your PCB to see how the i/o expander chip i/o pins are wired up to the LCD module to make sure that the numbers you are entering exactly match the pin wiring for your particular i2c backpack PCB. This library must also be installed by replacing the existing LiquidCrystal library. If the installation is not done correctly, the IDE will not locate the library so the code will not compile.

If you want you could use my hd44780 library package. It will auto detect the i2c address and pin mappings. To use it all you have to do is include the appropriate header files and define the lcd object. It can be quickly and easily installed using the IDE library manager. You can read more about it here: The i/o class for i2c backpacks is hd44780_I2Cexp I would recommend that you first run the included diagnostic sketch (I2CexpDiag) which will verify that the library is properly working with your backpack. It will test the i2c signals and then test the internal memory of the LCD module.

There are other examples included for that i/o class that you can look at to see what header files need to be included and how to declare the LCD object.

Once you include the needed header files for the i/o class, and declare the LCD object, the sketch can use the same API calls as the LiquidCrystal library. Note that hd44780 library also some extensions in addition to what is provided by the LiquidCrystal API. There are several additional capabilities that you can read about the github page but a couple of the main ones is that you can test the return status of API calls to see if they failed, and you read from the LCD memory.

--- bill

To make it work you need to do it as follow:
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4); // Set the LCD I2C address – 20 character 4 line I2C Display

Warning Warning Warning Warning Warning
Connect Vcc and Ground, SDA to A4, SCL to A5 on Arduino

add the following lines in the setup:
void setup() {
// put your setup code here, to run once:
lcd.begin(20, 4);
lcd.setCursor(0, 0); //set curso character position=0 line=0
lcd.print("Hello WORLD ");

Good Luck