LoginSignup
3
3

More than 3 years have passed since last update.

電子ペーパーモジュールをToDoリストとして使う

Posted at

きっかけ

僕「電子ペーパーモジュール何かに使えないかな?」
僕「最近やること多くて忘れそうだからToDoリスト(メモ的な何か)として使おう」

※電子ペーパーのセットアップ(接続や画像の表示等)はこっちに書いてあります。
Raspberry Piで電子ペーパーモジュールを動作させる

今回は文字を電子ペーパーモジュールに表示させます

用意したもの

・Raspberry Pi 3 model B+
・電子ペーパーモジュール (4.2inch e-Paper Module)
・スペーサー (お好みで)

手順

こんなものをイメージ
・適当なテキストファイル(text.txt)にやること(文字)を箇条書きして保存
・Pythonでテキストファイルを読み出し、e-Paperに書き込み

pythonのソースコードを書く

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") #いらすとやの画像を読み込み
    draw.rectangle((0, 0, 399, 299), fill=(255, 255, 255), outline=(0, 0, 0), width=3) #外枠の四角形
    draw.rectangle((0, 0, 399, 50), fill=(0, 0, 0), outline=(0, 0, 0)) #To Doリストの部分の塗りつぶしの四角形
    im.paste(fig1, (200, 150),fig1.split()[3])    

    font_path = ImageFont.truetype('/usr/share/fonts/opentype/noto/NotoSansCJK-Light.ttc',30)
    text1 = "To Doリスト\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()

テキストファイル内を以下のように編集し、write.pyと同じディレクトリに配置

text.txt
修論
予稿
不動産屋に連絡
明日飲み会

やってみた

いらすとやのイラストを入れるとシュールな感じになった
IMG_3433.jpg

表示する項目を変えたい場合は、text.textを書き換えた後にもう一度Pythonのコードを走らせると変えた項目に更新される

3
3
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
3
3