ラズパイ用Pimoroni(ピモロニ)PHAT 9選 3つ使ってみる

Raspberry Pi(ラズパイ)などの電子工作機器を発売しているPimoroni、ラズパイとともにイギリス発の会社なのでラズパイの親和性が高く、ラズパイに装着して遊べる面白いパーツを販売しています。

自分もPimoroniのPHATをいくつか買ってラズパイで使っているので、インストールや操作方法など、まとめてみました。

  1. PimoroniのRaspberry Pi ZeroサイズのPHAT
    1. Unicorn pHAT
      1. Raspberry Pi Zeroにピッタリ 4x8 LED
    2. Touch pHAT
      1. Raspberry Pi ZeroにピッタリなLEDが光る6タッチボタン
    3. Explorer pHAT
      1. Raspberry Pi Zeroにピッタリなよく使うピンをまとめる
    4. Pimoroni OnOff SHIM – パワー オン/オフ for Rasp
      1. Raspberry Pi Zeroより小さめ ラズパイのオン・オフをボタンで操作
    5. Pimoroni Pico Display Pack for Raspberry
      1. Raspberry Pi Zeroにピッタリな18-bit 1.14インチ ディスプレイ
    6. Pimoroni Four Letter pHAT – 4文字 pHAT for
      1. Raspberry Pi Zeroにピッタリ 4文字 pHAT
    7. Pimoroni Scroll pHAT HD for Raspberry Pi
      1. Raspberry Pi Zeroにピッタリ 17×7 の 119個の LED
    8. Pimoroni Unicorn HAT Mini – ユニコーン ハット ミニ
      1. Raspberry Pi Zeroにピッタリ 17×7(119個)RGB LED
    9. Pimoroni Inky pHAT – 3色 赤 黒 白 e-paper
      1. 2.13インチ Raspberry Pi Zeroにピッタリ 3色(赤、黒、白)電子ペーパー
  2. Pimoroni Touch PHAT でGPIO操作
      1. Touch pHAT
    1. 目的
    2. github
    3. インストール
    4. 設定
    5. テスト
      1. buttons.py
      2. launcher.py
    6. GPIO オン・オフのタッチボタンにする
    7. Warningが出た
    8. Cronで起動時に起動
    9. Touch PHAT 設置完成
  3. Scroll pHAT HD
      1. Pimoroni Scroll pHAT HD for Raspberry Pi
    1. Pimoroniのサイト
      1. Scroll HAT Miniもある
    2. scroll-phat-hd インストール
    3. ライブラリを登録
    4. サンプルの場所
    5. unicode-scrolling.py エラー
    6. pimoroni-dashboard
    7. cpu.py
    8. カウントダウン表示
    9. 日本語表示
      1. Ticker
      2. misakiフォント
    10. 3Dプリンターでカバーを作って電光掲示板として使う
  4. Inky pHAT
      1. Pimoroni Inky pHAT – 3色 赤 黒 白 e-paper
    1. pimoroniサイトとgithub
    2. インストール
    3. インストール後 サンプルの場所
    4. Raspi3Bで横表示、サンプルのカレンダーを使う
    5. Cronで毎日実行
    6. 小さいけどオシャレなカレンダーを表示
  5. PimoroniのRaspberry Pi ZeroサイズのPHAT 7種

PimoroniのRaspberry Pi ZeroサイズのPHAT

日本でも買えるPimoroniのPHATは7種ほどありました。イギリスのPimoroniサイトですともっと多数のPHATがあります。

こちらはRaspberry Pi Zeroのサイズにピッタリな7種を紹介します。順位は高い順です。

Unicorn pHAT

Unicorn pHAT
Pimoroni

1,500円前後

Raspberry Pi Zeroにピッタリ 4x8 LED

Touch pHAT

Touch pHAT
Pomoroni

1,500円前後

Raspberry Pi ZeroにピッタリなLEDが光る6タッチボタン

Explorer pHAT

Explorer pHAT
Pomoroni

2,000円前後

Raspberry Pi Zeroにピッタリなよく使うピンをまとめる

Pimoroni OnOff SHIM – パワー オン/オフ for Rasp

Pimoroni OnOff SHIM - パワー オン/オフ for Rasp
Pimoroni

2,500円前後

Raspberry Pi Zeroより小さめ ラズパイのオン・オフをボタンで操作

Pimoroni Pico Display Pack for Raspberry

Pimoroni Pico Display Pack for Raspberry
Pimoroni

3,500円前後

Raspberry Pi Zeroにピッタリな18-bit 1.14インチ ディスプレイ

Pimoroni Four Letter pHAT – 4文字 pHAT for

Pimoroni Four Letter pHAT - 4文字 pHAT for
Pimoroni

4,000円前後

Raspberry Pi Zeroにピッタリ 4文字 pHAT

Pimoroni Scroll pHAT HD for Raspberry Pi

Pimoroni Scroll pHAT HD for Raspberry Pi
Pimoroni

4,000円前後

Raspberry Pi Zeroにピッタリ 17×7 の 119個の LED

Pimoroni Unicorn HAT Mini – ユニコーン ハット ミニ

Pimoroni Unicorn HAT Mini - ユニコーン ハット ミニ
Pimoroni

5,000円前後

Raspberry Pi Zeroにピッタリ 17×7(119個)RGB LED

Pimoroni Inky pHAT – 3色 赤 黒 白 e-paper

Pimoroni Inky pHAT - 3色 赤 黒 白 e-paper
Pimoroni

7,500円前後

2.13インチ Raspberry Pi Zeroにピッタリ 3色(赤、黒、白)電子ペーパー

このPHATの中でいくつかラズパイで使いましたので使い方など紹介していきますね。

Pimoroni Touch PHAT でGPIO操作

GPIOをオン・オフしたりコマンドを覚えさせるとタッチで実行してくれるPHAT。

タッチ時のみLEDが光る仕様のようです。

Touch pHAT

Touch pHAT

1,500円前後

目的

タッチボタンでGPIO操作 オン・オフできるようにする

(オンで点灯・オフで消灯はできなかった。タッチした時のみ点灯する)

github

こちらにソースや使い方の説明があります。

GitHub - pimoroni/touch-phat: Python library and examples for Pimoroni Touch pHAT - six touch sensitive buttons to control your project.
Python library and examples for Pimoroni Touch pHAT - six touch sensitive buttons to control your project. - GitHub - pimoroni/touch-phat: Python library and ex...

インストール

$ sudo apt-get install pimoroni

設定

以下を実行して設定

$ pimoroni-dashboard

最初に以下のようなアラートが出るのでエンターキーを押して先に進む。

pHATを使うので 2 My Pimoroni product is a pHATを選ぶ

続いて↓下にスクロールしていって14 Touch pHAT を選ぶ。

これで設定は終了。

テスト

/home/pi/Pimoroni/touchphat にフォルダーが作成される。

$ cd /home/pi/Pimoroni/touchphat/examples 

buttons.py

サンプルを実行して、各タッチボタンを押す。

$ python3 buttons.py

Touch pHAT: Buttons Demo
Lights up each LED in turn, then detects your button presses.
Press a button to see the corresponding LED light up, and the name printed.
Press Ctrl+C to exit!

B
C
A
Back
B
C
D
Enter
Back

タッチボタンを押すと光って、A/B/C/D/Back/Enterが表示される。

ちなみにpython3ではなく、python buttons.pyとしたらpython2.7が起動してしまってエラーになった。

launcher.py

タッチすると、GPIOオン・オフできるようにする。

$ python3 launcher.py

Remainder of file ignored

No X display detected!
This example requires a full desktop
... exiting.

ただしSSHで外部からではなく、デスクトップ環境から実行しないとダメみたい。

GPIO オン・オフのタッチボタンにする

6個のタッチボタンをGPIO12・16・20・21・5・6のオン・オフを操作できるようにした。

gpio-touch-phat.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import signal
import time
import touchphat

import RPi.GPIO as GPIO
import sys

PUL  = int(12) # LED
FAN  = int(16) # FAN
TES  = int(20) #
TET  = int(21) #
#BUTTON5   = 5  #
#BUTTON6   = 6  #
BAL  = int(13) # バックライト
WAT  = int(19) # ラズパイ時計

GPIO.setmode(GPIO.BCM)
GPIO.setup(PUL,GPIO.OUT)
GPIO.setup(FAN,GPIO.OUT)
GPIO.setup(TES,GPIO.OUT)
GPIO.setup(TET,GPIO.OUT)
GPIO.setup(BAL,GPIO.OUT)
GPIO.setup(WAT,GPIO.OUT)


for pad in ['Back','A','B','C','D','Enter']:
	touchphat.set_led(pad, True)
	time.sleep(0.1)
	touchphat.set_led(pad, False)
	time.sleep(0.1)

@touchphat.on_touch(['Back','A','B','C','D','Enter'])
def handle_touch(event):
	print(event.name)
	if event.name == 'Back':
		switchgpio(PUL)
	elif event.name == 'A':
		switchgpio(FAN)
	elif event.name == 'B':
		switchgpio(TES)
	elif event.name == 'C':
		switchgpio(TET)
	elif event.name == 'D':
		switchgpio(BAL)
	elif event.name == 'Enter':
		switchgpio(WAT)

def switchgpio(gmode,light):
	if GPIO.input(gmode) == GPIO.HIGH:
		GPIO.output(gmode,GPIO.LOW)
		touchphat.led_on(light)
		#touchphat.set_led(light, True)

	else:
		GPIO.output(gmode,GPIO.HIGH)
		touchphat.led_off(light)
		#touchphat.set_led(light, False)

signal.pause()
GPIO.cleanup()

希望してた、GPIOオンの状態でずっと点灯はできない?みたい。

touchphat.led_onでも、touchphat.set_led(light, True)でも点灯しっぱなしはできなかった。

タッチした時だけ点灯のみ・・・どうやるんだろう?

Warningが出た

/home/pi/script/gpio-touch-phat.py:21: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
/home/pi/script/gpio-touch-phat.py:22: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
/home/pi/script/gpio-touch-phat.py:23: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
/home/pi/script/gpio-touch-phat.py:24: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
/home/pi/script/gpio-touch-phat.py:25: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
/home/pi/script/gpio-touch-phat.py:26: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
Back

gpio-touch-phat.pyの最後の行に以下を追加したらでなくなった。

GPIO.cleanup()

Cronで起動時に起動

最後にcronで再起動時の最後のほう40秒後に起動させるようにした。

$ crontab -e
@reboot sleep 40; /usr/bin/python3 /home/pi/script/gpio-touch-phat.py

Touch PHAT 設置完成

タッチした時のみ↓LEDが光るのが不満な点、GPIOオンのときには点灯しててくれるとよかった。

Scroll pHAT HD

続いて、カラーが全部で7色ほどある17x7LEDのPHAT、電光掲示板のように流れる文字を表示するのに使える。

Pimoroni Scroll pHAT HD for Raspberry Pi

Pimoroni Scroll pHAT HD for Raspberry Pi

4,000円前後

Pimoroniのサイト

Scroll pHAT HD - White
A whole heap of LED pixels with individual brightness control, for scrolling messages, animations, and more - Scroll pHAT HD!

Scroll HAT Miniもある

LEDは一緒だけど、左右に2つずつのボタンがあるのが違う。

Scroll HAT Mini
A 17x7 matrix of bright white LEDs with individual brightness control, and four handy buttons, made for Raspberry Pi. Just the job for scrolling messages, anima...

scroll-phat-hd インストール

ソースはgithubにあります。

GitHub - pimoroni/scroll-phat-hd: Python library for Scroll pHAT HD
Python library for Scroll pHAT HD. Contribute to pimoroni/scroll-phat-hd development by creating an account on GitHub.

ソースごとDLしてサンプルをSCPでアップロードして、python3 clock.pyを実行しても動いた。(時間がおかしいときは raspi-configで日本時刻にする。 )

apt-getでインストールが簡単↓

# cd script
$ sudo apt-get install pimoroni
$ sudo apt-get install python3-scrollphathd

ライブラリを登録

https://github.com/pimoroni/scroll-phat-hdの説明に書いてある。

python3,python2.7の両方にライブラリをインストールした。

cd script
git clone https://github.com/pimoroni/scroll-phat-hd.git
cd scroll-phat-hd/library 
sudo python3 setup.py install
sudo python setup.py install

サンプルの場所

/home/pi/script/scroll-phat-hd/examples

unicode-scrolling.py エラー

フォントがない?エラー

$ python unicode-scrolling.py
Traceback (most recent call last):
  File "unicode-scrolling.py", line 6, in <module>
    from scrollphathd.fonts import font5x7unicode
ImportError: cannot import name font5x7unicode

python3でも同じようなエラー、日本語フォントが無いみたい。

$ python3 unicode-scrolling.py
Traceback (most recent call last):
  File "unicode-scrolling.py", line 8, in <module>
    scrollphathd.set_font(font5x7unicode)
TypeError: set_font() missing 1 required positional argument: 'font'

pimoroni-dashboard

これはGUIの時だけみたい↓未確認

 $ pimoroni-dashboard

--- Warning ---

The Pimoroni Dashboard installer
does not work on this version of Raspbian.
Check https://github.com//
for additional information and support

cpu.py

以下、インストール必要

sudo pip3 install psutil

カウントダウン表示

少し改造して今年あと何日と何時間あるのか、カウントダウンを表示することにした。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#import datetime
from datetime import datetime
from time import sleep

import time
import scrollphathd
from scrollphathd.fonts import font5x5

#カウントダウン
end_day = datetime(year=2020, month=12, day=31, hour=23, minute=59, second=59, microsecond=0)

def get_remaining_time():
	delta = end_day - datetime.now()
	deltayear = '{}'.format(delta.days)
	hours = delta.seconds // 3600
	minutes = (delta.seconds % 3600) // 60
	seconds = delta.seconds % 60
	return deltayear, '{}:{}:{}'.format(hours, minutes, seconds)

def get_text():
	#カウントダウン
	nowyear=get_remaining_time()
	#UNIX time
	unixtime=time.time()
	lines = ["{}days left 2020".format(nowyear[0])
		, "{} after tday".format(nowyear[1])
		#, "UNIX Time {}".format(unixtime)
		]
	return lines


scrollphathd.set_brightness(0.2)
rewind = True
delay = 0.03

while True:
	lines=get_text()

	line_height = scrollphathd.DISPLAY_HEIGHT + 2
	offset_left = 0
	lengths = [0] * len(lines)

	for line, text in enumerate(lines):
		lengths[line] = scrollphathd.write_string(text, x=offset_left, y=line_height * line)
		offset_left += lengths[line]

	scrollphathd.set_pixel(offset_left - 1, (len(lines) * line_height) - 1, 0)
	scrollphathd.scroll_to(1, 0)
	scrollphathd.rotate(180)#上下逆
	scrollphathd.show()

	pos_x = 0
	pos_y = 0

	for current_line, line_length in enumerate(lengths):
		time.sleep(delay * 10)

		for y in range(line_length):
			scrollphathd.scroll(1, 0)
			pos_x += 1
			time.sleep(delay)
			scrollphathd.show()

		if current_line == len(lines) - 1 and rewind:
			for y in range(pos_y):
				scrollphathd.scroll(-int(pos_x / pos_y), -1)
				scrollphathd.show()
				time.sleep(delay)

		else:
			for x in range(line_height):
				scrollphathd.scroll(0, 1)
				pos_y += 1
				scrollphathd.show()
				time.sleep(delay)

	scrollphathd.clear()#コレを入れないと前の数字が重なってしまう

日本語表示

Ticker

GitHub - moguno/scroll_phat_hd-japanese-ticker: Raspberry PiのScroll pHat HDで、日本語のメッセージを流すやつ
Raspberry PiのScroll pHat HDで、日本語のメッセージを流すやつ. Contribute to moguno/scroll_phat_hd-japanese-ticker development by creating an account on GitHub.
$ git clone https://github.com/moguno/scroll_phat_hd-japanese-ticker.git

ticker.pyだけ動いた、他は動かない??

python3 ./misaki.py エラーにもならないで終了してしまう。

Python2で動くみたい。?

$ sudo apt-get install python-scrollphathd
$ sudo pip install psutil

だめpython ticker.pyとやると以下のエラーになる。

  File "ticker.py", line 67
SyntaxError: Non-ASCII character '\xe3' in file ticker.py on line 67, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
 $ python ./misaki.py           Traceback (most recent call last):
  File "./misaki.py", line 33, in <module>
    code_ranges = struct.iter_unpack("HH", fp.read(4 * block_cnt))
AttributeError: 'module' object has no attribute 'iter_unpack'

importの指定と同じファイル名のプログラムがあると、そっちを読みに行ってしまうのが原因?
他の言語と違い、ファイル名=クラス名にできないのめんどい

misakiフォント

今のところうまく動いてない。

8×8 ドット日本語フォント「美咲フォント」
$ cd /home/pi
$ mkdir font/misakifont
$ cd font/misakifont
$ wget https://littlelimit.net/arc/misaki/misaki_ttf_2019-10-19.zip
$ unzip misaki_ttf_2019-10-19.zip

日本語表示未解決

3Dプリンターでカバーを作って電光掲示板として使う

17x7 LEDでドットが少し少ないのであまり多彩な表現はできませんが、時刻やタイマー程度だったら可能で、たまに今年はあと何日あるのか見るのに便利です。(自分のようにボケーっとしていると1年があっという間に過ぎてしまいますので・・・)

3Dプリンターをお持ちの方はこちら↓のデータを使ってプリントしてみてください。

3D design raspi-led-phat | Tinkercad
3D design raspi-led-phat created by Bey.jp with Tinkercad

Inky pHAT

白・黒・赤の3色e-inkのPHATが出ているので試してみました。

特に使用用途もないので、サンプルにあったカレンダーを表示させてみます。

Pimoroni Inky pHAT - 3色 赤 黒 白 e-paper

Pimoroni Inky pHAT – 3色 赤 黒 白 e-paper

7,500円前後

pimoroniサイトとgithub

こちらを参考に

Inky pHAT (ePaper/eInk/EPD) - Red/Black/White
A low-energy, high-falutin, electronic paper (ePaper / eInk / EPD) display for your Pi, in three different colour schemes: red/black/white, yellow/black/white, ...
GitHub - pimoroni/inky: Combined library for V2/V3 Inky pHAT and Inky wHAT.
Combined library for V2/V3 Inky pHAT and Inky wHAT. - GitHub - pimoroni/inky: Combined library for V2/V3 Inky pHAT and Inky wHAT.

インストール

curl https://get.pimoroni.com/inky | bash
sudo pip3 install inky[rpi,fonts]

インストール後 サンプルの場所

cd /home/pi/Pimoroni/inky/examples

Raspi3Bで横表示、サンプルのカレンダーを使う

cd phat
python calendar-phat.py

Cronで毎日実行

毎日1回書き換えてカレンダーを更新させる。

crontab -e
10 0 * * * /usr/bin/python /home/pi/Pimoroni/inky/examples/phat/calendar-phat.py

小さいけどオシャレなカレンダーを表示

Raspberry Pi Zeroサイズ(65x30mm)とかなり小さいのでカレンダーだと顔を近づけないとよく見えないのですが、サンプルのカレンダーは表示がおしゃれにできているのでしばらくこの状態で使います。

海底のタコやヒトデのイラストがおしゃれ♪

PimoroniのRaspberry Pi ZeroサイズのPHAT 7種

画像 Pimoroni Inky pHAT - 3色 赤 黒 白 e-paper 1 Pimoroni Unicorn HAT Mini - ユニコーン ハット ミニ 2 Pimoroni Scroll pHAT HD for Raspberry Pi 3 Pimoroni Four Letter pHAT - 4文字 pHAT for 4 Pimoroni Pico Display Pack for Raspberry 5 Pimoroni OnOff SHIM - パワー オン/オフ for Rasp 6 Explorer pHAT 7 Touch pHAT 8 Unicorn pHAT 9
商品名 Pimoroni Inky pHAT – 3色 赤 黒 白 e-paper Pimoroni Unicorn HAT Mini – ユニコーン ハット ミニ Pimoroni Scroll pHAT HD for Raspberry Pi Pimoroni Four Letter pHAT – 4文字 pHAT for Pimoroni Pico Display Pack for Raspberry Pimoroni OnOff SHIM – パワー オン/オフ for Rasp Explorer pHAT Touch pHAT Unicorn pHAT
特徴 2.13インチ Raspberry Pi Zeroにピッタリ 3色(赤、黒、白)電子ペーパー Raspberry Pi Zeroにピッタリ 17×7(119個)RGB LED Raspberry Pi Zeroにピッタリ 17×7 の 119個の LED Raspberry Pi Zeroにピッタリ 4文字 pHAT Raspberry Pi Zeroにピッタリな18-bit 1.14インチ ディスプレイ Raspberry Pi Zeroより小さめ ラズパイのオン・オフをボタンで操作 Raspberry Pi Zeroにピッタリなよく使うピンをまとめる Raspberry Pi ZeroにピッタリなLEDが光る6タッチボタン Raspberry Pi Zeroにピッタリ 4x8 LED
メーカー Pimoroni Pimoroni Pimoroni Pimoroni Pimoroni Pimoroni Pomoroni Pomoroni Pimoroni
価格 7,500円前後 5,000円前後 4,000円前後 4,000円前後 3,500円前後 2,500円前後 2,000円前後 1,500円前後 1,500円前後

以上、PHAT追加したら追記していきます。

コメント

タイトルとURLをコピーしました