20x4 LCD not working, Help needed

I have a project where I’ll have to interface 5-6 sensors with arduino via LCD and wireless module as well. I’m trying to interface LCD for now without any sensors.

I’m unable to interface my 20x4 LCD with Arduino.
Initially I tried to connect it directly with Arduino, all I was getting was some Chinese characters moving quickly through the display.

I switched to using an I2C Port Expander Module , still I’m not getting any viable results. All I get is one row of boxes followed by an empty one then another row of boxes followed by another empty row.

I picked up the code from circuito.io, and patched according to its intstructions.

https://www.circuito.io/app?components=512,11021,417987

Moreover, I’m getting an error LCD not found at serial monitor.

The code I’m using is

// Include Libraries
#include "Arduino.h"
#include "LiquidCrystal_PCF8574.h"


// Pin Definitions



// Global variables and defines
// There are several different versions of the LCD I2C adapter, each might have a different address.
// Try the given addresses by Un/commenting the following rows until LCD works follow the serial monitor prints. 
// To find your LCD address go to: http://playground.arduino.cc/Main/I2cScanner and run example.
#define LCD_ADDRESS 0x3F
//#define LCD_ADDRESS 0x27
// Define LCD characteristics
#define LCD_ROWS 4
#define LCD_COLUMNS 20
#define SCROLL_DELAY 150
#define BACKLIGHT 255
// object initialization
LiquidCrystal_PCF8574 lcd20x4;


// define vars for testing menu
const int timeout = 10000;       //define timeout of 10 sec
char menuOption = 0;
long time0;

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup() 
{
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    while (!Serial) ; // wait for serial port to connect. Needed for native USB
    Serial.println("start");
    
    // initialize the lcd
    lcd20x4.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT); 
    menuOption = menu();
    
}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop() 
{
    
    
    if(menuOption == '1') {
    // LCD Display 20x4 I2C - Test Code
    // The LCD Screen will display the text of your choice.
    lcd20x4.clear();                          // Clear LCD screen.
    lcd20x4.selectLine(2);                    // Set cursor at the begining of line 2
    lcd20x4.print("    Circuito.io  ");                   // Print print String to LCD on first line
    lcd20x4.selectLine(3);                    // Set cursor at the begining of line 3
    lcd20x4.print("      Rocks!  ");                   // Print print String to LCD on second line
    delay(1000);

    }
    
    if (millis() - time0 > timeout)
    {
        menuOption = menu();
    }
    
}



// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{

    Serial.println(F("\nWhich component would you like to test?"));
    Serial.println(F("(1) LCD Display 20x4 I2C"));
    Serial.println(F("(menu) send anything else or press on board reset button\n"));
    while (!Serial.available());

    // Read data from serial monitor if received
    while (Serial.available()) 
    {
        char c = Serial.read();
        if (isAlphaNumeric(c)) 
        {   
            
            if(c == '1') 
    			Serial.println(F("Now Testing LCD Display 20x4 I2C"));
            else
            {
                Serial.println(F("illegal input!"));
                return 0;
            }
            time0 = millis();
            return c;
        }
    }
}

You must try eRadionicaLiquidCrystal library. I will attach it to this post. When you install a library upload this code:

#include "Wire.h"
 
void setup() {
  Serial.begin (115200);
 
  Serial.println ("I2C finder. Finding ...");
  byte count = 0;
   
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Address found: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  
      } 
  } 
  Serial.print ("found");
  Serial.print (count, DEC);
  Serial.println (" device(a).");
}  
 
void loop() {}

Open serial monitor. It will show you address from your display (something like 0x21, 0x23 etc.) then you upload this code

#include "Wire.h" 
#include "LiquidCrystal_I2C.h"
 

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 
#put your address instead of 0x3F
 
void setup()  
{
 
  lcd.begin(20,4);
  lcd.backlight(); 
 
  lcd.setCursor(0,0);    
  lcd.print("Hi world!");  
  
}
 
 
void loop()   
{ }

Try it out!!!

eRadionicaLiquidCrystal.zip (121 KB)

Khetran

Not only can the backpack have different i2c addresses, but it can have the i/o pins on the PCF8574 chip wired up differently to the LCD pins.
The library you have chosen, LiquidCrystal_PCF8574 has the PCF8574 to LCD pin mappings hard coded.
It may or may not work with your backpack as there are several different backpack designs that use different pin mappings.
Also, that library has copyright issues. The Author has violated the GPL by taking a LGPL library, creating a derivative and then assigning a different license that is incompatible with LGPL/GPL. This is a violation of the copyright.

The library in the second post is very old version of fm's newLiquidCrystal library: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
That library allows configuring the pin mappings, but if the mappings provided in the constructor do not match the way backpack was made, it will not work.
It also has copyright issues. The library cannot be licensed as CC BY-SA since it started with some LGPL and GPL code. The most recent version has been corrected to be GPL v3.

I'd recommend that you use my hd44780 library and the hd44780_I2Cexp i/o class.

It will autodetect the i2c address and the i/o pin mappings used on the backpack PCB so it should "just work".
It also includes a diagnostic sketch, I2CexpDiag, to test the i2c interface and LCD memory.

Install it from the IDE library manager. Then run the diag tool.
If there are issues, post the diagnostic output.
If the diagnostic passes, then you can run the other hd44780_I2Cexp i/o class examples.
The library includes lots of documentation in a "Documentation" sketch.

--- bill

Issue Resolved!
Thanks guys

I downloaded a different library and for now LCD seems to be working fine. Although now I'm stuck on the next part.

Which library?