Available LCDs and libraries

Just a quick question.

I have used the 16x2 LCDs both direct I/O and via I2C. I see there are some 20x4 LCDs available with the I2C interface. Are the Arduino libraries available to drive these?

Which library did you use for the 16x2? You might be able to use the same library for the 20x4, just change the begin to (20, 4). You might also need to change the address and the pin mapping in the constructor depending on the specific LCD module.

I used wire.h and liquidcrystal_I2c.h. There is a line that sets up the LCD for an I2C address, number of rows and columns (LiquidCrystal_I2C lcd(0x27, 16, 2);). So I know hypothetically I can change the values 16 and 2; but I was wondering if anyone had and knew it would work before I spent the money on the LCD.

It has worked for me with 2 different 20x4 LCDs. I have used the same library for 4 wire 16x2 LCDs as well

.

There is a line that sets up the LCD for an I2C address

That's the constructor.

number of rows and columns (LiquidCrystal_I2C lcd(0x27, 16, 2)

that would be something like

 lcd.begin(16, 2);

florinc:
That's the constructor.
that would be something like

 lcd.begin(16, 2);

Don't forget we're talking about the I2C version, not the direct I/O version. I had to change lcd.begin(16, 2) to lcd.begin() and add LiquidCrystal_I2C lcd(0x27, 16, 2) to make the I2C version of the 16x2 display work. And it does work. The question before the group is: Does LiquidCrystal_I2C lcd(0x27, 20, 4) work for the 20x4 LCD with the I2C interface?

adwsystems:
There is a line that sets up the LCD for an I2C address, number of rows and columns (LiquidCrystal_I2C lcd(0x27, 16, 2).

Well, if that works for an I2C backpack, you are very lucky as you have just by chance happened on a backpack which matches that old library. Most backpacks currently available will not and you need to use the more detailed constructor with the fmalpartida new-liquidcrystal library.

Other than that, of course the library should function with the 20 x 4 display. You may need to remember that the third and fourth line are actually extensions of the first and second, though cursor positioning works correctly if you specify within the 20 x 4.

I have found at least 3 different libraries called LiquidCrystal_I2C.h. None of which are on the Arduino site here. Which is the correct one? The best one?

That would be the link I provided.

Paul__B:
That would be the link I provided.

Well that library crashed and burned. I have four 16x2 LCDs that I have purchased over the last 6 months from four different places and none of them work with this library. I am working to determine where I may have gotten the library I have been using. I know it was via a link from the Arduino site here. Anyone have a better library than either the fmalpartida or my current library?

Edit: I found the source of the library I was using. GitHub - fdebrabander/Arduino-LiquidCrystal-I2C-library: Library for the LiquidCrystal LCD display connected to an Arduino board. as recommended to me many months ago.

adwsystems:
I have four 16x2 LCDs that I have purchased over the last 6 months from four different places and none of them work with this library.

I find that extremely improbable indeed.

I did explain (well, attempted to ... ) that using a given library with the abbreviated three argument descriptor will work only for the backpack which the particular library designer possessed at the time and wrote it for, which presumably explains why you have found an odd library with does work with the short descriptor.

The fmalpartida works with all the available backpack versions, however you need to use the complete descriptor and determine what that correct descriptor is using the I2Cguesser code.

I used Nick Gammon's I2C scanner in addition to the fact that I already knew and had working the displays. The address is 0x27 and the only thing connected to the Arduino UNO (nothing else on the I2C or anywhere else on the Arduino).

After replacing the LiquidCrystal_I2C libraries (including an attempt that involved uninstalling the Arduino IDE, deleting the libraries, and then reinstalling the IDE and adding and adding in the new library). I used the example code straight from the website, just changing the address (from 0x38 to 0x27)

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>


#define BACKLIGHT_PIN     13

LiquidCrystal_I2C lcd(0x27);  // Set the LCD I2C address


// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
   
};

void setup()
{
   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );
  
  lcd.begin(16,2);               // initialize the lcd 

   for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd.home ();                   // go home
  lcd.print("Hello, ARDUINO ");  
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print (" FORUM - fm   ");
  delay ( 1000 );
}

void loop()
{
   lcd.home ();
   // Do a little animation by writing to the same location
   for ( int i = 0; i < 2; i++ )
   {
      for ( int j = 0; j < 16; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 1 );
   }
   delay (200);
}

It did not work, blank screen with lots of flickering. One of the displays I am using is I2C 16x2(1602) LCD Display Module for Arduino - DFRobot

One conspicuous item about the fm library is the inclusion of the backlight pin. I don't have any serial enabled LCDs that have or require a output/input to drive the backlight. Many of the serial (I2C) LCDs I looked at do not have a pin for that. I would hope the library can handle that, but since I didn't write the library I don't know.

If it should work, what do I have to do to make it work? Being the link to the fm library is on the arduino site (opposed to being from a forum post), I would to prefer to use it.

adwsystems:
I used Nick Gammon's I2C scanner in addition to the fact that I already knew and had working the displays. The address is 0x27 and the only thing connected to the Arduino UNO (nothing else on the I2C or anywhere else on the Arduino).

If it should work, what do I have to do to make it work? Being the link to the fm library is on the arduino site (opposed to being from a forum post), I would to prefer to use it.

what is the chip connected to the LCD? a TCA9434, PCF8574? MCP23008? MCP23017?

the library need to be written for the correct I2C expander.

Chuck.

If I remember correctly a PCF8574, maybe an PCF8574A (is that an option?). I would need to double check at home tonight. Along those lines, the chip pinout would also have to match the library.

Edit: It is a PCF8574T chip.

adwsystems:
If I remember correctly a PCF8574, maybe an PCF8574A (is that an option?). I would need to double check at home tonight. Along those lines, the chip pinout would also have to match the library.

trace out the wiring from LCD module to the IO Expander. The fdebrabander Arduino-LiquidCrystal-I2C-library uses these defaults for defining how the module is wired.
the LCD databus is connected in 4bit mode using P4..P7, RS = P0, Rw=P1, En=P2, backlight = P3.
This must match your module. Else change the defines in your library.

// flags for backlight control
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00

#define En B00000100  // Enable bit
#define Rw B00000010  // Read/Write bit
#define Rs B00000001  // Register select bit

chuck.

Chuck:

The fmalpartida library, that was suggested to be used (post #6), is not working for the same displays.

If you are suggesting to use the fdebrabander library, then you are linking to the library I am using and is working for me (see post #9). Is that what I am reading?

adwsystems:
Chuck:

The fmalpartida library, that was suggested to be used (post #6), is not working for the same displays.

If you are suggesting to use the fdebrabander library, then you are linking to the library I am using and is working for me (see post #9). Is that what I am reading?

I understood that you had not been able to use your I2C LCD.

I was trying to show you how you could modify that library to fit your hardware.

If your LCD is now working, sorry I wasted your time. I thought you had not yet found a matching library.

Chuck.

The situation started as a question about a library capable of running both the 16x2 and 20x4 LCD via I2C. I have been using the fdebrabander library, which you suggested, to run the 16x2 I2C LCD quite successfully. Paul suggested using the fmalpartida library, which when implemented did not work on any of my LCDs. Do you know if the fdebrabander library is compatible and will also drive a 20x4 LCD?

adwsystems:
The situation started as a question about a library capable of running both the 16x2 and 20x4 LCD via I2C. I have been using the fdebrabander library, which you suggested, to run the 16x2 I2C LCD quite successfully. Paul suggested using the fmalpartida library, which when implemented did not work on any of my LCDs. Do you know if the fdebrabander library is compatible and will also drive a 20x4 LCD?

as long as the LCD module uses the HD44780 controller, and it is wired the same, it will work.

The HD44780 is used with 8x2,8x1,16x2 .. 40x2 displays.
I have one 40x4 display that is actually 2 40x2 displays in the same case. I have to keep track of where the next character is, turn off cursor on one, turn cursor on the other when I scroll from line 2 to line 3.

I have substituted 16x2 with 20x4, the display still works, but all of the row/column positions are different. Data shows up on the displays but not where you expect it.
(0,0) = top left, if you continously write data after the first line is filled the next position filled is the first character of the third line, then a few missing (hidden characters) then the second line is filled, then the forth line is filled.

You will have to change how you use the display; extra screen space, organization of prompts, etc..

chuck.

adwsystems:
I used Nick Gammon's I2C scanner in addition to the fact that I already knew and had working the displays. The address is 0x27 and the only thing connected to the Arduino UNO (nothing else on the I2C or anywhere else on the Arduino).

You do not appear to be reading or understanding my explanations and clearly do not understand what a "descriptor" is. :roll_eyes:

My comments stand. If you care to read the instructions, the fmalpartida library works beautifully.