Found multiple topics with the same problem, but none of them could solve my problem.
I'm using a Arduino Nano with a 20x4 LCD connected to it by using I2C. Too bad the display only displays squares and not the text I'm trying to display.
Connected the pins of the LCD to the following pins of the Arduino Nano:
VCC > +5V
GND > GND
SDA > SDA (A4)
SCL > SCL (A5)
First of all I tried the code form the vender where I bought the LCD. The code compiles and when I upload it, it only displays squares. I tried adjusting the potmeter, but it doesn't help.
For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.
Install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.
The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.
groundFungus:
For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.
Install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.
The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.
It works! Thanks for helping me! I didn't ground the RW pin, but I used the HD44780 library.
I used the example ...\Arduino\libraries\hd44780\examples\ioClass\hd44780_I2Cexp\HelloWorld
For future reference in case anyone who has a similar problems comes across this thread...
I don't think it's a good idea to try grounding the RW pin when the LCD is being driven by an I2C adapter.
When using a parallel connection without any adapter you can connect the R/W pin to GND instead of connecting it to the Arduino. If you do connect it to the Arduino then the LiquidCrystal library will set the pin low and the effect will be the same.
When using the adapter you don't (easily) have the option of grounding the pin without also leaving it connected to the IC on the adapter. This means that if you do ground the pin, and if the library driving the adapter sets the pin high at some point, you run the chance of damaging the adapter IC.
I believe that the hd44780 library does drive the pin high while it is analyzing the connections. I've been wrong before and Bill isn't shy so I'm sure he will let us know if this is or is not correct.
My apologies. Floresta is right. My thinking was not clear. The RW pin will be be connected to one of the I2C expander pins so should just be left alone. The RW pin would only be grounded if using the 4 or 8 bit interface and a library that does not read from the LCD.
floresta:
This means that if you do ground the pin, and if the library driving the adapter sets the pin high at some point, you run the chance of damaging the adapter IC.
Well, no, you don't risk damaging the adapter which uses a PCF8574.
odcodcodc,
I'm curious if you adjusted the contrast pot. The first photo looks like a maladjusted pot since both lines of text are showing all pixels on.
Don,
The datasheet for the PCF8574 is not very clear. They use the term quasi bi-directional pins.
What that really mean is that they drive the pins low but use a weak pullup for the HIGH output.
This allows using the pin for an input as an external signal can override the pullup.
In terms of probing, all the signals start out "high" and then there is some lowering of pins to try to figure out which is RS vs EN.
While I would also like to this probing and autoconfigure for the MCP23008 parts, I won't since that part drives the signals both ways, and you can end up shorts and the MCP parts have a pretty strong sink and source current capability.
bperrybap:
The datasheet for the PCF8574 is not very clear. They use the term quasi bi-directional pins.
What that really mean is that they drive the pins low but use a weak pullup for the HIGH output.
This allows using the pin for an input as an external signal can override the pullup.
Yes, it is a bit murky in regard to the specification as to which Vcc voltage this will happen, but when a pin is defined as HIGH but shorted to ground, it will indefinitely and comfortably supply a pull-up current of about 100 µA.
At the moment when it is written to be high it will briefly drive the pin with at least 1 mA and possibly 4 mA in an attempt to rapidly drive it HIGH. This pulse could be prolonged if the I2C clock was stretched at that point. In normal use however, holding pins LOW is completely harmless.
And I was cautious to refer only to the PCF857x, which represents the vast majority of I2C backpacks.