Control Board, Displays

How to use Graphic LCD Displays with Raspberry Pi?

How to connect Graphic LCD to Raspberry PI?

The article shows how to hook up a 128×64 graphics LCD display to a Raspberry Pi.

LCD used is a 128×64 with LCD controller of ST7565. It can be powered directly from the Raspberry Pi 3.3V rail. It requires 5 GPIO pins for data.

The schematic is, CS (Chip Select), RST(Reset) and A0 (Register Select) can be connected to any 3 GPIO pins. In this example, 8,24 and 25 are default values. Different values can be specified as parameters when instantiating the ST7565 Python class. SCLK (Serial Clock) on the GLCD goes to GPIO 11 which is the Pi’s serial clock. SID (Serial Input Data) on the GLCD goes to GPIO 10 on the Pi which is MOSI. GPIO 10 and 11 must be used for SID and SCLK. Vdd is connected to a 3.3V pin on the PI and the grounds are also connected.

The LCD has a RGB backlight. The LED pins can go to GPIO’s 16,20 and 21. To control the color from the Pi, specifying RGB pins when instantiate the ST7565 class. The resistors must be placed in series to limit the current to prevent LED breakdown. The LED brightness can be changed by using different values of resistors. It will be best to adjust the current to be around 20mA, of course, different values will result in a different mix of colors. It is very difficult to mix a pure white color. Please calculate the resistor value carefully, at 40mA, the LED brightness will decrease sharply with time, with the current of close to 60mA, the LED might be breakdown and be permanently damaged.

How to program a Graphic LCD?

The display is 128 pixels horizontal by 64 pixels vertical. The LCD can be broken into 8 horizontal pages. They are numbered from 3 to 0 and 7 to 4 up to down. Each page includes 128 columns and 8 rows of pixels. To address the pixels, specifying the page and column number, and send a byte to fill 8 vertical pixels at once.

The display has SPI (Serial Peripheral Interface) to connect to Pi. SPI requires 3 lines MOSI, MISO and Clock. The Pi is the master and the GLCD is the slave. In this example, Only writing to GLCD and not ready, so the connection to MOSI and Clock lines are needed. MOSI is the output from the Pi to the GLCD and the Clock synchronizes the timing.

  1. Enable SPI on Raspberry Pi first
  2. From the raspi-config menu, select Advanced Options, then SPI. Then select Yes for “ Would like the SPI interface to be enabled”. Hit OK, Reboot. Select Yes for “ the SPI kernel module to be loaded by default”. Reboot the Pi after enabling SPI. Then test SPI using IsmodIt should return SPI_bcm2708 or spi_bcm2835 depending on the Pi version. The python SPI library requires python2.7 dev which can be installed with apt-get install:
  3. The Python SPI library is called py-spidev. It can be installed using git:GLCD Python library for the Pi can be downloaded from the GitHub site.
  4. The main ST7565 library (st7565.py) handles drawing, text & bitmaps, and a font module (xglcd_font.py) to load X-GLCD fonts. Here are the basic drawing commands which to create points, lines, rectangles, circles, ellipses, and regular polygons:For more details, please refer to the reference below or contact our engineers.

Contact Us