Pages: [1]   Go Down
Author Topic: LCD 16x4 setCursor is not working right  (Read 11187 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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

Logged

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

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
Logged

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

Thank you!
It explains that.

Leonti
Logged

Netherlands
Offline Offline
Sr. Member
****
Karma: 1
Posts: 290
(:-)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: October 23, 2009, 02:00:36 am by wortelsoft » Logged

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

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
Logged

Netherlands
Offline Offline
Sr. Member
****
Karma: 1
Posts: 290
(:-)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Netherlands
Offline Offline
Sr. Member
****
Karma: 1
Posts: 290
(:-)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

Pages: [1]   Go Up
Jump to: