Liquid crystal problem

Hello, i have a problem with the liquid crystal library. I hooked up a 2x16 LCD as in the tutorial part of the site.
The problem is: If i use lcd.begin(16,2) then the text on the LCD will be out of contrast. If i don't use the begin function the text gets a good contrast and is readable. What is the problem? I use 0022 IDE.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() {
  // set up the LCD's number of columns and rows: 
  //lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

LE: Tried 20x4 LCD, same thing is happening.

What happens if you add some delay in your setup before printing hello world and in loop?

It's the official code so there should be no delay in it.

Shebu:
It's the official code so there should be no delay in it.

But how sure are you that your displays have passed quality check? I have bought a display for cheap but it is not so up to specs so I had to add some manual delays. That is at least one thing you can try. Don't be so close-minded when it comes to solving a problem. Especially when you ask others without even posting a pic, we're not so all-seeing, just that you know. :astonished:

If i don't use the begin function the text gets a good contrast and is readable. What is the problem?

The problem is most likely with your contrast potentiometer setting. Without the begin function the device is initialized for a 1-line display. With the begin function if the second argument is any number other than 1 the device is initialized for a 2-line display. In addition to enabling the extra line(s) this initialization for a 2-line display also affects the contrast of the display which must then be offset with your external contrast potentiometer. I suggest you follow the tutorial at Arduino Tutorial - connecting a parallel LCD.

Don

...but it is not so up to specs so I had to add some manual delays...

I could see where adding additional delays between the instructions that are sent to the display might be of some help with an out of spec display. Such delays might provide the added time necessary for a slow LCD controller to complete an instruction before receiving the next one. You would have to modify the library to accomplish this. In my own LCD code I routinely increase the delays above the recommended ones. I don't see how adding a delay when using the library would help since these delays would not be in the right place.

Don

floresta:
In addition to enabling the extra line(s) this initialization for a 2-line display also affects the contrast of the display which must then be offset with your external contrast potentiometer.[/color]

Don

Don,

Thanks for the tip. Did you write the library? I don't recall I came across such details as the above. Was the contrast pin grounded before the init occurs?

This is on what i work. I tried the tot on ladyada, still the same. I added the delays, still the same.

In the first 2 pictures you can see how the display looks with the begin function enabled. In the last image the function is disabled.

In the last image the function is disabled.

And the second line does not show up since the library is using its default setting of 1-line. In my opinion this is a colossal mistake by the library author since virtually all displays, including many of those that have only one line of characters, must be initialized as 2-line displays.

Go back to the version that uses the begin function and adjust your potentiometer. It looks like a 10-turn device so you may have to crank it a bit.

Don

Did you write the library?

No. I am not too fluent in 'C' and I have no experience in writing libraries. Shortly before Limor (Lady Ada) rewrote the old library I did come up with and post a cludge that at least made the old one work.

I don't recall I came across such details as the above.

This initially came from doing some experimentation. The explanation is buried in the Hitachi datasheet and is a result of what they call the 'duty factor'. It's 1/8 for a 1-line implementation and 1/16 for a 2-line implementation. My interpretation is that in the 2-line mode each pixel is energized 1/16 of the time as opposed to 1/8 of the time in the 1-line mode. This means that the 2-line display is inherently dimmer and thus requires a different contrast voltage.

Was the contrast pin grounded before the init occurs?

I don't understand this question!

Don

floresta:

In the last image the function is disabled.

And the second line does not show up since the library is using its default setting of 1-line. In my opinion this is a colossal mistake by the library author since virtually all displays, including many of those that have only one line of characters, must be initialized as 2-line displays.

Go back to the version that uses the begin function and adjust your potentiometer. It looks like a 10-turn device so you may have to crank it a bit.

Don

The pot is cranked to its max(gnd). When the contrast is ok (you can see something) i do not change anything at the hardware, just uploading another sketch.

I think my only solution is another version of the library. I should take the one from 0018(have it on linux) and try that.

The pot is cranked to its max(gnd).

Does the display change when you turn the potentiometer the other way - so that the wiper (and pin 3) is not at GND potential. If the display does not change then the potentiometer may have been damaged by turning it after it reached the end of it's normal range.

I think my only solution is another version of the library.

To my knowledge all of the libraries since v017 are the same and all of the libraries prior to that version are incorrect.

Don

floresta:

The pot is cranked to its max(gnd).

Does the display change when you turn the potentiometer the other way - so that the wiper (and pin 3) is not at GND potential. If the display does not change then the potentiometer may have been damaged by turning it after it reached the end of it's normal range.

Yes, if i turn it the other way the text disappears.

I think my only solution is another version of the library.

To my knowledge all of the libraries since v017 are the same and all of the libraries prior to that version are incorrect.

Don

That's bad for me. Now i don't have any solution.

Shebu:
Yes, if i turn it the other way the text disappears.

You're seriously hanging on to "not including the include lcd.begin(16,2); in setup()". Just let go of the pretty texts as they're not what you want anyway. What floresta meant was to include lcd.begin(16,2); in setup() and THEN turn the potentiometer both ways to see if the text shows up.

liudr:

Shebu:
Yes, if i turn it the other way the text disappears.

You're seriously hanging on to "not including the include lcd.begin(16,2); in setup()". Just let go of the pretty texts as they're not what you want anyway. What floresta meant was to include lcd.begin(16,2); in setup() and THEN turn the potentiometer both ways to see if the text shows up.

Done that. it does exactly what it is supposed to do. It dimes the contrast until it is unreadable. The text disappears.

Ok, sorry I thought you didn't. So here is what you found, with lcd.begin(16,2), there is no text however you turn the potentiometer? Right?
Do you have a multimeter? Measure the voltage on the middle pin of the potentiometer AS YOU TURN. Any change in voltage?

All is normal. At one end 0,012V at the other 5V and in between i get 1.2 or 2.3 or 3.4. So it's ok.

All is normal. At one end 0,012V at the other 5V and in between i get 1.2 or 2.3 or 3.4. So it's ok.

Is this measured at the potentiometer or at the display (you could have a bad connection). You typically want less than 1 volt, frequently only 0.3v. Perhaps some nice clear, in focus, photographs would help us spot something we haven't thought about. They must be shot straight down so we can see the display and both ends of all the interconnecting wires.

Don

floresta:

All is normal. At one end 0,012V at the other 5V and in between i get 1.2 or 2.3 or 3.4. So it's ok.

Is this measured at the potentiometer or at the display (you could have a bad connection). You typically want less than 1 volt, frequently only 0.3v. Perhaps some nice clear, in focus, photographs would help us spot something we haven't thought about. They must be shot straight down so we can see the display and both ends of all the interconnecting wires.

Don

Measured at the display.

LE: Added the pictures. The problem is with the library. I still don't understand how the 4 data pins can influence the contrast. I could eliminate the trimmer by putting the contrast directly to gnd.

The problem is with the library.

It's more likely that the problem is with the LCD module.

Don