Waveshare E-paper Display With Raspberry Pi Pico Microcontroller and MicroPython
by CoenTempelaars in Circuits > Microcontrollers
7099 Views, 4 Favorites, 0 Comments
Waveshare E-paper Display With Raspberry Pi Pico Microcontroller and MicroPython
Inspired by several e-paper projects on this site, I wanted to start tinkering with an e-paper display myself. I decided to keep things simple and to start small with:
- Waveshare black/white 3.7 inch e-paper display for Raspberry Pi Pico
- Raspberry Pi Pico microcontroller with presoldered headers
- MicroPython to execute the application
- Powered via USB
Since my Pico has no internet connectivity, I cannot make it do things like "show today's to-do list", "show today's appointments" or "show today's weather". I decided that the display shall print "Happy [day of the week]". The display will refresh around 3:00 am. I don't care much about the display refresh rate, as long as the display refreshes within one minute. The text has to be printed in a pretty font in the center of the display, which shall be in landscape orientation.
Future improvements are:
- Show some neat widgets with nano-gui
- Decrease the power consumption
- Connect it to a battery
- Package it into an old picture frame or a 3D printed housing
The steps in this guide have been executed with a black/white 3.7 inch e-paper display. It should be relatively easy to apply this guide to a display with different size and/or a display with color, provided that you have basic Python skills.
Supplies
- Waveshare e-paper display for Raspberry Pi Pico. I have used a black/white 3.7 inch e-paper display.
- Raspberry Pi Pico microcontroller. Either with presoldered headers or you will have to solder them yourself. I have used a Pico without wireless connectivity.
- Micro-USB cable to connect the Pico to a computer.
- USB charger to power the Pico after disconnecting it from the computer.
Connect the Pico to the Display
Gently connect the Pico to the e-paper display as shown in the pictures. Connect the Pico to your computer.
Install Thonny
Thonny is a Python IDE that allows us to send Python scripts to the MicroPython interpreter that will be running on the Pico. We will be using Thonny to edit our Python scripts and to execute them on the Pico.
Install Thonny version 3.3.3 or newer
See https://thonny.org for installation instructions.
Install MicroPython on the Pico
MicroPython is a Python interpreter that will be running on the Pico. The MicroPython interpreter will execute our Python application on the Pico.
Install MicroPython version 1.19.1 or newer on the Pico
See https://micropython.org for installation instructions.
Execute the Demo Application
Download the most recent Python demo application for your Waveshare e-paper from the Waveshare repository. Follow the instructions on https://waveshare.com for your specific product.
Open the Python script in Thonny and execute it on the Pico. Follow the Thonny built-in manual.
You should see text and shapes being printed on the e-paper. You should not see any errors in the Thonny terminal.
Shrink the Demo Application
A smaller script is easier to understand. Since we are only interested in monochrome text, we have the opportunity to remove unused functionality from the script.
Remove all code related to shapes, colors and grayscale. Do not remove any sleeps, unless you know what you are doing. Some sleeps are essential to avoid damaging the e-paper.
See all commits that start with the keyword "cleanup" in my repository:
Refactor the Demo Application
Refactoring is the art of improving the structure of the code while maintaining the behavior of the software.
Relentlessly improve the names of classes, attributes, methods and variables. Remove unnecessary comments. Resolve duplicate code and simplify complex structures. Stop when the code is easy to understand because it speaks for itself.
See all commits that start with the keyword "refactoring" in my repository:
Change the Font
From the repository below...
https://github.com/peterhinch/micropython-font-to-py
... we will use the following scripts:
- the Writer class to display text in our font
- the pre-converted freesans20 font to test the setup
- the font-to-py script to convert our font
Download writer.py and freesans20.py and store them on the Pico.
Download font-to-py.py and store it on your machine. If you are running Linux, consider to make font-to-py.py executable.
The Writer class requires that our EPD_3in7 class derives from framebuf.FrameBuffer, as done in the following commit:
https://github.com/CoenTempelaars/raspi-pico-epaper/commit/42a8e7c8e458be7ed8ba6f6c8e052a994f6c1b25
Use Writer and the freesans20 font to print something to the e-paper in a non-standard font for testing purposes, as in this commit:
https://github.com/CoenTempelaars/raspi-pico-epaper/commit/4efc36e844c2119f1476311241d91a41dd7047cb
Convert your own font with the font-to-py script. Use the -x parameter to apply horizontal mapping. Store the converted font on the Pico and change your code to print text in your font.
Rotate the Display
Change our EPD_3in7 class such that it implements a framebuffer in landscape orientation with bits vertically mapped. This framebuffer is the 'canvas' for the writer class. The contents of this framebuffer is transposed into a new framebuffer in portrait orientation with bits horizontally mapped. The latter framebuffer is sent to the e-paper.
See the following commit:
https://github.com/CoenTempelaars/raspi-pico-epaper/commit/4f47b1a42a439ca6c5852572997184407efea665
Center the Text
I created a specialization of a Writer class called CenterWriter. CenterWriter can be used to write one or more lines, adjusted to the center of the e-paper, horizontally and vertically. It disables the line wrapping and scrolling features of the Writer class. It provides a set_vertical_spacing method to increase the distance between the lines and it provides a set_vertical_shift method to shift the entire set of lines up or down. Give it a negative integer to shift up or a positive integer to shift down.
Introduce a CenterWriter class as in the following commits:
https://github.com/CoenTempelaars/raspi-pico-epaper/commit/d303419d738c639e03c65d51c7db1dca794bba6f
https://github.com/CoenTempelaars/raspi-pico-epaper/commit/4708537cc699b162056fbc58ddc3c00af674bf78
Personalize the Text
Use your imagination and modify main.py to show the text that you like. You can create a loop that updates the display every 24 hours around midnight or every hour or ... you choose!
Final Words
Was this guide helpful to you? Did you apply this guide successfully to an e-paper h different dimensions? Please let me know in the comments!
Did you find a mistake, ambiguity or unclarity in my instructions? Please leave a comment!
Do you need help? Don't be afraid to ask for help, but please consider that stackoverflow and the micropython forum have a much wider reach than the comments section below.