Waveshare E-Paper Displays

From Embedded Lab Vienna for IoT & Security
Jump to: navigation, search

Summary

This documentation addresses the Waveshare E-Paper Displays of all sizes.

Requirements

  • Hardware: Raspberry Pi
  • Operating system: Rasbian
  • Interpreter: Python3

Description

Calendar Application on E-Paper Display

Devices

epd 7,5 inch black and red:

116-displaypng.png

This display has a diagonal length of 7,5 inch. The e-paper display has an equivalent of 640 by 384 Pixel that can be set to either white, black or red. For more information to this particular device look at Wavesshares Wiki webpage.

epd 2,13 inch black and red:

115-213inch-e-paper-hat-b-5-1jpg.jpg

This display has a diagonal length of 2,13 inch. The e-paper display has an equivalent of 212 by 104 Pixel that can be set to either white, black or red. For more information to this particular device look at this Wavesshares Wiki webpage.

Usage

This devices can be operated via a wide variety of devices like a Raspberry Pi or a STM32 or and Arduino. The manufacturer published a github repository to provide a libraries e-paper display for a wide range of programming languages. The github repository can be found under this link. This repo also provide example programs for both of this devices in the directory e-Paper/RaspberryPi&JetsonNano/python/examples. With the smaller display the epd_2in13bc_test.py runs the example program, where as the epd_7in5bc_test.py runs the test program for the 7,5 inch display.

Waveshare e-paper display python library

Firstly the Class of the corresponding Display needs to be imported as well as some functions from the Pillow library.

from waveshare_epd import epd2in13bc        # for 2.13 inch display
from waveshare_epd import epd2in13bc        # for 7.5  inch display
from PIL import Image,ImageDraw,ImageFont
import traceback
import logging

Then an instance of the class needs to constructed for further usage of the epd functions.

epd = epd2in13bc.EPD()                      # for 2.13 inch display
epd = epd7in5bc.EPD()                       # for 7.5  inch display

This allows us to use the basic e-paper display functions.

epd.init()                                  # to intialize the display
epd.Clear()                                 # resets the display to a white canvas
epd.sleep()                                 # sets the display to sleep mode

To display images on the device the display and getbuffer function is used like this:

epd.display(epd.getbuffer(BlackImage), epd.getbuffer(RedYelloyImage))

# epd.display(blackimage, redimage) reads the byte stream of the black and red part of the to being displayed image seperately
# epd.getbuffer(BlackImage) converts an Image created by the Pillow library to an byte array

Pillow python library

The Waveshare display converts Pillow images to a byte array for displaying them on the e-paper display. Here will be explained only a reduced set of commands of the Pillow library, more information about it can be found here.

Image.new

The Image.new new function creates an new virtual image. The first parameter defines the color space and in this specific case the one bit black and white color space is needed. The second parameter is filled with a tuple that defines te pixels of the height and width. The last parameter sets the colour which the whole image gets filed with. Our particular Displays need two image instances one for the black and white portion and one for the red portion.

BlackImage     = Image.new('1', (epd.height, epd.width), 255)
RedYelloyImage = Image.new('1', (epd.height, epd.width), 255) 

Image.Draw

The image Draw function enables us to write text and draw shapes onto the virtual image

drawblack  = ImageDraw.Draw(BlackImage)
drawyellow = ImageDraw.Draw(RedYelloyImage)

Writing Texts

To write a text the true type text font file needs to be imported first. The font size needs to be specified, during the importing function. Afterward the Darw.text can be used as shown.

font20 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20)
drawblack.text((x_start, y_start), 'Hello World', font = font20, fill = 0)

Drawing Shapes

The drawing shapes functions are strait forward they need a specified tuple of start and end points and the colour the shape get filled with.

drawblack.line((x_start, y_start, x_end, y_end), fill = 0)
drawblack.rectangle((x_start, y_start, x_end, y_end), outline = 0)

Calendar Example

The calendar app which is shown in the image above can be downloaded on this gitlab repository it uses the Google Calendar API to display the events to the Waveshare Display.

Used Hardware

References