製品
今回はwaveshareの電子ペーパーを使用します。 サイズは何種類もありますが、今回は2.9インチで赤白カラーのこちらを使用します。 https://www.waveshare.com/2.9inch-e-paper-module.htm動作
公式サイトのサンプルコードを動かします。 https://www.waveshare.com/wiki/2.9inch_e-Paper_Module_(B) ちなみにこれは同じサイズで白黒と赤白黒の三色カラーの二種類があり、それぞれドライバが違うので注意してください。(今回は三色カラーのBタイプを動かします) まずWikiの下の方にあるDemo Codeからデモコードをダウンロード。 中にはarduino、raspberyPi、stm32と各種マイコンごとのコードがありますが、今回使用するのはraspberrypi/pythonです。 まずraspberryPiの側の用意です。$ sudo raspi-config

$ sudo apt-get install python-rpi.gpio python-pil次に結線。 Wikiにもありますが、以下のように接続します。
- BUSY - GPIO24 (Pin18)
- RST - GPIO17 (Pin11)
- DC - GPIO25 (Pin22)
- CS - GPIO8 (Pin24)
- CLK - GPIO11 (Pin23)
- DIN - GPIO10 (Pin19)
- GND - Pin6など
- 3.3v - Pin1

pi@raspberrypi:~/2.9inch_e-paper_module_b_code/raspberrypi/python $ sudo python main.py Traceback (most recent call last): File "main.py", line 27, in import epd2in9b File "/home/pi/2.9inch_e-paper_module_b_code/raspberrypi/python/epd2in9b.py", line 28, in import Image ImportError: No module named Imageどうやらコードのインポートの記述に誤りがあるようです。 以下に示すように2つのファイルの修正をします。
- main.py
- epd2in9b.py
import Image → from PIL import Image import ImageFont → from PIL import ImageFont import ImageDraw → from PIL import ImageDrawもう一度トライ。
pi@raspberrypi:~/2.9inch_e-paper_module_b_code/raspberrypi/python $ sudo python main.py Traceback (most recent call last): File "main.py", line 69, in main() File "main.py", line 54, in main font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 16) File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 238, in truetype return FreeTypeFont(font, size, index, encoding) File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 127, in init self.font = core.getfont(font, size, index, encoding) IOError: cannot open resource今度は内部で参照しているフォントが見つからないと言われました。 存在しているフォントを探してそれに修正しましょう。
$ find / -name '*.ttf' 2> /dev/null | head -n 1この環境では
/opt/vc/src/hello_pi/hello_font/Vera.ttf
というのがあったのでこれを使用します。
main.py
""" このように書き換える """ """ font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 16) """ font = ImageFont.truetype('/opt/vc/src/hello_pi/hello_font/Vera.ttf', 16)そしてもう一回動かす。
$ sudo python3 main.py

- フォントによる文字出力
- 図形の描写(線、四角、丸)
- 画像の出力