How to Display Animation on Waveshare E-Paper Display
How to use Waveshare E-Paper Display?
Please follow the previous tutorial for setting up the basic. This tutorial assumes you already have an animation ready to use.
What type of animation will be suitable to display on E-Paper
- Black and White, as the display we have in stock is Black and White only
- Low framerate animation, such as hand-drawn animation, as the display is not refreshing very fast.
- Short animation, depends on the Pi you use, Pi 3 may not be powerful enough to drive and store long animation.
File Preparation - Adobe Premiere Pro
- Resize the resolution to fit the display - 800x480 pixels
- Lower the framerate to 10 or 12 fps
- Export the video to jpg sequences from Premier and save them in a folder called ‘animation’
- Rename all jpg to
1.jpg to #.jpg
, if they are not alreadycd /path/to/your/folder a=1 for file in Sequence*.jpg; do mv "$file" "$a.jpg" ((a++)) done
- Now you can transfer the folder to the Raspberry Pi, you can use a USB stick or via SSH. Place the folder
animation
inside the foldere-Paper
.
File Preparation - Raspberry Pi
We will need to convert jpg to bmp in Pi using ffmpeg.
- Install ffmpeg,
sudo apt install ffmpeg -y
- Make sure you are at the
/animation
directory - Start conversion,
for f in *.jpg; do ffmpeg -i "$f" "${f%.jpg}.bmp"; done
- Remove old jpg files,
rm *.jpg
- Now all images in the animation folder should look like
1.bmp to #.bmp
Code
The below code will display the animation from frame 1 to the end frame.
!/usr/bin/python
# -*- coding:utf-8 -*-
# Display Width: 800, Display height: 480
import sys
import os
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
import random
from waveshare_epd import epd7in5_V2
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
logging.basicConfig(level=logging.DEBUG)
try:
logging.info("epd7in5_V2 Animation")
epd = epd7in5_V2.EPD()
logging.info("init and Clear")
epd.init_fast()
epd.Clear()
animation_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'animation')
image_files = sorted(
[f for f in os.listdir(animation_dir) if f.endswith('.bmp')],
key=lambda x: int(os.path.splitext(x)[0]))
if not image_files:
logging.info(e)
epd.sleep()
exit()
logging.info("switch to partial refresh")
epd.init_part()
while True:
for image_file in image_files:
image_path = os.path.join(animation_dir, image_file)
logging.info(f"Displaying: {image_file}")
Himage = Image.open(image_path).convert('1')
epd.display_Partial(epd.getbuffer(Himage), 0, 0, epd.width, epd.height)
# time.sleep(0.1)
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd7in5_V2.epdconfig.module_exit(cleanup=True)
exit()