Difference between revisions of "Waveshare E-Paper Displays"
(→Usage) |
|||
(13 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
=== Devices === | === Devices === | ||
'''epd 7,5 inch black and | '''epd 7,5 inch black and red: ''' | ||
https://stuff.elvis.science/uploads/models/116-displaypng.png | https://stuff.elvis.science/uploads/models/116-displaypng.png | ||
Line 21: | Line 21: | ||
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 [https://www.waveshare.com/wiki/7.5inch_e-Paper_HAT_(B) webpage]. | 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 [https://www.waveshare.com/wiki/7.5inch_e-Paper_HAT_(B) webpage]. | ||
'''epd 2,13 inch black and | '''epd 2,13 inch black and red: ''' | ||
https://stuff.elvis.science/uploads/models/115-213inch-e-paper-hat-b-5-1jpg.jpg | https://stuff.elvis.science/uploads/models/115-213inch-e-paper-hat-b-5-1jpg.jpg | ||
Line 28: | Line 28: | ||
=== Usage=== | === 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 [https://github.com/waveshare/e-Paper/tree/master link]. | 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 [https://github.com/waveshare/e-Paper/tree/master link]. This repo also provide example programs for both of this devices in the directory <code>e-Paper/RaspberryPi&JetsonNano/python/examples</code>. With the smaller display the <code>epd_2in13bc_test.py</code> runs the example program, where as the <code>epd_7in5bc_test.py</code> 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 [https://pillow.readthedocs.io/en/stable/ 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 [https://git.fh-campuswien.ac.at/c1710475053/elvis-praktikum/tree/master/Wave%20Share%20Display repository] it uses the Google Calendar API to display the events to the Waveshare Display. | |||
== Used Hardware == | == Used Hardware == |
Latest revision as of 15:44, 22 October 2020
Summary
This documentation addresses the Waveshare E-Paper Displays of all sizes.
Requirements
- Hardware: Raspberry Pi
- Operating system: Rasbian
- Interpreter: Python3
Description
Devices
epd 7,5 inch black and red:
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:
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.
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
- Waveshare ePaper Display HAT f Raspberry Pi dreifarbig 2.13"
- Waveshare ePaper Display HAT f Raspberry Pi dreifarbig 7.5"
- Raspberry Pi 3, Model B+, WLAN, BT