16,2 lcd works 20,4 does not.

I am using the example program from fm’s library. I finally got a sainsmart ic2 module to work with a 16,2 LCD. Now I can not get the 20,4 LCD working. I am using same sketch with changing the lcd.begin(20,4); from lcd.begin(16,2);. I have played with changing this piece of code.

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

No luck.

Thanks in advance!!!

/* YourDuino.com Example Software Sketch
 16 character 2 line I2C Display
 Backpack Interface labelled "A0 A1 A2" at lower right.
 ..and
 Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"
 MOST use address 0x27, a FEW use 0x3F
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here: 
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

/*-----( Declare Variables )-----*/
//NONE

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);  // Used to type in characters

  lcd.begin(20,4);   // initialize the lcd for 20 chars 4 lines, turn on backlight

// ------- Quick 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight(); // finish with backlight on  

//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0  
  lcd.setCursor(0,0); //Start at character 4 on line 0
  lcd.print("Hello, world!");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print("HI!YourDuino.com");
  delay(8000);  

// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Use Serial Mon");
  lcd.setCursor(0,1);
  lcd.print("Type to display");  


}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
 





 {
    // when characters arrive over the serial port...
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
      // clear the screen
      lcd.clear();
      // read all the available characters
      while (Serial.available() > 0) {
        // display each character to the LCD
        lcd.write(Serial.read());
      }
    }
  }

}/* --(end main loop )-- */

There are two models of that sainsmart module. One (1602) works with 16 x 2 LCDs and the other (2004) works with 20 x 4 LCDs. AFAIK they are not interchangeable.

Thanks Delta_G

I have a couple of generic modules. I will see if they work. My Question is though why wouldn’t they work universally? When I use the 8 wire method, I do not wire them differently.

Thanks again.

Ok I just tried the Generic module with know luck. 1602 works and 2004 does not? I looked at the limited info from ebay and it says the the units are universal. However the module looks very similar to the sain smart unit. I then looked back on the Sain smart website and this unit is universal. Does any one have any ideas? Maybe I have a defective unit?

Can you give us a link to the actual module you have? That way we don’t have to keep on guessing. Dontcha think that might be an important little tid-bit of information if you really want help?

weldsmith,
you don’t need to mess with the constructor when changing lcds or geometries.
The constructor tells the library how the PCF8574 is wired up to the hd44780 interface.
It has nothing to do with geometry.
If it worked with a 16x2 LCD and all you did was swap out the 16x2 with a 20x4 then it will work.
I do this all the time.
You haven’t said what “Now I can not get the 20,4 LCD working” means.
There are many ways things “don’t work”.

Delta_G:
There are two models of that sainsmart module. One (1602) works with 16 x 2 LCDs and the other (2004) works with 20 x 4 LCDs. AFAIK they are not interchangeable.

I can’t imagine how that could be possible; can you go into details?

From my observations of MANY i2c backpacks, the backpack module has no clue or dependencies on the actual LCD or display geometry.
Most of the backpacks out there use a i2c PCF8574 i/o expander that simply allows the hd44780 pins to be manipulated from a host i2c device.

Whether the LCD is 16x2 or 20x4 would not matter as both are using the same hd44780 interface.

Now there are some i2c lcd backpacks that use a MCP23008 chip instead of a PCF8574.
Those are not very common and I wouldn’t recommend them since they will always be slightly slower since they have more overhead to control the output port and if you get the pin mapping wrong on one of those, you can damage the backpack or the LCD.

— bill

bperrybap:
I can't imagine how that could be possible; can you go into details?

If the module is just passing commands through to the data pins sure. If it is doing anything else processing wise then I don't know. But the adverts that I saw made it look like they were distinct.

But I will admit that I haven't used anything like this in a long while. Nowadays I tie my 8 data pins to a shift register and stick it on my SPI bus and use this library. I bought a couple hundred 595's a couple years ago so I use them for just about everything.

Schematic can be found here.

Delta_G:
If the module is just passing commands through to the data pins sure.

If the backpack was working with a 16x2 using fm's LiquidCrystal_I2C library then it has a PCF8574 on it and all you can do with that backpack is control the 8 pin output port and so it will work with a 20x4 display just like it did with a 16x2 display since both use the same hd44780 interface pins.

I have seen i2c backpack vendors using all kinds of printed labels on them. And while generally a backpack with a given name printed on it will use a particular pin mapping/wiring, this is not always the case since there are many vendors that steal other vendors designs and it has come to the point that even the fakes are being faked so often you have no idea what you will be getting until you actually get it and visually examine the actual traces on the PCB.
And that is why it is best to use a library that allows the pin mapping to be configured since it will work with any of them.

Here are the labels I've seen on various PCF8574 backpacks and have tested with:
MJKDZ, GYIICLCD, 1602, LCM1602, 2004, LCM2004, LCM1602/2004,
Robot Arduino IIC LCM1602/2004, FUNDUINO, YWROBOT, DFROBOT, SAINSMART, SYDZ,
I2C lcd1602, www.mjkdz.com, I2C LCD extra IO

PCF8574 based backpacks are available for less than $1 USD shipped to your door quantity 1 from places like ebay, so it is hard to beat from a cost perspective vs building your own backpack, regardless of the i/o interface used.

--- bill

Delta_G:
If the module is just passing commands through to the data pins sure. If it is doing anything else processing wise then I don't know. But the adverts that I saw made it look like they were distinct.

How could it be doing anything else - it's chip is just a dumb I2C I/O extender?

The LCD controller has no way to differentiate a 16x2 display from a 20x4 display when used with it's 'normal' parallel connection to the microcontroller. The addition of a simple I2C I/O extender doesn't change anything.

The main reason you must tell the library about the configuration is so that it can convert the row and column cursor positioning commands into LCD memory addresses. Unfortunately the LiquidCrystal library doesn't always do this correctly as anyone who tries to use a 16x4 display will find out.

Don

floresta:
How could it be doing anything else - it's chip is just a dumb I2C I/O extender?

That's why I qualified that with, "I don't know". I was just going off the advert for a chip that I found when I searched the description that the OP gave. We still don't know exactly which one he has.

While what you say makes total sense, I couldn't put that together and figure out why they offered two different part numbers if they were both the same.

Ok I am back, I have come to the conclusion I have a bad 2004 unit all thougth I am pretty sure I have had it working through the 4 bit method. Some day I will un-solder and try the old way. 1602 will work for proofing my project for now.

For the argument both use the PCF8574T chip.

Bill,

For my education, you are saying all LCDs have the same trace pattern and the EN, RW, EN etc. will always have the same 1-16 input Pattern? All that I have read points to that and yes I have read half of the posts on the web in the last 10 hrs.

Thanks again Guys.

weldsmith:
Ok I am back, I have come to the conclusion I have a bad 2004 unit all thougth I am pretty sure I have had it working through the 4 bit method. Some day I will un-solder and try the old way. 1602 will work for proofing my project for now.

For the argument both use the PCF8574T chip.

"both" Wait... Huh? I thought you said that you were taking a single i2c backpack and moving it from a 16x2 display to a 20x4 display.
Are you now saying that there is more than one backpack involved?

Bill,

For my education, you are saying all LCDs have the same trace pattern and the EN, RW, EN etc. will always have the same 1-16 input Pattern? All that I have read points to that and yes I have read half of the posts on the web in the last 10 hrs.

I'm sure Don will jump in here in minute but basically hd44780 defines 14 pins.
And the other 2 pins are for the backlight.

Nearly all the hd44780 LCD modules use the same 16 pin pinout so if you google for a hd44780 pinout you can see what each of the 16 pins do.

In terms of the backpack, the issue is that how the PCF8574 is wired up to the hd44780 pins is not a "standard" and different backpack makers wire them up differently. There is no way to determine how the PCF8574 is wired up to the hd44780 pins and that is why you have to tell the library how it is wired up.

--- bill

Earlier in the Post I stated that I switched the back pack to a generic back pack, But I got the came results. I used the same Back pack for the 2004 and the 1602, Then, tired of the soldering dance I used a Generic on the 2004 with the same results.

I did Forget to mention that yes the LCD back light did strobe in the setup and I could clearly see the first and third row was lit and the contrast would work on those two rows only, but no characters would appear.

I think I have beat this dead horse enough. I will visit it again later. Unless there is still a chance that set up could be still an issue then I will change the setup if some one has an idea.

Thanks.

I'm sure Don will jump in here in minute but basically hd44780 defines 14 pins.
And the other 2 pins are for the backlight.

This is correct. Back when the controller was first introduced, and we are talking about decades ago, not months or years, the backlight, if present, was typically an electroluminescent panel requiring over 100 v (yes, one-hundred). The display used the 14-pin interface we still use and the backlight connections were at the end of the display.

Nearly all the hd44780 LCD modules use the same 16 pin pinout so if you google for a hd44780 pinout you can see what each of the 16 pins do.

This is also correct but the key word is 'nearly' and then only if the row of pins is above and to the left of the display itself. There are a few rogue displays out there with the functions of pins 1 and 2 reversed. You find out about this quickly when the chip gets really hot and the smoke comes out.

If the pins are below and to the left then all bets are off. The pin numbers still match those of the standard displays but their locations are frequently different.

Don

. . . and I could clearly see the first and third row was lit and the contrast would work on those two rows only, but no characters would appear.

This means that the LCD controller is getting power and probably is functional. You don't need any code to accomplish this and you don't have to connect the data and control lines either, which means that it doesn't matter how the PCF8574 is wired up to the hd44780 pins.

Don

weldsmith:
Earlier in the Post I stated that I switched the back pack to a generic back pack, But I got the came results. I used the same Back pack for the 2004 and the 1602, Then, tired of the soldering dance I used a Generic on the 2004 with the same results.

I did Forget to mention that yes the LCD back light did strobe in the setup and I could clearly see the first and third row was lit and the contrast would work on those two rows only, but no characters would appear.

I think I have beat this dead horse enough. I will visit it again later. Unless there is still a chance that set up could be still an issue then I will change the setup if some one has an idea.

Thanks.

I am still not following what you have actually done other than it sounds like you have 2 LCDs and are using 2 backpacks.

And since there are 2 backpacks involved, it is possible that they are not using the same wiring.

Details really matter when debugging at this level.
We can't see what you have done and what you are seeing.

Are you understanding that while all these backpacks use the same pcf8574 chip on them that different backpacks will wire the connections between the PCF8574 chip and the hd44780 pins differently?
And that you have to tell the library how the PCF8574 chip is wired up to LCD in order for it to work?

If you give the library the incorrect pin mappings, it won't work.

If one backpack is working and the other is not, then I'm assuming that your problem is that two backpacks use different wiring and so the constructor for each backpack will be different.

But then, from your posts, I can't really tell what you have and what you have done.
It would be helpful if you could show us photos of what you have so we can see EXACTLY what you have rather than depend on verbal descriptions.

--- bill

bperrybap:
It would be helpful if you could show us photos of what you have so we can see EXACTLY what you have rather than depend on verbal descriptions.

Note; photos with perfect focus and taken in daylight.

Guys,

I soldered them! Now I could have reversed them if I really was Brain Dead. Ok I probably opened myself up on that one. and I have a 1-4 dupont plug for the back pack. again I could have reversed that as well. but no I did not do that. now I have had three different back packs on the 2004. I plug the dupont plug into the 1602 it works and then the 2004 and it does not. I either have a bad 2004 or my programming for the pins are wrong.

weldsmith:
I soldered them!

Soldered what?
Back in post #11 you said that things were already soldered:

Some day I will un-solder and try the old way.

weldsmith:
now I have had three different back packs on the 2004.

A third backpack? Why do things keep changing?

I plug the dupont plug into the 1602 it works and then the 2004 and it does not. I either have a bad 2004 or my programming for the pins are wrong.

I'm lost I thought you mentioned something about a 1-4 dupont plug but then said you plugged the dupont plug into the 1602 and 2004 which are LCD panels (no backpack).
So now you are testing the LCD panels without the backpacks?
By just plugging in 16 wires into soldered headers on the 16x2 and the 20x4 LCD?

I'm not sure about the others, but I still can't tell what you have and what you are doing.
We can't see what you have and what you have done.
The verbal descriptions are confusing (at least to me).
How about some photos?
I'm about to give up trying to help.

I'll jump back in if some photos show up.

--- bill