HD44780 16x2 LCD with I2C Module not working (Blank Display)

Hello everyone!

I'm currently building a Arduino scale from the YouTube Channel Electronoobs.
Video Link:
How STRAIN GAUGE Works | Precision SCALE With Arduino - YouTube

These are the materials I'm using:

  1. Arduino Uno R3
  2. 1 - 5kg Load Cell with HX711
  3. HD44780 16x2 LCD with I2C Module
  4. Potentiometer, Push Buttons...

This is the Code:

#include <Q2HX711.h>              
//LCD config
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,20,4); 


//Pins 
const byte hx711_data_pin = 3;    
const byte hx711_clock_pin = 2;   
int tara_button = 8;              
int mode_button = 11;             
Q2HX711 hx711(hx711_data_pin, hx711_clock_pin); 

float y1 = 2831.0; 


long x1 = 0L;
long x0 = 0L;
float avg_size = 10.0; 
float tara = 0;
bool tara_pushed = false;
bool mode_pushed = false;
int mode = 0;
float oz_conversion = 0.035274;




void setup() {
  Serial.begin(9600);                 
  PCICR |= (1 << PCIE0);                                                              
  PCMSK0 |= (1 << PCINT0);            
  PCMSK0 |= (1 << PCINT3);             
  pinMode(tara_button, INPUT_PULLUP);
  pinMode(mode_button, INPUT_PULLUP);

  lcd.init();                         
  lcd.backlight();                    
  
  delay(1000);                        

  
  for (int ii=0;ii<int(avg_size);ii++){
    delay(10);
    x0+=hx711.read();
  }
  x0/=long(avg_size);
  Serial.println("Add Calibrated Mass");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" Add Calibrated ");
  lcd.setCursor(0,1);
  lcd.print("      Mass      ");
  
  int ii = 1;
  while(true){
    if (hx711.read()<x0+10000)
    {
      
    } 
    else 
    {
      ii++;
      delay(2000);
      for (int jj=0;jj<int(avg_size);jj++){
        x1+=hx711.read();
      }
      x1/=long(avg_size);
      break;
    }
  }
  Serial.println("Calibration Complete");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  Calibration   ");
  lcd.setCursor(0,1);
  lcd.print("    Complete    ");
}

void loop() {
  
  long reading = 0;
  for (int jj=0;jj<int(avg_size);jj++)
  {
    reading+=hx711.read();
  }
  reading/=long(avg_size);

  
  
  
  float ratio_1 = (float) (reading-x0);
  float ratio_2 = (float) (x1-x0);
  float ratio = ratio_1/ratio_2;
  float mass = y1*ratio;

  if(tara_pushed)
  {
    tara = mass;
    tara_pushed = false;
    Serial.print("TARA");
    Serial.print(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      .         ");    
    delay(300);
    Serial.print(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      ..        "); 
    delay(300);
    Serial.println(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      ...       "); 
    delay(300);   
  }
  if(mode_pushed)
  {
    mode = mode + 1;
    mode_pushed = false;
    if(mode > 2)
    {
      mode = 0;
    }
  }
  
  if(mode == 0)
  {
    Serial.print(mass - tara);
    Serial.println(" g");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print(mass - tara);
    lcd.print(" g"); 
  }
  else if(mode == 1)
  {
    Serial.print(mass - tara);
    Serial.println(" ml");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print(mass - tara);
    lcd.print(" ml");
  }
  else
  {
    Serial.print((mass - tara)*oz_conversion);
    Serial.println(" oz");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print((mass - tara)*oz_conversion);
    lcd.print(" oz");
  }
  
}


ISR(PCINT0_vect)
{
  if (!(PINB & B00000001))
  {
    tara_pushed = true;           
  }
  
  if (!(PINB & B00001000))
  {
    mode_pushed = true;           
  }
}

The Wiring:
Load Cell to HX711:
Red to E+
Black to E-
White to A-
Green to A+
HX711 to Arduino Uno:
GND to GND
DT to Digital Pin 3
SCK to Digital Pin 2
VCC to VCC

HD44780 16x2 LCD (with I2C) to Arduino Uno:
GND to GND
VCC to VCC
SDA to A4
SCL to A5
(Pushbuttons connections aren't necessary)
A User had a simillar Problem and he had been suggested to solder again his LCD. So I'm also posting some photos of my "scale":

Your breadboard has breaks in the middle of the power rails and the top set and bottom set are not connected. Jumper those breaks and connect the top and bottom as shown in the image and see what happens.

If blocks do not show up but the backlight comes on, try adjusting the contrast pot on the I2C backpack (blue square thing).

If you still have trouble it could be related to the LCD library that you are using. 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 menus, 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.

groundFungus:
Your breadboard has breaks in the middle of the power rails and the top set and bottom set are not connected. Jumper those breaks and connect the top and bottom as shown in the image and see what happens.

But he is not at this point using the breadboard for anything other than two separate busbars to connect multiple supply and ground wires, so that is not related to the problem.

The first thing is to adjust the contrast potentiometer on the backpack. Disconnect the SDA and SCL wires to the backpack, connecting only 5 V and ground, power it up and adjust the potentiometer (it will be near one end) until you clearly see all "blocks" on the top line only. Then (power down,) reconnect SDA and SCL and see if you get anything meaningful. If not, start with installing the HD44780 library and running its examples from where you can integrate your own code.

There are various "LiquidCrystal_I2C" libraries and the default you are using is unlikely to match the currently available I2C modules.

We give you a "karma" point for reading the instructions and properly posting your code. :grinning:

I can't upload the Code (on this forum) of the Diagnostic Sketch, beacause it has more than 9000 characters.

AND the Display is displaying:

LCD:0
0x27, P01245673H

LCD:0
0x27, P01245673H

That means that the first (and only) display that it found has an I2C address of 0x27 and shows the i2C expander to LCD pin mapping (RS, RW, EN, D4, D5, D6, D7, backlight).

That seems to be what is displayed when a diagnostic completes successfully. So, without seeing the diagnostic output, I would say that your display is OK.

Have you tried the hd44780 library "Hello World" sketch from the hd44780_I2Cexp class examples?

I can't upload the Code (on this forum) of the Diagnostic Sketch, beacause it has more than 9000 characters.

We don't want to see the code from the diagnostic sketch, we want to see the output copied from serial monitor.

And have you adjusted the display as advised so that the "blocks" are showing? No point going further if you have not.

melonenbuddy123:
I can't upload the Code (on this forum) of the Diagnostic Sketch, beacause it has more than 9000 characters.

AND the Display is displaying:

LCD:0
0x27, P01245673H

Is that all that shows up on the LCD display?
It doesn't end up showing other things and eventually showing an elapsed time?

You want to look at serial output. Follow the instructions in the I2CexpDiag sketch to see the serial output.
If the diagnostic sketch is locking up, we need to see the serial output to see how far along it is getting.

--- bill

Yes, I have done this with the on-board potentiometer and yes after this it showed an elapsed time.

If you saw the elapsed timer, then everything is working.

I just noticed:

LiquidCrystal_I2C lcd(0x3f,20,4);

vs

LCD:0
0x27, P01245673H

Notice the issue?
Hint: look at the i2c adress.

This is why I would recommend switching over to use the hd44780 library with the hd44780_I2Cexp i/o class.
It is easier to get working since you don't have to manually configure anything other than the rows and columns.

Save yourself some grief and just switch over to the hd44780 library.

--- bill

Should it look like this?:

#include <Q2HX711.h>              
#include <Wire.h> 
#include <hd44780_I2Cexp>
hd44780_I2Cexp lcd(0x27,20,4);

(Edit): There is an error...

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\E7470\Downloads\Scale_code\Scale_code.ino:9:26: fatal error: hd44780_I2Cexp: No such file or directory

 #include <hd44780_I2Cexp>

compilation terminated.

exit status 1

Look at the examples in the hd44780 library hd44780_I2Cexp i/o class to see the proper header files to include, the proper way to declare your lcd object, and the proper API call for initialization.

--- bill

Hi!

Well, I made some changes in the Code after looking at the examples:

#include <Wire.h> 
#include <hd44780>
#include <hd44780_I2Cexp.h>
#include <Q2HX711.h>

hd44780_I2Cexp lcd(0x27, I2Cexp_P01245673H, 0,1,2,4,5,6,7,3,HIGH); 

 
const byte hx711_data_pin = 3;    
const byte hx711_clock_pin = 2;   
int tara_button = 8;              
int mode_button = 11;             
Q2HX711 hx711(hx711_data_pin, hx711_clock_pin); 

float y1 = 2831.0; 

long x1 = 0L;
long x0 = 0L;
float avg_size = 10.0; t
float tara = 0;
bool tara_pushed = false;
bool mode_pushed = false;
int mode = 0;
float oz_conversion = 0.035274;




void setup() {
  Serial.begin(9600);                 
  PCICR |= (1 << PCIE0);                                                         
  PCMSK0 |= (1 << PCINT0);            
  PCMSK0 |= (1 << PCINT3);               
  pinMode(tara_button, INPUT_PULLUP);
  pinMode(mode_button, INPUT_PULLUP);

  lcd.init();                         
  lcd.backlight();                     
  
  delay(1000);                        

  
  // tare procedure
  for (int ii=0;ii<int(avg_size);ii++){
    delay(10);
    x0+=hx711.read();
  }
  x0/=long(avg_size);
  Serial.println("Add Calibrated Mass");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" Add Calibrated ");
  lcd.setCursor(0,1);
  lcd.print("      Mass      ");

  int ii = 1;
  while(true){
    if (hx711.read()<x0+10000)
    {
      .
    } 
    else 
    {
      ii++;
      delay(2000);
      for (int jj=0;jj<int(avg_size);jj++){
        x1+=hx711.read();
      }
      x1/=long(avg_size);
      break;
    }
  }
  Serial.println("Calibration Complete");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  Calibration   ");
  lcd.setCursor(0,1);
  lcd.print("    Complete    ");
}

void loop() {
 
  long reading = 0;
  for (int jj=0;jj<int(avg_size);jj++)
  {
    reading+=hx711.read();
  }
  reading/=long(avg_size);

  
  
 
  float ratio_1 = (float) (reading-x0);
  float ratio_2 = (float) (x1-x0);
  float ratio = ratio_1/ratio_2;
  float mass = y1*ratio;

  if(tara_pushed)
  {
    tara = mass;
    tara_pushed = false;
    Serial.print("TARA");
    Serial.print(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      .         ");    
    delay(300);
    Serial.print(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      ..        "); 
    delay(300);
    Serial.println(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      ...       "); 
    delay(300);   
  }
  if(mode_pushed)
  {
    mode = mode + 1;
    mode_pushed = false;
    if(mode > 2)
    {
      mode = 0;
    }
  }
  
  if(mode == 0)
  {
    Serial.print(mass - tara);
    Serial.println(" g");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print(mass - tara);
    lcd.print(" g"); 
  }
  else if(mode == 1)
  {
    Serial.print(mass - tara);
    Serial.println(" ml");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print(mass - tara);
    lcd.print(" ml");
  }
  else
  {
    Serial.print((mass - tara)*oz_conversion);
    Serial.println(" oz");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print((mass - tara)*oz_conversion);
    lcd.print(" oz");
  }
  
}


ISR(PCINT0_vect)
{
  if (!(PINB & B00000001))
  {
    tara_pushed = true;           
  }
  
  if (!(PINB & B00001000))
  {
    mode_pushed = true;           
  }
}

But there is still this error:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\E7470\Downloads\Scale_code\Scale_code.ino:7:19: fatal error: hd44780: No such file or directory

#include

compilation terminated.

exit status 1

It is hard to believe that you looked at the example code given the errors.

It is #include <hd44780.h>, you left off the .h.

And #include <hd44780ioClass/hd44780_I2Cexp.h>, not #include <hd44780_I2Cexp.h>

hd44780_I2Cexp lcd(0x27, I2Cexp_P01245673H, 0,1,2,4,5,6,7,3,HIGH); is wrong.

This is the right way:

#include <Wire.h> 
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>you

hd44780_I2Cexp lcd;

The hsd44780 library uses the begin() function, not init.

lcd.begin(16,2);
if (hx711.read()<x0+10000)
    {
      .  //  ************** a stray dot
    }

And the code compiles.

#include <Wire.h> 
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <Q2HX711.h>

hd44780_I2Cexp lcd; 

 
const byte hx711_data_pin = 3;    
const byte hx711_clock_pin = 2;   
int tara_button = 8;              
int mode_button = 11;             
Q2HX711 hx711(hx711_data_pin, hx711_clock_pin); 

float y1 = 2831.0; 

long x1 = 0L;
long x0 = 0L;
float avg_size = 10.0; // t *********** stray t
float tara = 0;
bool tara_pushed = false;
bool mode_pushed = false;
int mode = 0;
float oz_conversion = 0.035274;




void setup() {
  Serial.begin(9600);                 
  PCICR |= (1 << PCIE0);                                                         
  PCMSK0 |= (1 << PCINT0);            
  PCMSK0 |= (1 << PCINT3);               
  pinMode(tara_button, INPUT_PULLUP);
  pinMode(mode_button, INPUT_PULLUP);

  lcd.begin(16,2); // changed                        
  lcd.backlight();                     
  
  delay(1000);                        

  
  // tare procedure
  for (int ii=0;ii<int(avg_size);ii++){
    delay(10);
    x0+=hx711.read();
  }
  x0/=long(avg_size);
  Serial.println("Add Calibrated Mass");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" Add Calibrated ");
  lcd.setCursor(0,1);
  lcd.print("      Mass      ");

  int ii = 1;
  while(true){
    if (hx711.read()<x0+10000)
    {
      //. ********** stray dot
    } 
    else 
    {
      ii++;
      delay(2000);
      for (int jj=0;jj<int(avg_size);jj++){
        x1+=hx711.read();
      }
      x1/=long(avg_size);
      break;
    }
  }
  Serial.println("Calibration Complete");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  Calibration   ");
  lcd.setCursor(0,1);
  lcd.print("    Complete    ");
}

void loop() {
 
  long reading = 0;
  for (int jj=0;jj<int(avg_size);jj++)
  {
    reading+=hx711.read();
  }
  reading/=long(avg_size);

  
  
 
  float ratio_1 = (float) (reading-x0);
  float ratio_2 = (float) (x1-x0);
  float ratio = ratio_1/ratio_2;
  float mass = y1*ratio;

  if(tara_pushed)
  {
    tara = mass;
    tara_pushed = false;
    Serial.print("TARA");
    Serial.print(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      .         ");    
    delay(300);
    Serial.print(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      ..        "); 
    delay(300);
    Serial.println(".");
    lcd.setCursor(0,0);
    lcd.print("      TARA      ");
    lcd.setCursor(0,1);
    lcd.print("      ...       "); 
    delay(300);   
  }
  if(mode_pushed)
  {
    mode = mode + 1;
    mode_pushed = false;
    if(mode > 2)
    {
      mode = 0;
    }
  }
  
  if(mode == 0)
  {
    Serial.print(mass - tara);
    Serial.println(" g");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print(mass - tara);
    lcd.print(" g"); 
  }
  else if(mode == 1)
  {
    Serial.print(mass - tara);
    Serial.println(" ml");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print(mass - tara);
    lcd.print(" ml");
  }
  else
  {
    Serial.print((mass - tara)*oz_conversion);
    Serial.println(" oz");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     SCALE!     ");
    lcd.setCursor(0,1);
    lcd.print((mass - tara)*oz_conversion);
    lcd.print(" oz");
  }
  
}


ISR(PCINT0_vect)
{
  if (!(PINB & B00000001))
  {
    tara_pushed = true;           
  }
  
  if (!(PINB & B00001000))
  {
    mode_pushed = true;           
  }
}

The lcd is working now. I wrote a completly new code and i downloaded another library.

Thank u!

melonenbuddy123:
The lcd is working now. I wrote a completly new code and i downloaded another library.

Thank u!

You have to admire the world of Trump !

melonenbuddy123:
The lcd is working now. I wrote a completly new code and i downloaded another library.

Wow, I'm surprised.
After being shown your i2c address was incorrect for your original library.
then being pointed to a 2nd library (hd4780) that easier to use since it auto self configures itself,
you decided to switch to 3rd library.

I'm very curious which library you switched to.

--- bill

The OP worked hard to provide photos and information in #0, #3, #7

Clearly #9, #11 show that he does not understand replies or know how to write/edit code.

Following a project "how to" on the Internet should be straightforward.
Unfortunately it runs into the "different LiquidCrystal_I2C libraries with same names" feature.

I would hope that future "Internet tutorial projects" start using hd44780.h

It is important that projects work first time. It inspires confidence. The enthusiast then goes on to adapt code for her own projects.

David.

1 Like

This topic was automatically closed after 120 days. New replies are no longer allowed.