Thanh navigation

Thứ Hai, 8 tháng 8, 2022

Making and displaying Custom characters on lcd with Arduino Uno and 16×2 lcd (LCD: Part 2)

 

This project is about displaying custom characters on 16×2 character lcd using arduino uno microcontroller. With ardunio uno its very easy to display custom characters on lcd. In arduino their is built in structure to generate custom character like many other features which make it perfect board for embedded system projects or diy(do it yourself) projects etc. 

What are custom characters?

Custom characters are self made characters which we design by our self. We have full control on designing them with some constraints which i will discuss later. Like if we want to display a smiley 🙂 on 16×2 lcd. We don’t have an ASCII character for smiley to display it on 16×2 lcd. Example of custom characters is below

Example of custom characters displayed on 16x2 lcd 

Example of custom characters displayed on 16×2 lcd

How custom characters are made and displayed on 16×2 lcd?

Before beginning any further i recommend you to please take the 16×2 lcd display introduction tutorial. Taking the tutorial will let you know about the pin out and internal structure of 16×2 lcd

16×2 lcd has an internal ​CG-RAM(character generated ram) in which we can generate or place our custom character. CG-RAM size is 64 bytes. We can generate/place 8 characters of size 5×8 at a time in CG-RAM. We can also place 5×10 size characters in CG-RAM but only 4.

5×8 represents the dimension of the matrix in which a particular character can be displayed. 5 represents the number of coulombs and 8 represents the number of rows. 5×8 combined is a matrix size. Matrix is composed of pixels which we turn on and off to represent or make a character. For example to display a smiley 🙂 in 5×8 dimension individual pixels on and off will be same like below.

5x8 pixel dimension of custom character display 

5×8 pixel dimension of custom character display

For each 5×8 matrix with custom character in it we have to translate it in to its equivalent bits. For example the binary value of rows in 5×8 matrix is shown below. Against each binary value its HEX code is also given.

  • Each switched on pixel binary value is ‘1‘.
  • Each switched off pixel binary value is ‘0‘.

  16×2 custom character smiley binary bits

 The above binary or hex values are then arranged in a byte array. Byte array is then placed in to CG-RAM of 16×2 lcd. Now when we want to display this smiley character on lcd screen we just call its address in CG-RAM and finally the character will appear on 16×2 lcd screen.

I almost explained every thing above, about generating custom characters in 16×2 lcd CG-RAM and displaying them on lcd screen. But still their are few things which are not part of this tutorial. Like custom character address in CG-RAM. Its because the arduino ide has pre-defined library which places the custom characters in CG-RAM and call it when needed for display. If you want to know about whats happening behind the library then  i recommend you to please learn about the custom character generation in internal hardware level first before proceeding.

Arduino custom characters displayed on 16×2 lcd – Circuit diagram

For this project you only need a 16×2 character lcd and arduino uno microcontroller/board. You can use any other character lcd according to your wish but remember to change the lcd.begin(no of coulombs of lcd, no of rows of lcd) command in code and insert the dimensions of the lcd you are interfacing with arduino uno. Almost all the character lcd’s have same pin out and uses same hd44780 lcd controller. So their will be no difference in circuit diagram or remaining code. Hd44780 lcd controller is responsible to display characters on character lcd, communicate with external devices and CG-RAM also resides in HD44780 lcd controller.  

In this project i am using 16×2 lcd in 4-bit mode so you have to make pin connections according to the 4-bit mode. Its not very hard just connect in the order given below.

  • LCD RS pin to digital pin 13 of arduino uno
  • LCD Enable pin to digital pin 12 of arduino uno
  • LCD D4 pin to digital pin 11 of arduino uno
  • LCD D5 pin to digital pin 10 of arduino uno
  • LCD D6 pin to digital pin 9 of arduino uno
  • LCD D7 pin to digital pin 8   of arduino uno

 Custom characters displayed on 16x2 lcd using arduino uno

 

Arduino custom character display – Project code

The code of the project is simple. I am going to display 8 custom character on 16×2 lcd. First the required characters byte array are declared in code. Byte arrays are declared in binary as well as hexadecimal format.

The createChar() command in ardunio ide is very important. It creates/puts the character matrix/array against an addres in CG-RAM of 16×2 lcd. In other microcontrollers we have to write the memory address where we want to place our newly created custom character but in ardunio the createChar() command creates the required character automatically and place it against an address in CG-RAM. createChar() function is part of LiquidCrystal library. If we open the library and see the function statements they are communicating with the HD44780 lcd controller and CG-RAM address are defined in the function.

Arduino code steps to create and display custom characters on 16×2 lcd

byte a[8]={B00000,B01010,B00100,B00100,B00000,B01110,B10001,};
The above statement is a byte array of a custom character in binary format.
lcd.createChar(2 , a);
The above command places the a[] byte array custom character against address 2 in CG-RAM. Real address is different its not 2 see library for real address.
lcd.write(2);
The above command displays the custom character placed against the address 2 in CG-RAM.


#include<LiquidCrystal.h>     

LiquidCrystal lcd(13 ,12, 11, 10, 9, 8); //16x2 lcd arduino interface pins
 
//Custom characters byte arrays
byte customchar[8]={B00000,B01010,B00000,B00000,B00000,B00000,B11111,};
byte a[8]={B00000,B01010,B00100,B00100,B00000,B01110,B10001,};
byte s[8]={B00100,B01010,B10001,B10001,B01010,B00100,};
byte s1[8]={B01110,B01010,B11111,B11011,B11111,B01010,B01110,};
byte s2[8]={B01010,B00100,B00100,B01010,B10001,B00100,B10001,};
byte s3[8]={B00100,B01010,B11111,B01010,B10101,B11011,B10001,};
byte s4[8]={0x1F,0x11,0x11,0x11,0x11,0x11,0x1F,};
byte s5[8]={B11111,B11101,B11011,B11101,B11111,B10000,B10000,B10000,};
//Custom characters byte arrays

void setup()
{
lcd.begin(16 ,2); //Initialize 16x2 lcd
lcd.clear(); //Clear lcd display screen

lcd.createChar(1 , customchar); //Creating custom characters in CG-RAM
lcd.createChar(2 , a);
lcd.createChar(3 , s);
lcd.createChar(4 , s1);
lcd.createChar(5 , s2);
lcd.createChar(6 , s3);
lcd.createChar(7 , s4);
lcd.createChar(8 , s5); //Creating custom characters in CG-RAM
}
void loop()
{
int rand,i;
lcd.setCursor(0 ,0); //Place lcd cursor on first row and first coulomb of 16x2 lcd
lcd.print("Cust Character!!"); //Display this test on first row on 16x2 lcd
lcd.setCursor(0 ,1); //Place lcd cursor on second row of 16x2 lcd first coulomb

for(rand=0;rand<10;rand++){ //For loop will display custom characters one by one
i=random(10);
lcd.setCursor(i ,1);
lcd.write(i); //-->>>PRINTING/DISPLAYING CUSTOM CHARACTERS
delay(500);
}
lcd.clear(); //Clear lcd and start again
}

Numerous custom character generators are available online i usually use maxpromer its easy to use and biggest advantage of it is. It can generate whole arduino code in just seconds. Just give it a try i bet you gone love it.

maxpromer custom character generator online 

More projects regarding custom characters, arduino and other microcontroller. All the projects are open source. Each and every statement with circuit diagram of the projects are well explained in the tutorials. 

Part 2: https://www.engineersgarage.com/making-custom-characters-on-lcd-using-arduino/ 

Không có nhận xét nào:

Đăng nhận xét