LoginSignup
0
0

Raspberry Pi用 4.01インチ ACeP 7色e-Paper ディスプレイ 640×400 を動かしてみた

Last updated at Posted at 2023-09-17

はじめに

Raspberry Pi OS

Raspberry Pi Imager v1.7.5

Raspberry Pi OS (64-bit)

Raspberry Pi 4B (4GB)

7色 Eインクディスプレイ

手順

SPIの有効化

sudo raspi-config

Interfacing Options -> SPI -> Yes を選択する。

再起動する。

sudo reboot

Pythonライブラリのインストール

sudo apt update
sudo apt upgrade
sudo apt-get install python3-pip python3-pil python3-numpy
sudo pip3 install RPi.GPIO spidev

サンプルデモのプログラムを動かす

sudo apt install git
git clone https://github.com/waveshare/e-Paper.git
cd e-Paper/RaspberryPi_JetsonNano/python/examples/
python3 epd_4in01f_test.py

IMG_2470.jpg

IMG_2471.jpg

電子ペーパーへ画像を表示する

パレット画像(テキスト形式)を用意する

palette.txt
# ImageMagick pixel enumeration: 7,1,255,srgb
0,0: (0,0,0)  #000000  black
1,0: (255,255,255)  #FFFFFF  white
2,0: (0,255,0)  #00FF00  lime
3,0: (0,0,255)  #0000FF  blue
4,0: (255,0,0)  #FF0000  red
5,0: (255,255,0)  #FFFF00  yellow
6,0: (255,128,0)  #FF8000  srgb(255,128,0)

パレット画像(テキスト形式)をPNG形式へ変換する

ImageMagickのconvertコマンドを使用する。

sudo apt install imagemagick
convert palette.txt palette.png

(palette.png)
palette2.png

Stable Diffusionで生成された画像ファイル(512x512)の画像サイズ(640x400)とディザー形式へ変換する

convert image.png -rotate '-90<' -dither FloydSteinberg -resize 640x400 -gravity Center -extent 640x400 -remap palette.png tmp.bmp

電子ペーパーへ表示する。

サンプルデモのライブラリを使用して、画像ファイル(640x400)を電子ペーパーへ表示します。

cp ../lib/waveshare_epd/epd4in01f.py ./
cp ../lib/waveshare_epd/epdconfig.py ./

epd4in01f.py の 下記1行を修正する。

from . import epdconfig

import epdconfig

image.py を作成して実行する。

python3 image.py
image.py
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
import logging
import epd4in01f
import time
from PIL import Image,ImageDraw,ImageFont
import traceback

logging.basicConfig(level=logging.DEBUG)

try:
    logging.info("Start")
    epd = epd4in01f.EPD()
    logging.info("init and Clear")
    epd.init()
    epd.Clear()
    
    logging.info("read tmp.bmp file")
    Himage = Image.open('tmp.bmp')
    epd.display(epd.getbuffer(Himage))
    time.sleep(3)
    
    logging.info("Goto Sleep...")
    epd.sleep()
    
except IOError as e:
    logging.info(e)
    
except KeyboardInterrupt:    
    logging.info("ctrl + c:")
    epd4in01f.epdconfig.module_exit()
    exit()

IMG_2473.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0