Pages: [1] 2 3   Go Down
Author Topic: LCD Library  (Read 3326 times)
0 Members and 1 Guest are viewing this topic.
Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 100
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like the original LCD library author misread the Serial Library's "println()" (print line) method as "printIn" (print in), and duplicated it (erroneously) in the LCD lib for consistency. The method name is repeated in the LCD4Bit library too, with the following acknowleged by the author (neillzero) in LCD4Bit.cpp:

Code:
//print the given string to the LCD at the current cursor position.  overwrites, doesn't insert.
//While I don't understand why this was named printIn (PRINT IN?) in the original LiquidCrystal library,
//I've preserved it here to maintain the interchangeability of the two libraries.
void LCD4Bit::printIn(char msg[]) {

IMHO it should be updated, as it is neither intuitive nor consistent in its current state.

Is there too much momentum to change it now?
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I share your view that it should be changed.

Why not add  void LCD4Bit::println(char *msg)  as a new method but keep the old one so it will still work with legacy sketches. The example sketches should be changed to use the new method and this would produce errors if used with old libraries but that is a worthwhile price to pay for a more consistent and intuitive interface for new people to the LCD libraries.

If the old method was still supported and the change was clearly documented in the code and wiki then I don't think it would be a great inconvenience to existing users.
« Last Edit: April 23, 2008, 03:06:56 am by mem » Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 854
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If the old method was still supported and the change was clearly documented in the code and wiki then I don't think it would be a great inconvenience to existing users.

Is there a way to delcare library functions as depricated?  So for now printIn will raise a comple-time warning to change your code.  Then 1-2 years from now, take it out completely and let is raise an error.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I agree too that it should be changed, but not to println().  the Serial.println() function sends a line break after the text, so that the next thing sent will show up on the next line.  This is not the way the LCD.printIn() function works.  It leaves the cursor on the same line.  It works the same way as Serial.print().  So lets change it instead to LCD.print()
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi gradbert, I was thinking that both could be supported.

print would display text from the current cursor and leave the cursor one character beyond the end of that text, as per yr suggestion.

println would display text from the current cursor and leave the cursor at the start of the next line.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what would happen then if I have a 2 line lcd and i did
LCD.println("A");
LCD.println("B");
LCD.println("C");

would the last line roll off and lcd  showing

A
B

or would it scroll up showing

B
C

or would it wrap around to the top showing

C
B

Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would expect that printing beyond actual  lines would do the same as printing beyond actual columns, nothing would be displayed.
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 64
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what would happen then if I have a 2 line lcd and i did
LCD.println("A");
LCD.println("B");
LCD.println("C");

would the last line roll off and lcd  showing

A
B

or would it scroll up showing

B
C

or would it wrap around to the top showing

C
B


In this case, I think the C would get lost, as the chips in a 16*2 LCD don't have memory for more than 2 lines and 0x27 characters per line. If the characters are printed off the screen, they do not get printed, but instead remain in the driver's DRAM. If the LCD received commands to scroll the text, then these hidden characters would start appearing on the screen.
Ultimately, it would depend on how the function was implemented.
Logged

London
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I wrote the LCD4Bit library (it's really just a conversion of the existing 8-bit one).  
I haven't done any electronics work in the last year, sadly, and don't see myself having time to maintain the library in the near future.
As documented on the wiki, the source is in google code.  I'd be happy to make someone else an admin on that project so that they can maintain it and make future releases.

My main concerns would be:
 * backward compatibility (if a newbie has found or been given an old sketch, they should be able to download the library, wire up their arduino and have it just work) and
 * that the default download of the library be of a stable version.  There's no reason not to also release a beta version of the library and ask for testers.

function naming:

As in the code comment crimony pasted, I intentionally kept the mistake in the function name so that existing programs written against the 8-bit library could be made to work with the 4-bit library with minimal effort.

I'd be in favour of (as mem suggests) introducing a correctly named version of the function, and keeping the old named one too (and documenting it as legacy, and having it cause a deprecation warning, if that's possible).  This is my top concern - that we don't break existing sketches.  Arduino beginners have enough problems.  I have no idea of the number of people using the library.

With regard to choosing a good name, LCD.println() is indeed misleading as gradbert says, as it does not move the cursor to a new line afterward.  LCD.print() is already being used to allow printing of an individual character (but could be renamed to LCD.printChar()).  You could have LCD.printString() but I doubt that's consistent with anything else.  You might look to other arduino or processing libraries for a model.

You guys decide how to go forward, and I'll do my best to assist promptly.
neill
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi neill, thanks for responding and thanks for doing the original 4bit library.

Why not declare the new function as follows:
    void print(const char[]);
This should  overload the existing print statement so the correct one will be called for the argument type passed.  This is similar to the way HardwareSerial works, so is consistant with other Arduino libraries.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm planning to include a LiquidCrystal library in Arduino 0012.  It will support both 4 and 8 bit modes (though is there any reason you'd want to use the 8-bit one?).  The API mirrors the Wiring one (http://wiring.org.co/learning/libraries/LiquidCrystal/index.html) - using the same print() and println() functions as the Serial class.  The code is at: http://svn.berlios.de/wsvn/arduino/trunk/hardware/libraries/LiquidCrystal/#_trunk_hardware_libraries_LiquidCrystal_
Logged

London
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

mellis: great to hear.
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
Quote
I'm planning to include a LiquidCrystal library in Arduino 0012. The API mirrors the Wiring one
I would suggest to add another command that allows switching the cursor to
Off - 0x0C
On - 0x0E
Blinking - 0x0F

Is it useful to be able to switch  the display off completely? (0x08)
Then it could be wrapped into a single function:
displayMode(boolean displayOnOrOff, boolean cursorOnOrOff, boolean cursorBlinkOrStatic);

That would make the Lib complete...
Eberhard
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Me again,
I looked at the code and it supports only 1-line displays?
Most displays are 2 and 4 lines I think. There should be a way initialize the display for that.

Eberhard

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm planning to include a LiquidCrystal library in Arduino 0012.  It will support both 4 and 8 bit modes (though is there any reason you'd want to use the 8-bit one?).  The API mirrors the Wiring one (http://wiring.org.co/learning/libraries/LiquidCrystal/index.html) - using the same print() and println() functions as the Serial class.  The code is at: http://svn.berlios.de/wsvn/arduino/trunk/hardware/libraries/LiquidCrystal/#_trunk_hardware_libraries_LiquidCrystal_


The interface for the wiring lcd library is not as friendly as I would hope for the arduino.  The init routine doesn't allow for fine enough control of the location of the data pins, and it does not have any way to set the number of lines on the display.    Also it doesn't have any way to send arbitrary control codes (or any high level interface to the functions on the LCD)  

I would think that the interface could look somewhat like this:

class LCD {
  LCD(int numLines, int ePin, int rwPin, int rsPin, int d4Pin, int d5Pin, int d6Pin, int d7Pin);
  LCD(int numLines, int ePin, int rwPin, int rsPin, int d0Pin, int d1Pin, int d2Pin, int d3Pin, int d4Pin, int d5Pin, int d6Pin, int d7Pin);
  init();
  clear();
  enable();
  disable()
  cursorMode(int mode);
  cursorTo(int row, int column);
  commandWrite(int value);

  // print() and println() functions as in serial

}

notice that which constructor you use will set either 4bit or 8bit mode

Another thing that we could do would be to make Serial, SoftwareSerial and LCD all inherit from a common base class.  That way all the number printing routines and such would only have to be implemented once.  This might cost space if only one of the 3 was used, but we might wave space when using 2 or more.

Logged

Pages: [1] 2 3   Go Up
Jump to: