This tutorial is about making/building your own characters/special images and then displaying them on character 16×2 lcd. Generating custom characters or special character images and displaying on lcds of any sizes (16×1,16×2,8×1,8×2,20×1,20×2,40×1,40×2 etc) is not a very hard task. One must go through the internal structure of lcd control set in order to know how the character lcd works? Once you know how the lcd works and what features it offers. Then you can easily build and display characters of your desire on lcd screen in a defined matrix.
What are custom characters?
How custom characters are displayed on 16×2 lcd?
Circuit Diagram
How to Generate Byte Code for Custom Characters
- Visit https://maxpromer.github.io/LCD-Character-Creator/
- Create the Character You Want
- Copy the byte char array code. Example : byte customChar[] = { B00000, B00000, B01010, B10101, B10001, B01010, B00100, B00000 };
- Paste the code accordingly in my source code and change the name accordingly.
Source Code
/*
Custom Characters
16 x 2 LCD Display with Arduino
HarshTronics
For More :
https://www.harshtronic.blogspot.com
https://www.instagram.com/harshtronics
*/
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
int contrast = 100;
byte s1[8]= // Array of bytes
{
B00000, // B stands for binary formatter and the 5 numbers are the pixels
B00000,
B01010,
B10101,
B10001,
B01010,
B00100,
B00000
};
byte s2[8]={B00100,
B01110,
B01110,
B01110,
B11111,
B00000,
B00100,
B00000,};
byte s3[8]=
{
0b01110,
0b01110,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010,
0b01010,};
byte s4[8]={B00100,B01010,B11111,B01010,B10101,B11011,B10001,};
byte s5[8]=
{ B00000,
B01110,
B10001,
B10001,
B10001,
B01010,
B11011,
B00000,
};
byte s6[8] =
{
B00000,
B00000,
B01010,
B00000,
B10001,
B01110,
B00000,
B00000,
};
void setup() {
analogWrite(6,contrast);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
lcd.createChar(1, s1); // Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are supported
lcd.createChar(2, s2);
lcd.createChar(3, s3);
lcd.createChar(4, s4);
lcd.createChar(5, s5);
lcd.createChar(6, s6);
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Custom Character");
for(int i=5;i<11;i++)
{
lcd.setCursor(i,1);
lcd.write(i-4);
delay(500);
}
delay(50000);
}