電子ペーパー と E-Ink display HAT for Raspberry Pi を試す
購入したのはこれです
e-paper hat
Raspberry pi 用の e-paper hat
2.13inch e-Paper HAT (D) - Waveshare Wiki
(D)が何なのかイマイチわかりませんが、たぶんこれです。
接続
Zero に 40pin をはんだ付けして、HAT を差し込む。
SPI
raspi-config
から、SPI を有効化する。
SPIDEV, pil も入れる。
$ sudo apt install python-spidev python-pil
動作テスト
テスコードの取得と展開
7zipで圧縮されているようなので、
$ sudo apt-get install p7zip-full
しておく。
$ wget https://www.waveshare.com/w/upload/c/c7/2.13inch_e-paper_d_code.7z $ mkdir 2.13inch_e-paper_d_code $ cd 2.13inch_e-paper_d_code $ 7za x ../2.13inch_e-paper_d_code.7z
実行する。
$ python main.py e-Paper busy e-Paper busy release e-Paper busy e-Paper busy release traceback.format_exc(): Traceback (most recent call last): File "main.py", line 28, in <module> font15 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 15) File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 280, in truetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 145, in __init__ layout_engine=layout_engine) IOError: cannot open resource
フォントが無いだと・・・?!
フォントの設定
font15 = ImageFont.truetype('/opt/vc/src/hello_pi/hello_font/Vera.ttf', 15)
などとする。
んで、実行
$ python main.py e-Paper busy e-Paper busy release e-Paper busy e-Paper busy release Horizontal 1 #!/usr/bin/python Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal e-Paper busy e-Paper busy release Horizontal ・・・ループ
画像だけを表示する
#!/usr/bin/python # -*- coding:utf-8 -*- import epd2in13d import time from PIL import Image,ImageDraw,ImageFont import traceback try: epd = epd2in13d.EPD() epd.init() epd.Clear(0xFF) # read bmp file # epd.Clear(0xFF) image = Image.open('2in13d.bmp') epd.display(epd.getbuffer(image)) time.sleep(2) except Exception, e: print 'traceback.format_exc():\n%s' % traceback.format_exc() exit()
日本語を表示する
font は /usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc にしました。
#!/usr/bin/python # -*- coding:utf-8 -*- import epd2in13d import time from PIL import Image,ImageDraw,ImageFont import traceback try: epd = epd2in13d.EPD() epd.init() epd.Clear(0xFF) # Drawing on the image image = Image.new('1', (epd2in13d.EPD_HEIGHT, epd2in13d.EPD_WIDTH), 255) # 255: clear the frame draw = ImageDraw.Draw(image) font15 = ImageFont.truetype('/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc', 15) draw.text((40, 20), u'ようこそ!', font = font15, fill = 0) draw.text((40, 60), 'e-Paper demo', font = font15, fill = 0) draw.text((40, 80), 'Hello world', font = font15, fill = 0) epd.display(epd.getbuffer(image)) time.sleep(2) except Exception, e: print 'traceback.format_exc():\n%s' % traceback.format_exc() exit()
クリアするだけ
#!/usr/bin/python # -*- coding:utf-8 -*- import epd2in13d import time from PIL import Image,ImageDraw,ImageFont import traceback try: epd = epd2in13d.EPD() epd.init() epd.Clear(0xFF) except Exception, e: print 'traceback.format_exc():\n%s' % traceback.format_exc() exit()
犯したミス
電子ペーパーの向きを逆に刺した
サンプルプログラムを取得する際に、 7.5inch e-Paper HAT (B)
を、なぜか使用していた。
所感
ノイズっぽい線
左の方に、縦線が何本か出たりする。
いわゆるドット抜けに近い状態に見えるが、これは正常なのだろうか。
Youtube などで見る限り、そんな線は出てない。
初期不良の一種だろうか。
Zero W じゃなくてもよかった?
Zeroにピッタリのサイズだし、、、ということで、なんとなくZeroで実験したのだけども、べつに、Zeroでやる必要はなかった。
RPI ごと持ち運ぶのであれば、Zero が良いが、用途が決まっていないのであれば、zero は全てが遅いので無駄に時間がかかる(待つだけですが)。
機能を最大限に活かすのであれば、WifiかBluetoothで接続して、動的に内容を書き換える・・・のだろうけど、使いみちが思いつかないから、今は手が動かない。