Why is LCD not displaying?

I’m trying to display ppm values from a gas sensor on the LCD but no letters are showing on the display. The backlight is on and the Arduino Uno seems to be working fine so I think the problem is with the code??

I’m totally new at this so any suggestions?? Thanks in advance

Link to LCD: https://www.amazon.com/gp/product/B01E4YUT3K/ref=ppx_yo_dt_b_asin_title_o03_s00?ie=UTF8&psc=1

This is the code I used

#define I2C_ADDR 0x3F
#include <LiquidCrystal_I2C.h> // library code
#include <Wire.h>
#define MQ135PIN (0)
int gasPinA0 = A0;

LiquidCrystal_I2C lcd(0x3F, 2, 16);

void setup()
{
lcd.init();
Serial.begin(10000);
Serial.print(“Calibrating…”);
lcd.begin (16, 2);
lcd.setCursor(0, 1);
lcd.print (“AirQual Monitor”);

pinMode (gasPinA0, INPUT);
Serial.begin(8000); // start serial port, sets data rate to 8000 bps
delay(5000);

}

void loop()
{ //code for repeats

int analogSensor = analogRead(gasPinA0);
Serial.println(analogRead(gasPinA0));
delay(1000);

lcd.setCursor (0, 1);
lcd.print ("Air Qual: “);
lcd.setCursor (1, 2);
lcd.print (” PPM ");

lcd.clear();
}

There are several different I2C LCDs. They differ in that they have different I2C addresses and I2C expander (the chip in the I2C backpack) to LCD pin mappings. Your code depends on the pin mapping to be the same as the default in the library that you chose. That is the part that trips up many new users of I2C LCDs. There are 2 solutions. One solution is to try to figure out the pin mapping by tracing traces or trial and error. Another solution is to use the hd44780 library. That library will auto detect the I2C address and the I2C expander to LCD pin mapping. You can install the library through the Library Manager in the IDE. Go to Sketch, Include Library, Manage Libraries. Then when the Library Manager loads, choose Displays in the Topic drop down and enter hd44780 in the filter box. Select and install the hd44780 library by Bill Perry. Use the hd44780_I2cexp class. There are examples and a diagnostic program to help get you started.

  lcd.setCursor (0, 1);
  lcd.print ("Air Qual: ");
  lcd.setCursor (1, 2);

The syntax for setCursor is lcd.setCursor(column, line). A 16x2 LCD has lines numbered 0 and 1. There is no line 2.

Read the how to use this forum sticky to see how to properly post your code and some advice on how to get the most from the forum.

never mind

Indeed. :roll_eyes:

The backlight turning on just means you have power.

The next thing to verify is that your SCL and SCK lines are hooked up correctly to the Arduino.

Then verify that you're talking to the correct address

https://retrolcd.com/Help/I2CFinder

That is a simple sketch that you can load up to find the address of any I2C devices connected.

The library I use for the character displays is this one

https://retrolcd.com/Help/LiquidCrystal_I2C

There are so many variations I just picked one and made it available for the curriculum I'm putting together. Just put the files in the same folder as your project and include the h file with quotes

If you download the Dinosaur PDF, starting at about page 22 is the code for using that library to get it initialized so you can print out to the display.

I have had LCD displays that simply did not work. When buying parts, I highly recommend getting them direct from China through AliExpress and buy a handful at a time and sort by orders so you can buy from the vendors with the most orders. I haven't really had many issues with that. These character displays with I2C controller are $2 each.

bkucenski:
The library I use for the character displays is this one
RetroLCD

And that may be working for you however one of the more frequent contributors here is Bill Perry - “bperrybap” - and he has put considerable work into an extremely versatile and comprehensive library with enhanced performance as well the ability to not only locate the I2C address of the display but also to determine the correct backpack matrix to the display amongst the various versions available.

This library has now been incorporated into the main IDE library manager so you install it directly with no further mucking about with downloads and zip extraction to particular directories, and incorporates examples and documentation. Consequently we feel it is actually quite unhelpful to suggest any other library as the “HD44780” library is so thoroughly supported by contributors here as explained in reply #1 above.

I suggest you take a look at it!

With the limited resources of the Arduino, a more generic library may be useful for beginners but is ultimately overkill once you move beyond the beginner stage.

Using bperrybap's LCD library is a no-brainer.

Just do it, as the saying goes.

bkucenski:
With the limited resources of the Arduino, a more generic library may be useful for beginners but is ultimately overkill once you move beyond the beginner stage.

It depends.
A more feature rich library, like the hd44780 library has the advantage of being able to work with any of the i2c backpack designs as well as change out an i2c display without having to recompile the code even if the i2c address or pin mappings change.
It is also quite a bit faster than the other libraries.

--- bill

The question is then, does it only compile the modules required for a particular situation? Or to what extent does it incorporate code which is not needed?

That is the real question posed by bkucenski.

In the 'loop' you display something and immediately delete it with 'lcd.clear'.
In this short time you can see nothing. Move the 'delay' before the 'clear'.
And I think, you dont need the 'delay(5000) in 'setup'.

Paul__B:
The question is then, does it only compile the modules required for a particular situation? Or to what extent does it incorporate code which is not needed?

That is the real question posed by bkucenski.

The answer to that is also, It depends.
I can provide some additional color on that.
(This is from memory, so the exact numbers may be a bit off)

Only compiling the modules needed isn’t the issue as the gcc compiler & linker have had the ability to be told to eliminate unused functions & data for quite some time and the Arduino IDE enables this.
However, there are cases that depending on how the code is written, unused referenced code & data is still pulled in.

The amount of dead wood code & data can vary depending on the version of gcc used and if/how virtual functions are used or if the code is assigned to an interrupt vector.
The ability to prune out unused functions does still exist.; however, the more recent versions of gcc have removed the ability to prune out unused virtual functions as the specific compiler & linker flags to deal with virtual functions (which were not enabled by the Arduino IDE), and linker code have now been removed from gcc.
IMO, this makes using virtual functions very expensive unless you really really need runtime binding which is not something needed or typically ever used in an embedded environment.

IMO, it relegates virtual functions to being a convenience capability that helps out from a s/w maintenance perspective, but there are other C++ techniques that can be used to offer the same capabilities that don’t suffer the dead wood code issue.
At the time I wrote the hd44780 code, I didn’t realize the virtual function dead wood code issue.

The ISR issue can be resolved with clever use of weak attributes, but the Arduino core & bundled libraries don’t do that so if an used Arduino supplied library, like say Wire is linked in, it will drag in all the code even if the sketch never references it.
i.e. including <Wire.h> will include the Wire code even if it is not used by the sketch.
This trips up certain libraries like fm’s newLiquidCrystal as it links in all the i/o classes regardless of which is actually used by the sketch.

The library manager LiquidCrystal_I2C library is a bare bones library that must have the i2c address configured and is hardcoded to a particular pin mapping between the PCF8574 and the LCD. It doesn’t work with several of the software i2c libraries.
If that works for the needed application, it will be the smallest amount of code and includes very little dead wood code.

fm’s newLiquidCrystal compiles all the i/o classes and links them in regardless of them being used and do to poor coding in other Arduino library code referenced, there is few k of unused code that can be dragged in that is unused and unrelated to the i/o class being used. This is not related to the virtual function issue. This is mainly an issue when not using an i2c based device as the Wire library code and data is always linked in regardless of whether it is used by the sketch.

hd44780 only compiles and links in the i/o class that is used by the sketch.
hd44780 with the hd44780_I2C i/o class for an application like a PCF8574 based backpack does end up dragging in around 1.5k or so of uneeded code from a combination of the virtual function issue and the auto chip detect code to determine PCF8574 of MCP23008 and then the MCP23008 support code.
I’m fully aware of these issues and do have plans to resolve this by refactoring the code get around the virtual function issue so that only code that is actually used/referenced is linked in.

I have also been tossing around the idea of releasing a new separate slimmed down library that is just for PCF8574 based backpacks.
I think this could make things even easier for users (especially non English speaking users) since there would be, less documentation to read, no confusion over i/o classes and the code could be even smaller than a refactored hd44780_I2Cexp i/o class as there would be no code to detect and handle other chips

I haven’t had the time to work on it.

— bill

shekhar55:
There are some of the following issues because of LCD is not displaying. www.roku.com/link

And why have you chosen to insert this piece which has no possible connection whatsoever with the previous discussion here and is 100% irrelevant? :astonished:

The previous reply by Paul illustrates why it is essential to include a quote when you reply to a questionable post.

Without that quote Paul's response would be impossible to figure out since the person to whom he addressed his comment seems to have gone back and deleted the post in question.

Don

floresta:
the person to whom he addressed his comment seems to have gone back and deleted the post in question.

I reported it as possible spam with a dodgy link; it may have been moderated away.

floresta:
The previous reply by Paul illustrates why it is essential to include a quote when you reply to a questionable post.

Exactly. And I was caught also yesterday by posting a comment to another dodgy post which disappeared as I replied to it requiring me to promptly delete my comment as I had not quoted it. :grinning:

elvon_blunden:
I reported it as possible spam with a dodgy link; it may have been moderated away.

And it did seem to be spam - I had the same thought myself about reporting it - though the link could almost be helpful to some people. But not here.

Most ironically, the link refers to power supply failure as a possible cause of "no picture" and my Aldi TV failed in that exact mode last Thursday - in the middle of a program. I'm not sure whether I feel like pulling it apart and fault-finding though I presume now I come to think of it that it will likely be the backlight driver - whatever that is - at fault.

Paul__B:
And it did seem to be spam - I had the same thought myself about reporting it - though the link could almost be helpful to some people.

Perhaps that’s the key to good spam: choose an article (presumably just lifted from somewhere) that’s very relevant, then the link is more likely to get clicked as a legitimate part of the content.

(Must remember that :wink: )