Como criar caracteres personalizados no LCD usando Arduino- (Parte 5/49)

How to create custom characters on LCD using Arduino - (Part 5/49)

The LCD module is the most common output unit on a microcontroller board. It is very effective as it can display messages, values, clock, etc. Special types of LCD drivers are used to drive the LCD. Two or more driver ICs of this type, together with the LCD screen, form LCD modules found in embedded systems. The characters displayed on the LCD modules are actually stored in the internal memory locations of these controllers. They are stored in a way that exactly resembles the ASCII table. Whenever microcontrollers send an ASCII value, LCD controllers display the ASCII character that has been stored corresponding to that value.

LCD modules can display not only ASCII characters but also custom characters. The user can store the pixel matrix corresponding to the custom character on an LCD module. The stored custom character can be displayed by sending the corresponding value to the LCD module. Arduino is an easy prototyping platform in which the hardware is very simple to use and connected to any other circuit. The programming environment is also very easy to get started and has many built-in functions for every simple and complex task. The IDE also has functions for interfacing with LCD and among them there are functions that help in creating customized characters as well. This project demonstrates how it is possible to create custom characters on an LCD and display them using Arduino .

The LCD module has two or more display driver ICs that store the character pattern to be displayed. Whenever an ASCII value is sent to the LCD module, the controller loads the corresponding character array and displays it on the LCD screen. To display each character, the LCD screen uses an 8*5 pixel matrix on the screen. In the internal memory, all pixels to be activated for a given character are stored as 1 and the rest are kept as 0. An example of a character stored in the internal EPROM memory of the HD44780 common LCD controller is shown in the following image;

Padrão de caracteres armazenado na memória EPROM do controlador LCD HD44780

Fig. 2: Character pattern stored in the EPROM memory of the HD44780 LCD controller

The image shown above is the character pattern stored in the LCD controller's internal memory. The ASCII value for the letter 'b' in binary is 0b01100010 and therefore the pattern is stored in the memory location with the same address. Therefore, when the microcontroller sends the ASCII value of character 'b', the LCD controller loads the character pattern from the same location with the address equal to that ASCII value. The memory where standard characters are stored is called character generator ROM (CGROM). The user cannot write to these locations as it is read-only memory (ROM). The LCD controller has another memory block which is a read-write memory with 64 bytes (8*8) of storage per location where the user can store their custom characters. The user can write 64 custom characters into this memory, known as Character Generator RAM (CGRAM).

In this project, the Arduino pro-mini board is used, which is then programmed with the help of Arduino IDE version 1.0.3 on the Windows operating system. The image of the Arduino pro-mini board and the Arduino IDE is shown below;

Placa Arduino Pro-Mini típica

Fig. 3: Typical Arduino Pro-Mini board

 Janela do software Arduino IDE

Fig. 4: Arduino IDE software window

Another hardware that can perform USB to TTL conversion is used to load the program onto the Arduino board.

Placa conversora USB externa para TTL para programação de Arduino e comunicação serial

5: External USB to TTL Converter Board for Arduino Programming and Serial Communication

It is assumed that the reader has gone through the project how to get started with Arduino and done all the things discussed in it. You need to find out the custom character that needs to be displayed on the LCD screen. The custom characters displayed in this project are shown in the following image, and the following section explains how to find out the character pattern required for each custom character.

Personagens personalizados criados no projeto no LCD usando a configuração do circuito Arduino na placa de ensaio

Fig. 6: Custom characters created in project on LCD using Arduino circuit setup on breadboard

LCD uses a block of 8*8 pixels to display each character and hence you have to take an 8*5 matrix and draw the required custom character and find out the required bit pattern. One can work with the help of pixel matrix and binary matrix as shown in the following image.

Pixel 8*5 e disposição binária para meio ciclo positivo para caráter personalizado

Fig. 7: 8*5 Pixel and Binary Matrix for Positive Half Cycle for Custom Characters

There are eight rows R0 to R7 and eight columns C0 to C7. The values ​​in all rows and columns are now zero as all pixels are turned off. All the pixels that need to be activated should be given the value 1 and the rest should be kept as 0. Now read the binary pattern and write the same in CGRAM to generate the custom character. It is advisable to store the character pattern in a character array so that it is easy to use with C code. The pixel array and binary array of the first custom character displayed in the project are shown in the following image;

 8*5 pixels e matriz binária para o primeiro caractere personalizado

Fig. 8: 8*5 pixels and binary matrix for the first custom character

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b00000,

0b00000,

0b00000,

0b00000,

0b00000,

0b00000,

0b00000,

0b11111

};

The pixel matrix and binary matrix of the second custom character displayed in the project are shown in the following image;

Pixel 8*5 e disposição binária para o segundo personagem personalizado usando Arduino

Fig. 9: 8*5 pixels and binary matrix for second custom character using Arduino

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b00000,

0b00000,

0b00000,

0b00000,

0b00000,

0b00000,

0b11111,

0b11111

};

The pixel matrix and binary matrix of the third custom character displayed in the project are shown in the following image;

 Pixel e matriz binária para terceiro caractere personalizado usando Arduino

Fig. 10: Pixel and binary array for third custom character using Arduino

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b00000,

0b00000,

0b00000,

0b00000,

0b00000,

0b11111,

0b11111,

0b11111

};

The pixel matrix and binary matrix of the fourth custom character displayed in the project are shown in the following image;

Pixel e matriz binária para o quarto caractere personalizado

Fig. 11: Pixel and binary matrix for the fourth custom character

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b00000,

0b00000,

0b00000,

0b00000,

0b11111,

0b11111,

0b11111,

0b11111

};

The pixel matrix and binary matrix of the fifth custom character displayed in the project are shown in the following image;

Pixel e matriz binária para o quinto caractere personalizado

Fig. 12: Pixel and binary matrix for the fifth custom character

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b00000,

0b00000,

0b00000,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111

};

The pixel matrix and binary matrix of the sixth custom character displayed in the project are shown in the following image;

Pixel e matriz binária para o sexto caractere personalizado

Fig. 13: Pixel and binary matrix for the sixth custom character

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b00000,

0b00000,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111

};

The pixel matrix and binary matrix of the seventh custom character displayed in the project are shown in the following image;

 Pixel e matriz binária para o sétimo caractere personalizado usando Arduino

Fig. 14: Pixel and binary matrix for the seventh custom character using Arduino

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b00000,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111

};

The pixel matrix and binary matrix of the eighth custom character displayed in the project are shown in the following image;

Pixel e matriz binária para o oitavo caractere personalizado usando Arduino

Fig. 15: Pixel and binary matrix for the eighth custom character using Arduino

The 8-byte character array for the custom character shown above can be defined in code as given below;

{

0b11111,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111,

0b11111

};

The Arduino IDE has a library called which provides many functions to access the LCD module. Few of these functions which are very useful in small applications have already been discussed in the previous project in how to interface with an LCD , how to display the sensor value on the LCD , how to connect the LCD to the PC and how to make a scrolling LCD display .

The code written for this project has an lcd.createChar function that helps create custom characters on an LCD screen. The details of the lcd.createChar function are discussed in the following section.

lcd.createChar

The lcd.createChar function can be used to write a custom character to the required location in the CGRAM. The function has two parameters in which the first parameter is the location in the CGRAM memory where the character array corresponding to the custom character needs to be stored and the second parameter is the character array itself. For example, if there is a custom character array called 'cc' and it needs to be stored in the 5th location of the CGRAM one can use the following statement;

lcd.createChar(5, cc);

The above instruction writes the character array to the 5th CGRAM location of the LCD controller from where it can be displayed by calling the lcd.write function discussed in the projects on how to connect LCD to PC and how to make a scrolling LCD display .

lcd.write(5);

Project source code

 ###




 /*================================= EG LABS =========================== ==========================

 Receive a character through the serial port of the PC and display the same character

 in a 16*2 LCD in scrolling manner along with glowing an LED each time

 

 The circuit:

 * LED attached from pin 5 to ground through a 1K resistor
 
 

LCD:

 * LCD RS pin to digital pin 12

 * LCD Enable pin to digital pin 11

 * LCD D4 pin to digital pin 5

 * LCD D5 pin to digital pin 4

 * LCD D6 pin to digital pin 3

 * LCD D7 pin to digital pin 2

 * LCD R/W pin to ground

 * 10K resistor:

 * ends to +5V and ground

 *wiper to LCD pin 3

 * LED anode attached to digital output 6

 * LED cathode attached to ground through a 1K resistor

 //================================= EG LABS =========================== ==========================*/


 // include the library code:

 #include

 
// initialize the library with the numbers of the interface pins

 LiquidCrystal LCD(12, 11, 5, 4, 3, 2);


 //----------------- store the custom characters in arrays ---------------------//

 byte cc1(8) =

 {

 0b00000,

 0b00000,

 0b00000,

 0b00000,

 0b00000,

 0b00000,

 0b00000,

 0b11111

 };


 byte cc2(8) =

 {

 0b00000,

 0b00000,

 0b00000,
 
0b00000,

 0b00000,

 0b00000,

 0b11111,

 0b11111

 };


 byte cc3(8) =

 {

 0b00000,

 0b00000,

 0b00000,

 0b00000,

 0b00000,

 0b11111,

 0b11111,

 0b11111

 };


 byte cc4(8) =

 {

 0b00000,

 0b00000,
 
0b00000,

 0b00000,

 0b11111,

 0b11111,

 0b11111,

 0b11111

 };


 byte cc5(8) =

 {

 0b00000,

 0b00000,

 0b00000,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111

 };


 byte cc6(8) =

 {

 0b00000,
 
0b00000,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111

 };


 byte cc7(8) =

 {

 0b00000,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111

 };


 byte cc8(8) =

 {
 
0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111,

 0b11111

 };

 //----------------- store the custom characters in arrays ---------------------//


 // give the LED pin a name:

 int led = 6;


 void setup

 {

 //---- create custom characters ----//

 lcd.createChar(1, cc1);

 lcd.createChar(2, cc2);

 lcd.createChar(3, cc3);

 lcd.createChar(4, cc4);

 lcd.createChar(5, cc5);
 
lcd.createChar(6, cc6);

 lcd.createChar(7, cc7);

 lcd.createChar(8, cc8);

 //---- create custom characters ----//

  

// initialize the led pin as an output.

 pinMode(led, OUTPUT);

  

// set up the lcd's number of columns and rows:

 lcd.begin(16, 2);

 }


 void loop

 {

 lcd.print("EG LABS ");

 

lcd.write(1); // display custom character

 //---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);

 delay(1000);
 
//---- blink LED -----//

   

lcd.write(2); // display custom character

 //---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);

 delay(1000);

 //---- blink LED -----//

  

lcd.write(3); // display custom character

 //---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);

 delay(1000);

 //---- blink LED -----//

   

lcd.write(4); // display custom character
 
//---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);

 delay(1000);

 //---- blink LED -----//

     

lcd.write(5); // display custom character

 //---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);

 delay(1000);

 //---- blink LED -----//

  

lcd.write(6); // display custom character

 //---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);
 
delay(1000);

 //---- blink LED -----//

  

lcd.write(7);

 //---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);

 delay(1000);

 //---- blink LED -----//

  

lcd.write(8); // display custom character

 //---- blink LED -----//

 digitalWrite(led, HIGH);

 delay(1000);

 digitalWrite(led, LOW);

 delay(1000);

 //---- blink LED -----//

 

lcd.clear;

 }

 ###

 

Circuit diagrams

Circuit Diagram-Creating Custom Characters-LCD-Using-Arduino

Project Components

  • Arduino ProMini
  • LCD
  • LED
  • Resistor

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.