raspberry pi

RaspiLcd monochrome graphic display connection and Python Programming

RaspiLCD with Raspberry Pi, Overview:

The RaspiLCD is a monochrome graphic display with a 1.8 inch display (see Figure 1). In addition, the display has a total of six freely assignable Buttons on the circuit board. As a nice extra there is a DS1338 Real Time Clock with a backup battery integrated.

Figure 1: The RaspiLCD, mounted on a Raspberry Pi 1, model B

Amazon Purchase Links:

Raspberry Pi

raspberry pi 4 4gb kit

Wireless Keyboard and Mouse for raspberry pi:

Night vision Camera for Raspberry Pi:

Oled HDMI touch display for raspberry pi:

TOP10 Best Raspberry Pi Kits

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

The RaspiLCD connection to the Raspberry Pi

The connection of the display seems to be very easy at first glance, because an existing socket strip below the circuit board exactly on the GPIO strip of the Raspberry Pi fits. However, you must first use the yellow cinch socket on the Raspberry Remove the Pi (see Figure 2), which is quite annoying as it won’t can be used more and removing it also involves a few risks.

Figure 2: Before installing the RaspiLCD on a Raspberry Pi 1, Model B, you have to remove the video jack.


Figure 3: The RaspiLCD on a Raspberry Pi 1, Model B + or on a Raspberry Pi 2, Model B


Assembly tips

The RaspiLCD can be used on the Raspberry Pi 2 or on the Raspberry Pi 1, model B +, can only be mounted using a stacking header. There is no need to remove, but the LCD board now hovers quite high above the Pi (see Figure 3). Use small plastic spacers around the display to stabilize!

Alternatively, a connection with jumper cables is possible. You should see the display want to build in permanently, sooner or later a small self-built one is recommended Adapter that connects the GPIO pins to the display. We removed the socket for our experiments. Then the RaspiLCD fits like molded onto the mini-PC and rests firmly on the integrated spacers. The entire GPIO bar is now occupied. RaspiLCD, however, carries the I2C and UART pins in the form of a 6-pin hole pattern so that you can also use them with the display.

The control with Python

After you have decided on a connection method, we can help continue controlling the display. There are some on the manufacturer’s website Links to C and Python libraries that contain some demo programs. Very much You will not find any documentation there, however. Hence, you are researching the possibilities on your own. We try to get you started with the display a little easier.

As an example, let’s write a small program that shows the CPU temperature and the current date on the RaspiLCD. Both functions are via a main menu accessible. The software is available on the manufacturer’s website. Libraries are available for selection in C, Java, PHP and Python. First download the Python library and extract it to a folder. To perform the actions on your PC or run them on the Raspberry Pi the following commands are used. With apt-get you install mercurial. This version is required to control the program to load the files from Bitbucket.


sudo apt – get install mercurial

hg clone https :// bitbucket.org/Svedrin/raspilcd

Then compile the library. In the shell script buildrun.sh are contain necessary commands. Once the compilation process is complete, the Demo program on the RaspiLCD. Press the buttons on the LCD screen to try out all the functions of the demo program.

cd raspilcd / RaspiLCD \ V0 .9.0

chmod + x buildrun .sh

./ buildrun .sh

The lcd.so file is now in the / home / pi / raspilcd / RaspiLCD V0.9.0 / directory. This is very important for the later use of the Python library. At the it’s best to leave the file where it is for now. Our tests showed that the easiest way is to find the path of the lcd.so file in the python library as a complete Specify path. To do this, change to the pylcd directory and open raspilcd.py:

cd / home / pi / raspilcd / pylcd

nano raspilcd.py

Now change the line raspi_lcd = ctypes.cdll.LoadLibrary (“lcd.so”) as follows from:

raspi_lcd = ctypes. cdll. LoadLibrary ( “/ home / pi / raspilcd / RaspiLCD V0 .9.0 / lcd.so”)

Save and exit the file. The library is now ready for use. All further Functions that are necessary for the operation of the RaspiLCD are also included in the Directory pylcd. Copy the entire contents of the directory into the path, in which your own program is to be saved. Or create your own Program impylcd directory.

The following Python code creates a small main menu and the subitems Temperature and time (see Figure 4 and 5). The program also contains Functions for displaying the CPU temperature and the date, we use many of them Basic functions of the raspilcd library, which are mostly are self-explanatory.

#! / usr / bin / python
# coding = utf -8
from raspilcd import RaspiLCD, font_terminal_6x8,
import time
import commands
from PIL import Image # optional
img = image. open ("image. bmp") # optional
lcd = RaspiLCD ()
lcd. backlight = True
def time ():
now = time. strftime ("% y.% b% H:% M:% S")
lcd. clear_framebuffer ()
lcd. font = font_fixedsys_8x15
lcd. print_xy (0, 20, now)
lcd. font = font_terminal_6x8
lcd. print_xy (0, 50, "Menu")
def temp ():
temp = commands. getoutput ("/ opt / vc / bin / vcgencmd measure_temp")
lcd. clear_framebuffer ()
lcd. font = font_fixedsys_8x15
lcd. print_xy (0, 20, "CPU - Temp:% s1f"% (temp [5:]))
lcd. font = font_terminal_6x8
lcd. print_xy (0, 50, "Menu")
def menu ():
lcd. clear_framebuffer ()
lcd. font = font_terminal_6x8
lcd. image_xy (0, 0, img) # optional
lcd. print_xy (60, 10, "temperature")
lcd. print_xy (95, 45, "time")
Menu ()
lcd. write_framebuffer ()
lcd. event ['btn: center: pressed']. addListener (time)
lcd. event ['btn: left: pressed']. addListener (temp)
lcd. event ['btn: right: pressed']. addListener (menu)
lcd.run ()

The small program creates an overview menu and has three of the six buttons a function to:

  • temperature
  • Time
  • back to the menu
Figure 4: The RaspiLCD sample program – temperature display


Figure 5: The RaspiLCD sample program – current time


By pressing the buttons marked with temperature and time, it jumps to the selected values to display them on the LCD (see Figure 4 and 5). For error-free execution of the program, an image image.bmp must be available and the PIL library installed. Delete the lines marked with #optional to run the program without Execute image.

Function overview

The following are the main methods and properties of the RaspiLCD class described. So you have to create a RaspiLCD object first and then you can apply the mentioned keywords to this object:

lcd = RaspiLCD ()

lcd.backlight = …

lcd.print_xy (…)

backlight = True / False: LCD backlight on / off.

print_xy (x, y, “Text”): This function shows text on the display. For x and y insert the position in pixels. Due to the resolution of the display x is a maximum of 128 and y is a maximum of 64 pixels.

font = fontname: Sets the font size for the following font commands. Available Fonts are: font_terminal_6x8, font_fixedsys_8x15, font_lucida_10x16 and font_terminal_12x16. Calling this function requires the import of the Fonts:

from raspilcd import RaspiLCD, font_terminal_6x8,

font_fixedsys_8x15, font_lucida_10x16, font_terminal_12x16

draw_line (x0, y0, x1, y1): Draws a line on the display. Determine x0 / y0 the start point, x1 / y1 the end point of the line.

draw_circle (x0, y0, r): Draws a circle. Required values: x0 / y0 = position for the center of the circle, r = radius.

draw_rect (x0, y0, x1, y1, line): Draws a rectangle. Determine x0 / x1 and y0 / y1 again the coordinates. The fourth value defines the line width. Will not Given a value, the line width is 1 pixel.

draw_ellipse (x, y, b, h): Draws an ellipse. x / y stands for the position, b / h for Width and height of the ellipse.

clear_framebuffer (): clears the framebuffer. To clear the display, you have to Send the empty buffer to the display with the following command.

write_framebuffer (): Transfers the framebuffer to the display. Imagine the mode of operation is as follows: Each text / drawing function writes to a internal buffer. Nothing happens on the display yet. Only after running write_framebuffer () transfers the internal buffer to the display. It is no transfer value necessary within the brackets. You should use the run () at the end of the program, the buffer is automatically transferred.

clear_display (): This function executes the two previous commands one after the other and thus deletes the entire screen content.

image_xy (x, y, img): Displays an image on the LC display. The library PIL required. If necessary, install this according to:

apt-get install python-setuptools

easy_install pip

pip install PIL

x / y indicate the position of the image and img indicates the path to the one to be displayed Image in BMP format.

run (): Always execute this function at the end of the program. she leads write_framebuffer () and enables the use of the buttons.

event [‘btn: center: pressed’]. addListener (function name): Creates an event that continuously monitored by a button. When the button is pressed, the function function name executed. You customize the button by changing the middle value: center, top, left, right or bottom.

As mentioned at the beginning, the RaspiLCD also has an integrated real-time clock Button cell. To start up the clock, proceed as described in Real Time Clock article.

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button