LoginSignup
4
3

More than 5 years have passed since last update.

Unicorn HAT HDで日本語を表示する

Posted at

念願のRaspberryPi3を購入できました ('-'*)
その際UnicornHAT HDに興味を惹かれつつ、日本語の表示ってどうなんだろうと半信半疑ながらも人柱覚悟で一緒に購入してみました

結果

問題なく表示できますw

Attachment1.jpg
Attachment2.jpg

作業手順

とりあえず、Unicorn HATは未装着の状態で作業を行います

フォントのインストール

とにもかくにもフォントが必要なので、GoogleのNotoフォントを入れました

apt-get -y install fonts-noto

※ その後再起動しました

UnicornHAT HD関連 いろいろインストール

公式に従って

curl https://get.pimoroni.com/unicornhathd | bash

※ root権限ではインストールできませんでした、一般ユーザで作業しましょう

※ その後シャットダウンし、UnicornHATを取り付けました

日本語表示用スクリプト

とりあえずサンプルコードをさくっとコピーしました
(pathは適当に読み替えていただければ・・・)

cp -R /home/pi/Pimoroni/unicornhathd /opt/
cp /opt/unicornhathd/examples/text.py /opt/unicornhathd/

ではでは、改変します

2行目にUFT-8の指定を追加します

#-*- coding: utf-8 -*-

24行目 - 29行目まで、表示させる文字列を日本語に変えます
その際、Unicodeを明示します

lines = [u"あ",
         u"ア",
         u"亜"]

37行目 FONT指定部分の変更

FONT = ("/usr/share/fonts/truetype/freefont/FreeSansBold.ttf", 12)
↓
FONT = ("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", 12)

試行錯誤の結果、これで大丈夫でした

ついでに

45行目 unicornhathd.rotation(0)の部分を
unicornhathd.rotation(90)とか、unicornhathd.rotation(180)、unicornhathd.rotation(270)で表示方向が変わるので自由に配置できますね('-'*)

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