Pages: [1]   Go Down
Author Topic: Suggestion for LiquidCrystal library  (Read 953 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

when I connected a 16x4 LCD display, I noticed that the position of the cursor with setCursor is not correct on line 2 and 3. When I call setCursor(0, 2), the position is at column 4, not 0.

I found out how this problem can be fixed easily. The lcd.begin function has a parameter for the cols, but it is never used. Although this information is necessary for a correct addressing of the screen. I changed the files as follows and it worked fine with my display. It should also work with a 20-column display, because it does the same as the previous version.

In LiquidCrystal.h, add a private variable _numcols (last lines in the file):
Code:
  uint8_t _numlines,_numcols,_currline;

In LiquidCrystal.cpp, I made the following changes:
Code:
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
  if (lines > 1) {
    _displayfunction |= LCD_2LINE;
  }
  _numlines = lines;
  _numcols = cols; // this is new

Last thing: I changed setCursor:
Code:
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
  int row_offsets[] = { 0x00, 0x40 };
  if ( row >= _numlines ) {
    row = _numlines-1;    // we count rows starting w/0
  }
  if ( col >= _numcols ) {
    row = _numcols-1;    // we count cols starting w/0
  }
 
  command(LCD_SETDDRAMADDR | (col + row_offsets[row % 2]+_numcols * (row / 2)));
}

Explanation: the offset for line 0 and 1 is always (?) 0x40, and the offset for line 2 and 3 seems as if it depends to the columns. Line 2 is handled as an extension to line 0, and line 3 as an extension to line 1. You notice that when you scroll the content of the display; the characters of line 0 and 1 move to line 2 and 3. Line 0 and 1 always have an offset of 0x00 and 0x40, and line 2 and 3 have an offset of 0x00+_numcols and 0x40+_numcols.

I would suggest to change the official code, so it will work without changing the library for 2x16, 4x16 (tested by me), and all other previous displays with 20 colums. All you have to do is to pass the correct number of colums to lcd.begin, e.g. lcd.begin(16, 2) in my case.

Best regards, Kosmas
Logged

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

Hello,

when I connected a 16x4 LCD display, I noticed that the position of the cursor with setCursor is not correct on line 2 and 3. When I call setCursor(0, 2), the position is at column 4, not 0.

. . .

I would suggest to change the official code, so it will work without changing the library for 2x16, 4x16 (tested by me), and all other previous displays with 20 colums. All you have to do is to pass the correct number of colums to lcd.begin, e.g. lcd.begin(16, 2) in my case.

Best regards, Kosmas

Don't hold your breath waiting for this to be fixed.  Check out the date on this thread: --> http://forum.arduino.cc/index.php?topic=14604.0

For an explanation of the reasons for the problem follow the LCD Addressing link at http://web.alfredstate.edu/weimandn.  The 16x4 information is all the way at the end.


Don
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't found other postings to this problem, sorry. And I don't understand your posting. I just made a suggestion to improve a library, and it is fully compatible with the yet existing one. I will use it in future projects, because it is better than the original one:

  • It does not work only for 20 column displays, but also for a lot of 16 columns displays.
  • The old library has variables and parameters that are never been used, as if the original programmer left a way for future expansions.
  • My understanding of a library is not to modify the source to make it work for different hardware. When I have projects for 16 and 20 column displays simultaneously, I don't want to use 2 different libraries. That makes no sense to me.

Best regards, Kosmas
Logged

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

Quote
And I don't understand your posting.
"Don't hold your breath waiting for this to be fixed" is an expression that means that what you are expecting is not likely to happen any time soon.

The existing LiquidCrystal library is far from perfect but it is a lot better than the one it replaced several years ago.  When the new version was introduced I pointed out some of its remaining problems to both the author (Lady Ada of Adafruit) and to the Arduino people by means of the earlier forum.  As you can see nothing has been corrected.

I hope that your efforts to have the library improved are successful but I don't think that will happen anytime soon.  You might want to look into this replacement library --> https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home.


Don
Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The existing LiquidCrystal library is far from perfect but it is a lot better than the one it replaced several years ago.  When the new version was introduced I pointed out some of its remaining problems to both the author (Lady Ada of Adafruit) and to the Arduino people by means of the earlier forum.  As you can see nothing has been corrected.
I think this shows one of the interesting problems with open-source software for the Arduino. It seems to be no problems at all raising money to fund yet-another-arduino-clone-board on Kickstarter but software - no way. Nobody seems interested in financing for instance a new LCD library. To do that you have to find a hardware tweak and sell an add-on. As Adafruit has gone commercial they really can't put X1000 dollar behind doing an update of the library. And companies of that scale can not rely on hobby efforts or allowing anybody to update. That could generate too much bad-will and too many non-billable service request hours.

Most of the Arduino libraries are developed by non-professionals that simply want to share. This is great! But these libraries do not mature and become true open-source class as for instance gcc, Eclipse, etc. There is a lot of infra-structure missing. It would be nice to see the Arduino team driving the next step in the software development - true component oriented software for the Arduino, e.g. a foundation for device drivers and hardware integration. Right now it is really difficult to use the hardware resource available on an Arduino Mega or Due without a better programming paradigm and component interfaces.

The Arduino hardware (or any other hardware) is nothing without software and an effective software development environment/software components. It seems like earnings on Arduino hardware is used to develop new hardware but very seldom used on developing new software components.

Cheers!
« Last Edit: July 09, 2013, 04:17:40 pm by kowalski » Logged

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1731
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The existing LiquidCrystal library is far from perfect but it is a lot better than the one it replaced several years ago.  When the new version was introduced I pointed out some of its remaining problems to both the author (Lady Ada of Adafruit) and to the Arduino people by means of the earlier forum.  As you can see nothing has been corrected.
I think this shows one of the interesting problems with open-source software for the Arduino. It seems to be no problems at all raising money to fund yet-another-arduino-clone-board on Kickstarter but software - no way. No body seems interested in financing for instance a new LCD library. To do that you have to find a hardware tweak and sell an add-on. As Adafruit has gone commercial they really can't put X1000 dollar behind doing an update of the library. And companies of that scale can not rely on hobby efforts or allowing anybody to update. That could generate too much bad-will and too many non-billable service request hours.

Most of the Arduino libraries are developed by non-professionals that simply want to share. This is great! But these libraries do not mature and become true open-source class as for instance gcc, Eclipse, etc. There is a lot of infra-structure missing. It would be nice to see the Arduino team driving the next step in the software development - true component oriented software for the Arduino, e.g. a foundation for device drivers and hardware integration. Right now it is really difficult to use the hardware resource available on an Arduino Mega or Due without a better programming paradigm and component interfaces.

The Arduino hardware (or any other hardware) is nothing without software and an effective software development environment/software components. It seems like earnings on Arduino hardware is used to develop new hardware but very seldom used on developing new software components.

Cheers!

I agree. It seems like software should be free and needs no sponsoring like hardware.
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Sweden
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Jantje.

I don't think people understand the amount of work that it takes to build and support a serious library or a development environment. If they did they would not expect it for free. 

For instance, how many hours have you spent on your Eclipse plug-in for Arduino. I would guess in the range of hundreds. That is not something you put together over a weekend. Great job BW!!!

Here are some numbers that might be of interest. Developing software within a 10.000+ organization/company takes on average 1 hour per line (approx. 10 lines per developer per day). That is total cost, testing, documentation, project management, etc. There is tons of statistics that points to this. Actually the number drops for embedded and time critical software (See http://en.wikipedia.org/wiki/COCOMO, more links below).

This implies that 1000 lines of software costs in the range of 100.000 dollars/euro to develop and maintain. Making a copy/downloading costs more or less zero ;-)

Now a small startup software company (<10 designers) can produce as much as X10 per hour. But after a few years/projects when they have to maintain legacy, have to hire, etc, productivity drops. The numbers are more or less constant for different programming languages, though components and abstraction helps get the most out of the 10 lines per day per designer.

Please note that device driver and real-time software are the most expensive to develop.

My guess is that there are many companies (and people) out there that would be willing to sponsor specific projects. The problem is handling the "projects" and knowing that what they are sponsoring. Kickstarter is great but it is difficult to apply to software projects as it is difficult to display the intended "product". Hardware is so much easier. One way forward might be to make at least some library maintenance sponsored through for instance licensing of the Arduino software, e.g., "a dollar" per board could be put on software development.

Cheers!

More links:
1. http://stackoverflow.com/questions/966800/mythical-man-month-10-lines-per-developer-day-how-close-on-large-projects
2. http://csse.usc.edu/csse/TECHRPTS/1987/usccse87-502/usccse87-502.pdf
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1731
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think people understand the amount of work that it takes to build and support a serious library or a development environment. If they did they would not expect it for free. 

I agree with your points. However I'm not so sure about the second phrase above. As soon as there is no "delivery cost" it is hard to convince people to separate from money.
Think about how people "feel" about downloading music/movies.

Best regards
Jantje

PS thanks for the compliment.
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: [1]   Go Up
Jump to: