Bug in standard liquidcrystal?

Hi,

I'm connecting a 20x4 display to my non-arduino hardware, but I'm using the standard Arduino Liquidcrystal library.

I forgot to change the "lcd.begin (16,2)" into declaring that I had 4 lines.

The result is that I can move to lines 0, 1, and 2 just fine, but when I try to go to the last line, I end up on the second line. This is due to:

void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
  int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
  if ( row > _numlines ) {
    row = _numlines-1;    // we count rows starting w/0
  }
  
  command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}

I've set "numlines" to "2" as everybody with a 16x2 does. Now when I go to "row 2" (the third one, which is not present on the 16x2 displays), row is NOT > numlines, so the "if" doesn't trigger. When I try to go to line 3, it "limits my movement" back to line 1, the last one if I had a 16x2.

Am I the first to find this bug? It's been in there for ages....

In researching this I found several "improved" liquidcrystal libraries. Why hasn't one of those been adopted?

Am I the first to find this bug? It's been in there for ages....

If you look through my previous posts you will see that I have been mentioning this for ages as well.

The lcd.begin() function gives the LiquidCrystal library the information it needs to properly initialize the display and to permit the lcd.setcursor() function to work properly. Unfortunately the library itself does not follow up on this capability. It does not use the first parameter at all and it only checks to see if the second one is 1 or greater than 1.

The library does not compensate for the fact that the 16x4 and the 20x4 have different starting addresses for the third and fourth rows of characters. Therefore the characters on the third and fourth rows are, and have always been, positioned incorrectly.

Why hasn't one of those been adopted?

Possibly because of the phenomena known as NIH (Not Invented Here). The current LiquidCrystal library, which is a vast improvement over the ones used before v0017, was indeed written by an outsider so the feat is not impossible - only nearly impossible.

Don

at least it is solved in 0.22 and 1.0

at least it is solved in 0.22 and 1.0

I'm not particularly fluent in 'C' but I don't see where this has been solved. Could you point out where any row offsets other than these are used?

 int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };

Perhaps they have approached this a different way but I would have used the 'col' parameter to select the appropriate row offsets.

Don

What I meaned to say is that the

if ( row > _numlines ) {
    row = _numlines-1;    // we count rows starting w/0

bug is solved

it is now.:

if ( row >= _numlines ) {
    row = _numlines-1;    // we count rows starting w/0

I confess that I didn't read his post carefully enough and I was in fact commenting on a different cursor positioning bug. I personally don't recall helping anyone on his particular cursor positioning problem before. Obviously he is not the first one to discover the bug since it has already been fixed. I hope they get around to fixing the offset problem for the 16x4 displays as well.

Don

floresta:
I hope they get around to fixing the offset problem for the 16x4 displays as well.

It's fixed in fm's LiquidCrystal replacement library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/overview

--- bill

It's fixed in fm's LiquidCrystal replacement library:

But as the OP stated "Why hasn't one of those been adopted?"
My theory is NIH.

Don

I've noticed that as well in other area's, NewSoftwareSerial?

Doc

Offtopic sandbox:
I think the Arduino folks, while okay-ish at open source, aren't entirely in the swing of it.
I think the best option would be to put all of the Arduino project on github, as the official repository and download site, and include setup/build instructions for making your own changes.
Then, anyone could fork it, make changes, and send pull requests for improvements. That just seems to work a lot smoother with github than any other open source project host I've found (sourceforge, bazaar, codeproject, tigris, etc)
GitHib for the win!

jwatte:
Offtopic sandbox:
I think the best option would be to put all of the Arduino project on github, as the official repository and download site, and include setup/build instructions for making your own changes.

GitHub - arduino/Arduino: Arduino IDE 1.x :wink:

True :slight_smile: But that's not where I actually get the downloaded versions.

as the official repository and download site, and include setup/build instructions for making your own changes

If the download/install instructions included the link-up with the source, it would make it easier to apply patches.

However, looking at the other LCD libraries, most of them add a bunch of code size for a feature set that will never be used all at once. A better option might be to write a LiquidCrystal library that uses a template to define the specific LCD class (pin numbers, data mode, parameterize on an I/O handler, etc.) Then, the code would actually be smaller, and it would be more flexible to boot.

You'd do something like:

LiquidCrystal<Digital4PinLCDInterface<EPin, RSPin, D7Pin, D6Pin, D5Pin, D4Pin> > myLcd;

void setup() {
  myLcd.init();
}

It is slightly more magic for a new programmer to understand, but it's also a lot more efficient, and flexible.