arduinoarduino-uno

Create a LiquidCrystal object using a 2 data line LCD


Arduino newbie here trying my first project.

I have purchased an LCD that it said was Arduino compatible. It supports two lines of text with what appears to be two data lines, which are A4 and A5. It also connects to GND and 5V.

Here is the chart from the seller on how to wire it up (which I have followed):

WireUpToArduinoFromLCD

I am now trying code a connection to it, and the LiquidCrystal.h library seems to want to have 4 data lines: https://www.arduino.cc/reference/en/libraries/liquidcrystal/liquidcrystal/

LiquidCrystal(rs, enable, d4, d5, d6, d7)

But I have only 2 data lines.

In addition, it wants to know

the number of the Arduino pin that is connected to the RS pin on the LCD

My LCD does not have an RS pin. (I don't know what that pin might mean.)

Did the seller lie to me? (Meaning is this display not Arduino compatible?)

If not, how can I create a LiquidCrystal instance with only two data lines and no RS pin?


Solution

  • From your documentation your LCD has an I2C interface. You need a different library in this case such as LiquidCrystal_I2C. This code works for me:

    #include <LiquidCrystal_I2C.h>
    
    LiquidCrystal_I2C lcd(0x3f, 16, 2);  // Set the LCD I2C address - ususally 0x27 or 0x3F
    
    void setup() {
        lcd.init();      
        lcd.backlight();
        
        lcd.clear();              
        lcd.print("Hello world");
        
        lcd.setCursor(0, 1);        // go to the next line
        lcd.print("Line Two");
    }
    
    void loop() {
    }
    

    You will need to know the I2C address of the LCD. This is usually 0x27 or 0x3F. Currently the code uses 0x3F (which works with mine). If not try 0x27. If it still doesen't work, reply in the comments, and I will add an address sniffer so you can find out what yours is.

    The pin connections in the image look OK. A4 is indeed the I2C SDA line, and A5 the I2C SCL.