Bird
0
0
Arduinoprogramming~10 mins

Custom characters on LCD in Arduino - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Custom characters on LCD
Define 8-byte pattern array
Create custom char in LCD memory
Set cursor position on LCD
Write custom char to LCD
Display
The program defines a pattern for a custom character, loads it into the LCD's memory, sets the cursor, and then displays the custom character on the screen.
Execution Sample
Arduino
byte smiley[8] = {
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000,
  0b00000
};

lcd.createChar(0, smiley);
lcd.setCursor(0, 0);
lcd.write(byte(0));
This code defines a smiley face pattern, loads it as custom char 0, moves cursor to top-left, and displays the smiley.
Execution Table
StepActionVariable/FunctionValue/EffectLCD State
1Define custom char patternsmiley[0,10,0,0,17,14,0,0]No change
2Load custom char into LCDlcd.createChar(0, smiley)Custom char 0 storedCustom char 0 memory updated
3Set cursor positionlcd.setCursor(0, 0)Cursor at col 0, row 0Cursor moved
4Write custom charlcd.write(byte(0))Displays custom char 0Smiley shown at (0,0)
5End--Program waits for next commands
💡 All steps completed, custom character displayed on LCD at position (0,0).
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
smileyundefined[0,10,0,0,17,14,0,0][0,10,0,0,17,14,0,0][0,10,0,0,17,14,0,0][0,10,0,0,17,14,0,0][0,10,0,0,17,14,0,0]
lcd custom char 0emptyemptyloaded with smiley patternloaded with smiley patternloaded with smiley patternloaded with smiley pattern
cursor positionundefinedundefinedundefined(0,0)(0,0)(0,0)
LCD displayblankblankblankblanksmiley at (0,0)smiley at (0,0)
Key Moments - 3 Insights
Why do we use lcd.createChar before lcd.write?
lcd.createChar loads the pattern into LCD memory so lcd.write can display it; without loading, lcd.write won't show the custom shape (see steps 2 and 4 in execution_table).
What does the byte array represent?
Each byte in the array defines one row of the 5x8 pixel character; bits set to 1 light pixels, 0 leave them off (step 1 in execution_table).
Why do we use byte(0) in lcd.write?
byte(0) tells lcd.write to display the custom character stored at position 0 in LCD memory (step 4 in execution_table).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the cursor position after step 3?
A(0,0)
B(1,0)
C(0,1)
Dundefined
💡 Hint
Check the 'cursor position' value in variable_tracker after step 3.
At which step is the custom character pattern loaded into LCD memory?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the 'Action' column in execution_table for loading custom char.
If we change lcd.write(byte(0)) to lcd.write(byte(1)), what happens?
ADisplays the smiley again
BDisplays a different custom char if defined at 1
CDisplays nothing
DCauses an error
💡 Hint
Custom chars are stored at positions 0-7; writing byte(1) shows char at position 1 if created.
Concept Snapshot
Custom characters on LCD:
- Define 8-byte array for 5x8 pixel pattern
- Use lcd.createChar(index, pattern) to load
- Set cursor with lcd.setCursor(col, row)
- Display with lcd.write(byte(index))
- LCD supports up to 8 custom chars (0-7)
Full Transcript
This example shows how to create and display a custom character on an LCD using Arduino. First, we define a byte array representing the pixel pattern of the character. Then, we load this pattern into the LCD's memory at a specific index using lcd.createChar. Next, we set the cursor position where we want to display the character. Finally, we write the custom character to the LCD using lcd.write with the index. The execution table traces each step, showing variable states and LCD changes. Key moments clarify why loading the character before writing is necessary, what the byte array means, and why we use byte(0) in lcd.write. The visual quiz tests understanding of cursor position, loading step, and what happens if we write a different custom char index. The snapshot summarizes the process in a quick reference format.