Pages: [1]   Go Down
Author Topic: Bug in standard liquidcrystal?  (Read 700 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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?
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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

« Last Edit: June 06, 2012, 08:42:26 am by floresta » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


at least it is solved in 0.22 and 1.0
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Code:
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
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


What I meaned to say is that the

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

bug is solved

it is now.:

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



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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





Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2641
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 46
Posts: 2865
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2641
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

https://github.com/arduino/Arduino  smiley-wink
Logged

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

True :-) But that's not where I actually get the downloaded versions.
Quote
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:

Code:
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.
« Last Edit: June 10, 2012, 05:47:16 pm by jwatte » Logged

Pages: [1]   Go Up
Jump to: