I'm trying to get this sketch to work with my 20x4 display. Can someone else try it out and see if it works for them? The LCD I have is originally a parallel connection but I installed an I2C backpack. I have tried many different libraries and nothing is working right. All I can get on the display is an 'H' at the top line and first character.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.print("Hello, world!");
}
void loop()
{
}
There are many libraries out there all called "LiquidCrystal_I2C". They are not all the same and don't work on all backpacks.
The one you have works with your backpack but is an old LiqiudCrystal_I2C library.
This bug was fixed about two years ago.
You should use the LiquidCrystal_I2C library that is available in the IDE library manager.
As an alternative, I would recommend my hd44780 library package.
It is available in the IDE library manager so it can quickly and easily be installed from the IDE gui using the library manager.
With other i2c LCD libraries you must specify the address. Most libraries are also hard coded to work with backpacks that use a specific pin mapping between the PCF8574 and the hd44780 LCD display and if your backpack doesn't use that pin mapping, it won't work.
A few libraries, like fm's NewLiquidCrystal library allow the sketch to configure the PCF8574 pin mappings and backlight control.
If the pin mappings are not specified correctly, it will not work.
The hd44780 library can auto detect everything, the i2c address, the pin mappings, and the backlight control.
You can read more about it here: GitHub - duinoWitchery/hd44780: Extensible hd44780 LCD library
The hd44780 github page contains information about the library including installation instructions.
Use the IDE library manager to install it as it is easier and faster than trying to do it manually or using the zip install.
Also, by using the IDE library manager it ensures that the library is installed properly not to mention that you will also get the latest tested version of the library.
The library package includes support for several different h/w i/o interfaces used to communicate with the LCD module.
Each i/o interface has its own i/o class and its own set of examples.
The examples for each i/o class are grouped together in a directory by the name of the i/o class.
While all the examples are always available regardless of which h/w you actually have, using an example for an i/o class that is for different h/w will not work.
It will compile but obviously will not work.
The i/o class you will want to use for that backpack which contains an i2c i/o expander chip is hd44780_I2Cexp
That i/o class includes a diagnostic sketch (I2CexpDiag) which will test the i2c signals and internal RAM of the LCD module to verify that the the library is properly communicating with the LCD module.
It is useful to first run this sketch to verify that the library is properly talking to your backpack and LCD module.
Read the instructions in the sketch for how to run it and what to expect on the serial monitor.
After running the diagnostic sketch, you can run and look at other sketches for the hd44780_I2Cexp i/o class like the HelloWorld sketch to see what header files need to be included and how to declare the lcd object.
The hd44780 library contains additional capabilities not available in other libraries like
- return status to tell if API functions are not working correctly (usually do to i2c communication issues)
- ability to enable automatic line wrapping
- ability to read the display RAM or LCD status
- faster than other libraries as Arduino can run in parallel with LCD commands/instructions
I would recommend first running the diagnostic skech I2CexpDiag to verify that everything is working, then you can run and look at the other examples included in the hd44780_I2Cexp i/o class (like HelloWorld) to see the what header files need to be included and how to declare the lcd object.
--- bill
I was finally able to find a library that works. I am able to get all 4 lines of the 2004 lcd to show text.
What library did you send up using?
If you are going to use Liquidcrystal_I2C why wouldn't you use the the one from the ide library manager? Just a few clicks and the library manager installs the latest version for you right from the ide.
bperrybap:
If you are going to use Liquidcrystal_I2C why wouldn't you use the the one from the ide library manager? Just a few clicks and the library manager installs the latest version for you right from the ide.
Because I had no idea I could do that. Thanks for letting me know though. This may make it easier for me to get my projects running.
bigone5500:
Because I had no idea I could do that.
I recommended it back post #1.
--- bill
bperrybap:
I recommended it back post #1.
--- bill
DOH!!! I suppose I misread that... 