Go Down

Topic: LCD 16x4 setCursor is not working right (Read 12326 times) previous topic - next topic

Leonti

Hello!
I've just connected my 16x4 LCD to Arduino board.
I can print to it, but I have problem with 3rd and 4th lines of LCD - the message is printed on those lines starting from 5th character.
Code: [Select]
void setup() {
 // set up the LCD's number of rows and columns:
 lcd.begin(16, 4);
 // Print a message to the LCD.
 lcd.setCursor(0, 3);  
 lcd.print("hello, world!");
}


If I set cursor like this  lcd.setCursor(-4, 3); it's working properly.

Why is it doing this? Is there is a way to solve it?

Leonti


floresta

Leonti:
Quote
Why is it doing this?
This has come up at least once before since the improved LiquidCrystal library was released.  It is because the library treats all 4-line displays the same with respect to the starting address for each line.  The problem is that the 16x4 has different starting addresses for lines 3 and 4 than the 20x4 for which the library is written.

Quote
Is there is a way to solve it?
Your method will work until the library is updated.  You could go into the LiquidCrystal.cpp file and edit the setCursor routine.  

Changing:  int row_offsets[] = { 0x00, 0x40, 0x14, 0x50 }; to: int row_offsets[] = { 0x00, 0x40, 0x10, 0x54 }; would probably do the trick.  Of course the 20x4 displays would now be messed up!

If you want to read about the reason for the curious addressing scheme for these LCD displays then check out http://web.alfredstate.edu/weimandn, use the link to LCD Addressing.

Don

Leonti


wortelsoft

#3
Oct 23, 2009, 08:59 am Last Edit: Oct 23, 2009, 09:00 am by wortelsoft Reason: 1
I corrected this problem last night will see if I can get my source code to the maintainer(s). I've added conditional change to the offset.

floresta

wortelsoft:
Quote
... will see if I can get my source code to the maintainer(s)

Do you (or does anyone else) know the proper way to do this?  On the Arduino home page it says:

Quote
Development: For information on the development of Arduino, see the Arduino project on Google Code. Changes to the software are discussed on the developers mailing list.

I tried communicating to them via the provided link and got a nastygram in response.  It appears that the 'software' mentioned is limited to the IDE which does not include the libraries, even the official ones that come with the IDE.

I have some corrections to the comments and a change in the initialization that I feel should be implemented even though the current code seems to work reliably.

Don

wortelsoft

At the bottom off the reference page it links to the bugs section on the forum.
Just found another bug with the 16x4, scrolling is wrong I think.

I have text on the second row. It wil scoll over second and fourth row.

wortelsoft

The scrol function is doing nothing wrong. I just how it works. So if I want a one line scoll function i have to build it my self.

floresta

If you want some background information on the reasons behind this strange LCD behavior take a look at the LCD Addressing link at http://web.alfredstate.edu/weimandn.

Don

Go Up