Arduino Forum

Forum 2005-2010 (read only) => Software => Bugs & Suggestions => Topic started by: crimony on Apr 23, 2008, 07:08 am

Title: LCD Library
Post by: crimony on Apr 23, 2008, 07:08 am
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: [Select]
//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?
Title: Re: LCD Library
Post by: mem on Apr 23, 2008, 10:06 am
I share your view that it should be changed.

Why not add  [font=Courier]void LCD4Bit::println(char *msg)[/font]  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.
Title: Re: LCD Library
Post by: Oracle on Apr 23, 2008, 02:34 pm
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.
Title: Re: LCD Library
Post by: gradbert on Apr 25, 2008, 06:00 am
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()
Title: Re: LCD Library
Post by: mem on Apr 25, 2008, 06:18 am
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.
Title: Re: LCD Library
Post by: gradbert on Apr 25, 2008, 06:59 pm
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

Title: Re: LCD Library
Post by: mem on Apr 25, 2008, 07:47 pm
I would expect that printing beyond actual  lines would do the same as printing beyond actual columns, nothing would be displayed.
Title: Re: LCD Library
Post by: MysteriousAges on Apr 25, 2008, 08:04 pm
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.
Title: Re: LCD Library
Post by: neillzero on Apr 28, 2008, 01:21 pm
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
Title: Re: LCD Library
Post by: mem on Apr 28, 2008, 01:47 pm
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.
Title: Re: LCD Library
Post by: mellis on Apr 28, 2008, 04:41 pm
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_
Title: Re: LCD Library
Post by: neillzero on Apr 28, 2008, 05:32 pm
mellis: great to hear.
Title: Re: LCD Library
Post by: wayoda on Apr 28, 2008, 06:00 pm
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
Title: Re: LCD Library
Post by: wayoda on Apr 28, 2008, 06:12 pm
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

Title: Re: LCD Library
Post by: gradbert on Apr 28, 2008, 10:32 pm
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.

Title: Re: LCD Library
Post by: mellis on Apr 28, 2008, 11:21 pm
I've been doing multiline support the way that wiring does: not explicitly configuring it that way, but allowing you to move the cursor to any line you want.  I can write to all the lines on the 2 and 4 line displays I have.

gradbert: The constructor for the LiquidCrystal library on Arduino will be basically what you suggest.  The rest of the API will mirror Wiring's, although we could certainly add some functions (either now or later).
Title: Re: LCD Library
Post by: gradbert on Apr 29, 2008, 07:23 am
Ok, I figured code speaks louder than words, so I took the LCD4bit library and combined it with the code from SoftwareSerial.  The constructor it the interface described previously.  It has the most of the same print() and println() functions as SoftwareSerial.  The print(uint8_t) is replaced with rprint(uint8_t).  something with the casting was giving me grief.  All the printing functions have been moved to a class called Printable.  the LCDnew class only has to implement rprint().  I don't have the carrage return/line feed handling implemented in the LCD class yet.

check it out at http://www.gradbert.org/ldcnew.zip

I still need to do some work on this but I figure some early feedback would be good
Title: Re: LCD Library
Post by: mem on Apr 29, 2008, 03:40 pm
hi gradbert, I am looking forward to trying your LCD library but your site is not responding.
Title: Re: LCD Library
Post by: mellis on Apr 29, 2008, 04:45 pm
gradbert: cool.  I actually did something similar (see: http://svn.berlios.de/wsvn/arduino/trunk/hardware/cores/arduino/), but you've got some nice improvements.  I like the name Printable better than Print, which is what I used.  Also, did you get this to work on the Arduino?  I had trouble getting virtual functions to compile, so I hacked together my own version.  
Title: Re: LCD Library
Post by: gradbert on Apr 29, 2008, 05:38 pm
Quote
hi gradbert, I am looking forward to trying your LCD library but your site is not responding.


I should be more careful posting late at night.  The correct url is http://www.gradbert.org/lcdnew.zip
Title: Re: LCD Library
Post by: gradbert on Apr 29, 2008, 06:00 pm
Quote
gradbert: cool.  I actually did something similar (see: http://svn.berlios.de/wsvn/arduino/trunk/hardware/cores/arduino/), but you've got some nice improvements.  I like the name Printable better than Print, which is what I used.  Also, did you get this to work on the Arduino?  I had trouble getting virtual functions to compile, so I hacked together my own version.  



I did get it working.  In the zip file is an example program that will compile, download, and display on an lcd.  The only thing that was really giving me a problem was that the build doesn't seem to be very happy with a library including another library, so in my sketch I have to explicitly include <Printable.h>.

Now because the pin assignments are local to the instance of the object, I should be able to hook up two lcd displays at once.  If I have some time this week, I will make a second lcd cable and try it.
Title: Re: LCD Library
Post by: gradbert on Apr 30, 2008, 06:48 am
Here is a pic of an arduino driving two lcd's at once using the lcd library i have been playing with
(http://www.gradbert.org/twolcd.jpg)

(the small circuit board on the protoboard is a 3 axis accelerometer, for another project)
Title: Re: LCD Library
Post by: gradbert on Apr 30, 2008, 07:33 am
I have the println() methods working now.  The new version is at http://www.gradbert.org/lcdnew.zip
Title: Re: LCD Library
Post by: tigrezno on May 15, 2008, 12:43 pm
will this work with serial-enabled LCDs?
Title: Re: LCD Library
Post by: gradbert on May 16, 2008, 05:15 am
no, this is for paralele interfaced LCD's with the hitachi chipset.  
Title: Re: LCD Library
Post by: brianbr on May 19, 2008, 12:14 am
Quote
will this work with serial-enabled LCDs?



I have a library for an LCD driven by Software Serial. The command codes are for a PH Anderon controller chip, but they would be trivially easy to edit.


http://www.wulfden.org/downloads/code/arduino/SWSerialLCDPHA_Lib.zip

cheers ... BBR
Title: Re: LCD Library
Post by: follower on May 19, 2008, 12:50 pm
Quote
It will support both 4 and 8 bit modes (though is there any reason you'd want to use the 8-bit one?).

Isn't there some non-trivial speed difference between the two methods? (From memory, not personal experience.)

--Phil.
Title: Re: LCD Library
Post by: cmroanirgo on Jun 09, 2008, 11:08 am
Quote

I have a library for an LCD driven by Software Serial. The command codes are for a PH Anderon controller chip, but they would be trivially easy to edit.


http://www.wulfden.org/downloads/code/arduino/SWSerialLCDPHA_Lib.zip

cheers ... BBR


I must thank everyone so far for their efforts for a unified 8 and 4-bit library, but wouldn't it be prudent to also support a serial version of this new library? I was thinking of just an undertaking...but many wonderful people here have already started and I wouldn't dream of encroaching upon their work :)

Title: Re: LCD Library
Post by: mellis on Jun 09, 2008, 04:56 pm
As far as I know, different serial LCDs have different protocols, which makes it hard to write a single library to talk to them.  But if anyone wants to take a shot at creating a nice system for supporting multiple protocols and selecting between them, that would be cool.
Title: Re: LCD Library
Post by: tweeks on Jun 28, 2008, 07:41 am
What's the process for the code getting merged into the other 4/8bit hitachi and/or serial LCD librar(ies)?

Also.. Please provide a clear hookup diagram for your version.. I've seen a half dozen different hookup configs.. none of which are compatible with each other.

Tweeks
Title: Re: LCD Library
Post by: mellis on Jun 28, 2008, 06:12 pm
Good point on the diagram.

The LiquidCrystal library in Arduino 0012 will support both 4 and 8 bit.  For the moment, there's no serial support, since I guess every Serial LCD has a different interface.  The playground is publicly editable, but you should probably coordinate with whoever posted the version you want to modify / improve.
Title: Re: LCD Library
Post by: strohhalm on Jul 17, 2008, 03:33 am
i am working only a short time now with lcd´s. But as a newbie there i have brand new questions i have had.
For example: what happens with signs in column 17 when you  have 16x2 display.
Does the hole stuff scroll to the left one char or will it dissapear or will it be in some ram? Will it go to the next line? could that be possible? Like serial, a behavior like a terminal?
One of many things i wanted to read in the controller manual? but i don´t had time until now.
I think if you want to have a consistency here, the behavior should be like in a terminal. (my thoughts ;-) )
Then the print & println makes sense, because you expect this line oriented behavior. I have similar behavior for example in python or perl with text output not only with serial communication.
it is also possible to clear a terminal and navigate to a position.
a lcd is a kind of a very small terminal, especially with only one line. But with 2 the picture becomes a bit more sharper and with 4 it should be sharp.
cd with more line become affordable so we should think about this and . . .

a n d . . .  what about graphic lcd?

if not now implemented, we should think about to get it maybe in v13. all the features of the text lcd should be consistent on a graphic display too! The only difference should be that you are able to program your graphics also.

Another question i have, what about lcd´s with newer technologies. Like the dog-m series.
If you want to take a look: http://www.lcd-module.de/eng/dog/dog.htm
Here you can see what the future can change in a maximum compatible way on the hardware side.
I am fiddling around to get the 1 line 8 char version to run, in little steps, (looks good at the moment).
The only difference here, before the last two commands of init( clear and cursor mode), some commands have to be written in sequence (3.3V or 5V, contrast, voltage, bias, ..) it´s only five to seven commands.
But thats only with 4bit mode. You have also an additional SPI mode, and the controller manual says there exists also a i2c version! I would really like a i2c interface! Thats so easy to use.
Apropos: SPI is also a library worth, hopefully without headache - which mode(1to4), howto more devices?.
So we have to expect some additional technology there also.
Isn´t the 4bit data protocol called something like 6800 code and the 8bit 8521? . as i have in mind now. So it comes from the old days, when we were happy to have an epson FX80 printer! Isn´t 6800 a 8bit uprocessor a sister series to the 6502 (2MHz, the heart of the 8bit Ataris :) ) the predecessor of the 68000 32/16 (heart of Atari ST).

So in consistency, can the data protocol brought to where it belongs, in some extra or one extra library?
something like: DATA bitshinundher1 = DATA(SPI, MODE, CS, CLK, DO, DI); - atmega manual has also something to say here!

or   DATA bitshinundher2 = DATA(4P , RS, RW, E, D4, .. D7);
or   DATA bitshinundher3 = DATA(SER , BAUD, PAR, ?.);
or   DATA bitshinundher4 = DATA(2W ,  ?.);
or whatever, these data transfer protocols are a bit too complicated to handle, i think.
with a good standard protocol library in the background, other libraries could also really benefit of it,
maybe a gps, LED, Bluetooth or whatever lib which has to communicate to some klingon ic in some klingon protocol.

Code: [Select]
LCD klingonlcd = LCD(x rows ( , y cols (, COLOR)) ); // text lcd only rows, graphic x & y , standard bw or RGB-bit - 256 or 12364 or ?
I think thats it what a lcd defines: rows, columns and colormode

all other is secondary,

Code: [Select]
klingonlcd.data(PROTOCOL (, spec1 (, specx. . . )));
and then if necessary a not standard init:
Code: [Select]
klingonlcd.initlcd(0xXX (, 0xYY(, B0100100 . . . )));  // the additional init sequence

or can we make lcdfactfiles, like the atmega168 file for the compiler, where it can check where the ports are and what features a special avr chip has?
Code: [Select]
# include "4bit.lcdprot"  // if necessary add a lcd specific file:
# include "klingon.lcdspec"   // don´t know if possible.
or:
# include "cc.arduino.dataprot.4bit.lcd"  
# include "cc.arduino.spec.lcd.klingonlcd"  

( ohh, what would i give for to know the C Syntax much more better then yet :( , often i feel so handicaped, have it in mind, but don´t know how to write.. . )


so. it´s too late now. stop thinking and go sleeping
and there´s more than one way to do that.

goodNight.Austin Texas! Or wherever you are!

PS: if someone uses Dog-M displays, they are really nice!, BUT MIND the gap: THERE IS a foly on the back of the display! Especially when you can see a light gray line! But don´t scratch away the milky part of the display. For german buyers: you can get them at http://www.reichelt.de the text version 12? lcd + 4? standard colors led backlight. Thats really affordable for what you get.