I'm planning a project with a 4 line LCD. These are the only ones that I can find locally. I've been looking through the datasheet and it seems hd44780 compatible, but I'm not sure. Can somebody check the datasheet and just verify for me that it will work.
ok, so it works, but only the first line. The other lines won't display anything. And if I use the 4bit2x20 lcd library then it doesn't show anything ??
Make sure you are using a version of the library that has four line support.
The constructor should look something like this:
//constructor. num_lines must be 1 or 2 or 4, currently.
LCD4Bit::LCD4Bit (int num_lines) {
g_num_lines = num_lines;
if (g_num_lines != 1 && g_num_lines != 2 && g_num_lines != 4)
{
g_num_lines = 1;
}
}
And your cursorTo function should look something like this.
void LCD4Bit::cursorTo(int line_num, int x){
//if we are on a 1-line display, set line_num to 1st line, regardless of given
if (g_num_lines==1){
line_num = 1;
}
//offset 40 chars in if second line requested
//
switch (line_num){
case 2:
x+= 0x40 ; break;;
case 3:
x+= 0x14 ; break;; // In fact, line 3 is an extension of the line 1 (beyond the 20 first characters)
case 4:
x+= 0x54 ; break;; // Line 4 is an extension of line 2
}
commandWrite(0x80+x);
}
]
There is four line specific code in a few other places in the library but if yours doesn't have lines like the above then you need to download one that says it supports 4 lines.
Make sure you are using a version of the library that has four line support.
I checked the library and it looks fine. But this is what I Figured out.
When I set it to a 1 line lcd, it works fine for line1. I can also write on line 3 using lcdlocate(1, 0x14), essentially forcing it to start writing at that address. But, as soon as I change the num lines to anything else then I can't do anything, not even write on line 1. The only other place where the numlines have any relevance (except for setting the location) is in the init part
int num_lines_ptn ;
if (g_num_lines != 4) {
num_lines_ptn = g_num_lines - 1 << 3;
} else {
num_lines_ptn = 2 - 1 << 3; // we are controlling the 4 lines display as an 2 lines.
}
int dot_format_ptn = 0x00; //5x7 dots. 0x04 is 5x10
commandWriteNibble(num_lines_ptn | dot_format_ptn);
delayMicroseconds(60);
The datasheet on this lcd doesn't give much else apart from the pinouts. Any help would be greatly appreciated.
Most 4 line displays actually contain two driver chips and the panel manufacturers use subtly different ways of connecting them up. There are some suggestions in the discussion thread linked above that may help you get yours going.
When I set it to a 1 line lcd, it works fine for line1. I can also write on line 3 using lcdlocate(1, 0x14), essentially forcing it to start writing at that address. But, as soon as I change the num lines to anything else then I can't do anything ...
Am I correct in thinking that you can write to line 3 by doing
cursorTo(1, 0x14);
but cursorTo(3, 0); does not work?
and that you tried this with the library linked in post 8 ?
Am I correct in thinking that you can write to line 3 by doing
cursorTo(1, 0x14);
but cursorTo(3, 0); does not work?
and that you tried this with the library linked in post 8 ?
Correct, but cursorTo(3,0) won't work because I specify only 1 line when I init the LCD. If I use any other amount then nothing works. Yes, I tried that library.
Don't know if this helps but I think I found the datasheet for the controller for this lcd:
OK, so I got it to work. I the registers in the datasheet are either wrong or I have the wrong datasheet, but here is what I figured out:
(1) It's really a 2x40 lcd, but the lines are cut in two so you have a 4x20
(2)
According to my datasheet the registers for each line should start at :
Line 1 : 0x0
Line 2 : 0x40
Line 3 : 0x14
Line 4 : 0x54
but the registers actually are :
Line 1 : 0x0
Line 2 : 0x28
Line 3 : 0x14
Line 4 : 0x3C
Weird ??
So I initialized the lcd as a two line lcd and I changed the cursorTo function to the following :
void LCD4Bit::cursorTo(int line_num, int x){
//first, put cursor home
commandWrite(CMD_HOME);
//if we are on a 1-line display, set line_num to 1st line, regardless of given
if (g_num_lines==1){
line_num = 1;
}
//offset 40 chars in if second line requested
if (line_num == 2){
x += 0x28;
}
if (line_num == 3){
x += 0x14;
}
if (line_num == 4){
x += 0x3C;
}
//advance the cursor to the right according to position. (second line starts at position 40).
for (int i=0; i<x; i++) {
commandWrite(0x14);
}
}