Interfacing 128×64 Graphical LCD with Arduino

1,337 views

Introduction

In the world of electronics and embedded systems, having a display to showcase information is always essential. The 128×64 graphical LCD is a perfect solution for such requirements, capable of displaying both text and graphics.

In this article, we will explore how to interface the 128×64 graphical LCD with Arduino and create custom graphics & text to display on the screen. With this knowledge, you can enhance your projects with an advanced and visually appealing display.

What is a 128×64 Graphical LCD?

A 128×64 graphical LCD (Liquid Crystal Display) is a type of display that consists of 128 columns and 64 rows of pixels. It is called a graphical LCD because it is capable of displaying not only alphanumeric characters but also simple graphics and images.

These displays use a technology called passive matrix, where each pixel is controlled by a combination of row and column signals. Each pixel is made up of a liquid crystal that can be either opaque or transparent, allowing light to pass through or be blocked.

Hardware Components

To interface an 128×64 Graphical LCD with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
DC Power for Arduino1
Graphical LCD128×641
Potentiometer1
Jumper Wires1

128×64 LCD Pinout

128 x 64 Graphical LCD Pinout
128 x 64 Graphical LCD Pinout
Pin LabelPin FunctionPin Description
1VSSGroundGround connection. Connect to the GND pin of the Arduino UNO.
2VDDPower supplySupply the 5 V power supply here. For most of the LCD modules, you can connect the 5 V line from the Arduino pinout
3V0Contrast AdjustmentThe voltage at this pin defines the LCD contrast. 
4D/I#Data/ InstructionThe pin defines whether the data lines contain data or the instruction. 
5R/W#Data Read/ WriteThis is a control line. A read operation is indicated by driving this pin high. A write operation is indicated by driving this pin low.
6EEnable signalA high to low transition on this pin enables the LCD controller for communication 
7DB0Databus lineData bit 1
8DB1Databus lineData bit 2
9DB2Databus lineData bit 2
10DB3Databus lineData bit 3
11DB4Databus lineData bit 4
12DB5Databus lineData bit 5
13DB6Databus lineData bit 6
14DB7Databus lineData bit 7
15CS1Chip select lineChip select CS1
16CS2Chip select lineChip select CS2
17RST#Reset lineYou can reset the LCD controller by driving this pin Low. 
18VEENegative voltage outputVEE and V0 are used for contrast adjustments
19AAnodeThis is the anode of the LED used for the backlight. 
20KCathodeThis is the cathode of the LED used for the backlight.

128×64 LCD Arduino Circuit

Make connections according to the circuit diagram given below.

Wiring / Connections

Arduino128X64 Graphical LED
5VVCC , A(+)
GNDGND , CS1 , K(-)
D10D/I
D11R/W
D13E

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Installing Libraries

Before you start uploading a code, download and unzip the following libraries at /Program Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

#include <Arduino.h>
#include <U8g2lib.h>
 
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
 
// 'TheOffice', 128x64px, source: //https://www.electronicshub.org/interfacing-128x64-graphical-lcd-with-arduino/
 
static const unsigned char myBitmap [] PROGMEM = {
 
  0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0x3f, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x06, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7,
  0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0x9f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x03, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0xb0,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3f, 0x00,
  0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x08, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xb0,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x7f, 0x00,
  0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x08, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xb0,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xc0, 0x7f, 0x00,
  0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x08, 0xf0, 0xff, 0x03, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x07, 0x00, 0x00, 0x7c, 0xb0,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x07,
  0x00, 0x00, 0xfe, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x08, 0xf8, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb0, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb0,
  0x81, 0xff, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x0f,
  0x00, 0x00, 0xfe, 0xb0, 0x81, 0xff, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x08, 0xf8, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xb0, 0x81, 0xff, 0x1d, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xb0,
  0x01, 0x38, 0xdc, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x0f,
  0x00, 0x00, 0x7c, 0xb0, 0x01, 0x38, 0xfc, 0xf3, 0x03, 0x00, 0x00, 0x00,
  0x08, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0x38, 0xb0, 0x01, 0x38, 0xfc, 0xfb,
  0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0xfc, 0xb0,
  0x01, 0x38, 0x9c, 0x3b, 0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x07,
  0x00, 0x00, 0xfe, 0xb0, 0x01, 0x38, 0x9c, 0xfb, 0x07, 0x00, 0x00, 0x00,
  0x08, 0xfc, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb7, 0x01, 0x38, 0x9c, 0xfb,
  0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb7,
  0x01, 0x38, 0x9c, 0x3b, 0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x07,
  0x00, 0x00, 0xfe, 0xb7, 0x01, 0x38, 0x9c, 0xfb, 0x07, 0x00, 0x00, 0x00,
  0x08, 0xfe, 0xff, 0x07, 0x00, 0x00, 0xff, 0xb7, 0x01, 0x38, 0x9c, 0xf3,
  0x03, 0x00, 0x00, 0x00, 0x08, 0xfe, 0xff, 0x07, 0x00, 0x80, 0xff, 0xb7,
  0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00,
  0x00, 0xc0, 0xff, 0xb6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0xc8, 0xff, 0xff, 0x00, 0x00, 0xe0, 0xff, 0xb6, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xb6,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00,
  0xc0, 0xff, 0xff, 0xb6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0xc8, 0xff, 0xff, 0x00, 0xe0, 0xff, 0xff, 0xb6, 0x01, 0xf8, 0x07, 0xbe,
  0xff, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00, 0xe0, 0x7f, 0xff, 0xb7,
  0x01, 0xfc, 0x1f, 0xbf, 0xff, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0xfc,
  0xff, 0x0f, 0xff, 0xb7, 0x01, 0xfe, 0x1f, 0xbf, 0xff, 0x00, 0x00, 0x00,
  0xc8, 0xff, 0xff, 0xfc, 0xff, 0xef, 0xff, 0xb7, 0x01, 0x1f, 0x3e, 0x8f,
  0x03, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0xc0, 0x01, 0xfe, 0xff, 0xb7,
  0x01, 0x0f, 0xbc, 0xff, 0xef, 0xf0, 0x87, 0x1f, 0xc8, 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 0xb7,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xc0,
  0xe1, 0x61, 0x00, 0xb7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x08, 0x00, 0x00, 0xc0, 0xe1, 0x61, 0x00, 0xb7, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xc0, 0xe1, 0x61, 0x00, 0xb7,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xc0,
  0xe1, 0x60, 0x00, 0xb2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x03, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0,
  0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0xbc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0x06, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
  0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0x7f
};
 
 
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
 
 
void draw(void)
{
  u8g2.drawXBMP( 0, 0, 128, 64, myBitmap);
}
 
 
void setup()
{
  // put your setup code here, to run once:
  u8g2.begin();
  u8g2.clearBuffer();
}
 
void loop()
{
  // put your main code here, to run repeatedly:
  u8g2.firstPage();
  do
  {
    draw();
  } while (u8g2.nextPage());
 
  delay(1000);
 
}

Code Explanation

This code is for interfacing a 128×64 graphical LCD with an Arduino using the U8g2 library. The code starts with including the Arduino and U8g2 libraries. Then it checks if the LCD has hardware support for either SPI or I2C communication protocols, and includes the appropriate library depending on the result.

After that, there is a static array of bitmap data stored in the program memory of the Arduino. This bitmap data represents an image named “TheOffice” that is 128×64 pixels in size. The bitmap data is stored in the array in hexadecimal format.

The bitmap data is then used to display the image on the graphical LCD using the U8g2 library. The library provides methods to initialize the LCD, set its font, and display the bitmap data on the screen.

Overall, the code sets up the necessary libraries and data to display an image on a 128×64 graphical LCD using an Arduino microcontroller.

Applications

Here are some common applications of 128×64 graphical LCD displays:

  • Digital clock or timer
  • Electronic instrumentation and measurement devices
  • Data loggers and recorders
  • Industrial process control systems
  • Temperature and humidity monitoring systems
  • Heart rate monitors
  • Blood pressure monitors
  • GPS navigation systems
  • Personal digital assistants (PDAs)
  • Handheld gaming devices
  • Audio and video players
  • Robotics and automation systems
  • Smart home automation systems
  • Fitness trackers and health monitors
  • Automotive diagnostic tools

Conclusion.

interfacing the 128×64 graphical LCD with Arduino is a great way to add an informative and attractive display to your embedded system. By following the steps outlined in this article, you can quickly and easily get your display up and running, and start displaying custom graphics and text. The possibilities are endless with this display, and we hope this article has inspired you to explore and innovate with this powerful tool.