Go Down

Topic: New character in 4x20 LCD (Read 323 times) previous topic - next topic

Dr_Quark

Has anyone successfully added new characters to their display? I'd like an "up arrow" and a "down arrow."
Dr.Quark

Budvar10

#1
Dec 15, 2017, 08:04 am Last Edit: Dec 15, 2017, 08:04 am by Budvar10
Usually, these displays support custom defined characters on positions 0-7. It is just bitmap. I'm using LCD library from F. Malpartida for the years. This lib contains ::createChar() function. It's easy with this.
What is the problem specifically?
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

krupski

#2
Dec 15, 2017, 10:27 am Last Edit: Dec 15, 2017, 10:29 am by krupski
Has anyone successfully added new characters to their display? I'd like an "up arrow" and a "down arrow."
If your display is a standard "HD44780 compatible" type that works with LiquidCrystal.h, then yes you can create your own custom characters.

Here's a piece of code from one of my sketches where I add the "degrees" symbol to display temperature (assuming you have already initialized the LCD and call it's object "LCD":

Code: [Select]
   const uint8_t deg_sign[] = {
        0b00110,
        0b01001,
        0b01001,
        0b00110,
        0b00000,
        0b00000,
        0b00000,
        0b00000,
    };

    LCD.createChar (1, deg_sign);


The createChar function takes two parameters: The first is which character to use to print the degrees sign (0x01 in my example). The second one is the array of bits to make up the character.

To print using that character, I do this:


Code: [Select]
LCD.print ("Temperature is ");
LCD.print (temperature);
LCD.print ((char) 0x01);
LCD.print ("C");

// resulting in "Temperature is nnnĀ°C"


The LCD digits are a 5 by 8 pixel array, with the last (bottom) defining an underline.  A zero is "pixel off" and a one is "pixel on".

The array for the number three would look like this:

# # # # #   ->   1 1 1 1 1   ->   0b11111,
. . . # .   ->   0 0 0 1 0   ->   0b00010,
. . # . .   ->   0 0 1 0 0   ->   0b00100,
. . . # .   ->   0 0 0 1 0   ->   0b00010,
. . . . #   ->   0 0 0 0 1   ->   0b00001,
# . . . #   ->   1 0 0 0 1   ->   0b10001,
. # # # .   ->   0 1 1 1 0   ->   0b01110,
. . . . .
  ->   0 0 0 0 0   ->   0b00000,

In fact, I create my characters like that (using # for 1 and . for 0, with double spacing to visualize it better, then edit the "#" to 1 and "." to zero and remove the spaces).

Lastly, if ANY bit of the bottom row is set to 1, then the entire bottom line is active, creating an underline.

Hope this helps.

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Budvar10

@Krupski, brilliant tutorial for newbies. Should be permanently available somehow. +1
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

Dr_Quark

#4
Dec 15, 2017, 11:56 am Last Edit: Dec 15, 2017, 04:45 pm by Dr_Quark
Thanks. I had read the HD44780 spec sheet, but I just never got my code to work. That was a year ago. Now that I'm revamping my device I thought I'd take another shot at it.

I'm assuming that the createChar() function is in the LCD library.
Dr.Quark

Dr_Quark

#5
Dec 15, 2017, 04:57 pm Last Edit: Dec 15, 2017, 04:59 pm by Dr_Quark
"...assuming you have already initialized the LCD and call it's object "LCD" "

the idea of class and object is not familiar to me. I'll have to delve into this.

(BTW, thanks to whoever moved this to the correct topic area)
Dr.Quark

krupski

#6
Dec 15, 2017, 09:52 pm Last Edit: Dec 15, 2017, 10:01 pm by krupski
Thanks. I had read the HD44780 spec sheet, but I just never got my code to work. That was a year ago. Now that I'm revamping my device I thought I'd take another shot at it.

I'm assuming that the createChar() function is in the LCD library. <---YES it is.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

krupski

"...assuming you have already initialized the LCD and call it's object "LCD" "

the idea of class and object is not familiar to me. I'll have to delve into this.

(BTW, thanks to whoever moved this to the correct topic area)

To use the LCD, you connect it to the Arduino (keep track of which ARDUINO pins are connect to which LCD pins such as Enable, D0, D1, D2, D3, etc....)

Example (of course, you need to change the #defines for the LCD pin numbers to match YOUR wiring setup):

Code: [Select]
// LCD parallel pin connections
#define _RW   38
#define _EN   39
#define _V0   40
#define _RS   41
#define _D7   42
#define _D6   43
#define _D5   44
#define _D4   45
#define _D3   46
#define _D2   47
#define _D1   48
#define _D0   49

#include <LiquidCrystal.h> // include the LCD library

static LiquidCrystal LCD (_RS, _RW, _EN, _D0, _D1, _D2, _D3); // create an LCD "object" (4 bit mode)

void setup (void)
{
    LCD.begin (20, 4); // initialize a 20 character, 4 row LCD
    LCD.print ("Yippee it works!");
}

void loop (void)
{
    // nothing
}


This should be all you have to do......


Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Go Up