Go Down

Topic: LCD 16x2 with I2C dont want display chars (Read 255 times) previous topic - next topic

Thomas85

Hi,
I have problem with my lcd display. Dont want to display "Hello" ;(

Working only backline/ nobacklight

Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() 
{
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("LCD & I2C");
  delay(500);
  lcd.setCursor(0,1);
  lcd.print("**********");
}

void loop()
{
   lcd.backlight();
   lcd.print("Hello");
   delay(5000);
   lcd.noBacklight();
   
   delay(5000);
}

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. 

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display.  Run the diagnostic sketch and post the results.

Erik_Baas

If the backlight works, the address (0x27) is correct. Try rotating the trimpot on the I2C interface clockwise to increase the contrast of the display.

bperrybap

#3
Jun 26, 2019, 09:53 am Last Edit: Jun 26, 2019, 09:54 am by bperrybap
If the backlight works, the address (0x27) is correct.
Depends on what you mean by "works".

If "works" means that the backlight can be controlled by s/w to turn it on and off, then yes the address is correct.
(That sketch doesn't attempt to control the backlight on & off, so it seems to be an unknown)

If "works" simply means that the backlight is on, then there is no assurance that the i2c address is correct.


There are several different backpack designs.
Some use an active high signal to turn on the backlight some use an active low signal to turn on the backlight.
The PCF8574 powers up with all the i/o pins in input mode. Internally this is done with pullup resistors so they look like a high signal.
If the backpack design uses an active high backlight signal to turn on the backlight, then the backlight will turn on as soon as the backpack has power.
No initialization is needed.
So  if the backpack is of that design (active high control signal), the backlight will be on even if the i2c address being used is incorrect.

And then there is the pin mappings in the library that must match the way pcf8574 pins are connected to the lcd and backlight circuit.
The LiquidCrystal_I2C library being used has those pin mappings hard coded.
If those mappings don't match the way the h/w is wired, things won't work correctly even if the i2c address is correct.


--- bill


Erik_Baas

(That sketch doesn't attempt to control the backlight on & off, so it seems to be an unknown)
Thomas wrote: "Working only backline/ nobacklight" (note: I assume "backline" was a typo), so there is communication between the Arduno, the backpack and the LCD. That means the I2C address is correct.

Quote
There are several different backpack designs.
I read somewhere on this forum that most LCD's have the same pinout, so I didn't expect any problems there.

Quote
And then there is the pin mappings in the library that must match the way pcf8574 pins are connected to the lcd and backlight circuit. The LiquidCrystal_I2C library being used has those pin mappings hard coded.
That is something I was not aware of. Going to take a look at it. Still a beginner, still learning...  ;-)

floresta

Once you get things working I don't think your "Hello" message is going to appear the way you expect it to. 

Don

bperrybap

Thomas wrote: "Working only backline/ nobacklight" (note: I assume "backline" was a typo), so there is communication between the Arduno, the backpack and the LCD. That means the I2C address is correct.
We don't really know from the OP's comment what he meant.
backline and nobacklight are both typos as neither is a defined method in that library.
I was going by the code that was posted in post #1 which only attempts to turn on the display.
twice: once by init() and once by backlight()

And with that code, just because the backlight is on, it does not mean that the i2c address is correct.

The sketch does not attempt to turn the backlight on and off. (blink the backlight) It merely attempts to turn it on.
If the backpack design is one that turns the backlight on by default with no initialization by the library needed, then there is no way to know if the the backlight was turned on by the sketch telling the library to turn it on, or whether it turned on all by itself when power was applied.


I read somewhere on this forum that most LCD's have the same pinout, so I didn't expect any problems there.
Not quite sure what you meant by this. Were you talking about the pinout of the LCD or the pin mappings used on the backpack? The two are not the same thing. The pinout of the LCD is not likely to be an issue.
i.e. while most hd44780 LCDs do have the same pin-out for the 16 pins, the way those pins are wired to the PCF8574 chip on the i2c backpack can vary. The LiquidCrystal_I2C library assumes a particular way of wiring the pins. If the backpack is not wired that way, then even if the i2c address is correct, things will not work correctly.


The easiest way to determine if things are working and get something up and working is to use the hd44780 library which does not require entering the i2c address or pin mapping information as it automatically determines this information.
In also includes a diagnostic sketch, I2CexpDiag which will test everything and report any issues.

--- bill

Go Up