I "Can I use it for something like an electronic paper module?" I "I'm going to forget a lot of things to do lately, so let's use it as a to-do list (something like a memo)"
・ Raspberry Pi 3 model B + ・ Electronic paper module (4.2inch e-Paper Module) ・ Spacer (if you like)
Image of something like this ・ Itemize and save what to do (characters) in an appropriate text file (text.txt) -Read a text file with Python and write it to e-Paper
Write python source code
write.py
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
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
from waveshare_epd import epd4in2bc
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
import RPi.GPIO as GPIO
logging.basicConfig(level=logging.DEBUG)
try:
    #erase e-paper
    logging.info("epd4in2bc Demo")
    epd = epd4in2bc.EPD()
    logging.info("init and Clear")
    epd.init()
    epd.Clear()
    time.sleep(1)
    
    #read text file
    f = open('text.txt', 'r')
    memo_text = []
    for line in f:
        memo_text.append(line)
    f.close()
    #print(memo_text)
    
    #make text figure
    im = Image.new("RGB",(400,300),"white")
    draw = ImageDraw.Draw(im)
    fig1 = Image.open('fig.png').convert("RGBA") #Load the image of Irasutoya
    draw.rectangle((0, 0, 399, 299), fill=(255, 255, 255), outline=(0, 0, 0), width=3) #Outer frame rectangle
    draw.rectangle((0, 0, 399, 50), fill=(0, 0, 0), outline=(0, 0, 0)) #Filled rectangle in the to-do list
    im.paste(fig1, (200, 150),fig1.split()[3])    
    font_path = ImageFont.truetype('/usr/share/fonts/opentype/noto/NotoSansCJK-Light.ttc',30)
    text1 = "To Do List\n"
    draw.text((10, 10), text1 , fill=(255, 255, 255), font=font_path)
   
    
    font_path = ImageFont.truetype('/usr/share/fonts/opentype/noto/NotoSansCJK-Light.ttc',24)
    i = 0
    w = 0
    while i in range(len(memo_text)):
        draw.text((10, 50 + w), "・" + memo_text[i] , fill=(0, 0, 0), font=font_path)
        w = w + 35
        i = i + 1
    im.save("./../pic/hoge.bmp")
    # Drawing on the image
    logging.info("3.read bmp file")
    HBlackimage = Image.open(os.path.join(picdir, 'hoge.bmp'))
    HRYimage = Image.open(os.path.join(picdir, 'hoge.bmp'))
    epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage))
    time.sleep(2)
    logging.info("Goto Sleep...")
    epd.sleep()
    
except IOError as e:
    logging.info(e)
except KeyboardInterrupt:
    logging.info("ctrl + c:")
    epd4in2bc.epdconfig.module_exit()
    exit()
Edit the text file as follows and place it in the same directory as write.py
text.txt
Master's thesis
Proceedings
Contact real estate agent
Drinking party tomorrow
I felt surreal when I added the illustration of Irasutoya.

If you want to change the displayed item, rewrite text.text and then run the Python code again to update to the changed item.
Recommended Posts