Adafruit 32x16 RGB LED MatrixをRaspberry Piで動かしてみる

Last updated on

引き続き、LED Matrixの制御についてです。

最初は、Adafruit公式のtutorialを参考にしようと思ったのですが、
tutorial内で使うライブラリがアップデートされていたので、ライブラリのReadmeを参考にしました。

1.Raspberry PiとLED Matrixの接続

接続図を参考に。
rpi-rgb-led-matrix/wiring.md at master · hzeller/rpi-rgb-led-matrix

結構うってなる説明文ですが、32x16の1台だけだったら😄の部分だけを接続すればOKです。

あと、電源はRaspberry Piとは別に5V2A程度のACアダプタに接続します。

2.Raspberry Piにライブラリをインストール

適当にディレクトリを作る

1
2
$ mkdir display16x32
$ cd display16x32

ライブラリのリポジトリをclone & compile
(LED Matrixのバージョンによっては、makefileの設定は必要みたい。とりあえず、大丈夫でした。:readme.md参照)

1
2
3
$ git clone https://github.com/hzeller/rpi-rgb-led-matrix/
$ cd rpi-rgb-led-matrix
$ make

3.サンプルを動かしてみる

サンプルプログラムのcompile

1
2
$ cd examples-api-use
$ make

サンプルプログラムのoptionを確認

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$ sudo ./demo
Expected required option -D <demo>
usage: ./demo <options> -D <demo-nr> [optional parameter]
Options:
-D <demo-nr> : Always needs to be set
-L : Large display, in which each chain is 'folded down'
in the middle in an U-arrangement to get more vertical space.
-R <rotation> : Sets the rotation of matrix. Allowed: 0, 90, 180, 270. Default: 0.
-t <seconds> : Run for these number of seconds, then exit.
--led-gpio-mapping=<name> : Name of GPIO mapping used. Default "regular"
--led-rows=<rows> : Panel rows. 8, 16, 32 or 64. (Default: 32).
--led-chain=<chained> : Number of daisy-chained panels. (Default: 1).
--led-parallel=<parallel> : For A/B+ models or RPi2,3b: parallel chains. range=1..3 (Default: 1).
--led-pwm-bits=<1..11> : PWM bits (Default: 11).
--led-brightness=<percent>: Brightness in percent (Default: 100).
--led-scan-mode=<0..1> : 0 = progressive; 1 = interlaced (Default: 0).
--led-show-refresh : Show refresh rate.
--led-inverse : Switch if your matrix has inverse colors on.
--led-rgb-sequence : Switch if your matrix has led colors swapped (Default: "RGB")
--led-pwm-lsb-nanoseconds : PWM Nanoseconds for LSB (Default: 130)
--led-no-hardware-pulse : Don't use hardware pin-pulse generation.
--led-slowdown-gpio=<0..2>: Slowdown GPIO. Needed for faster Pis and/or slower panels (Default: 1).
--led-daemon : Make the process run in the background as daemon.
--led-no-drop-privs : Don't drop privileges from 'root' after initializing the hardware.
Demos, choosen with -D
0 - some rotating square
1 - forward scrolling an image (-m <scroll-ms>)
2 - backward scrolling an image (-m <scroll-ms>)
3 - test image: a square
4 - Pulsing color
5 - Grayscale Block
6 - Abelian sandpile model (-m <time-step-ms>)
7 - Conway's game of life (-m <time-step-ms>)
8 - Langton's ant (-m <time-step-ms>)
9 - Volume bars (-m <time-step-ms>)
10 - Evolution of color (-m <time-step-ms>)
11 - Brightness pulse generator
Example:
./demo -t 10 -D 1 runtext.ppm
Scrolls the runtext for 10 seconds

32x16だと、--led-rows=16の指定が必要とのこと。
まずは0番(some rotating square)のサンプルプログラムを実行してみる。

1
$ sudo ./demo -D 0 --led-rows=16

動いたー。

attention
(demo:0の写真じゃないけど)

使用した機材
  • Raspberry Pi 2 Model B
  • Adafruit 32x16 RGB LED Matrix
  • 5V2A ACアダプタ
  • ジャンパワイヤ(オス〜メス) いっぱい
追記

Raspberry Piの設定によっては、サンプルプログラムを動かした時に、サウンドボードのエラーが出る場合がありました。
このライブラリとRaspberry Pi内蔵のサウンドボードが共存できないらしい。

サウンドボードをOFFにするには、

1
$ sudo nano /boot/config.txt

でRaspberry Piのconfigを開いて、

1
2
#dtparam=audio=on // <-元から書いてあるものをコメントアウト
dtparam=audio=off // <-この行を追加

して保存、再起動してください。

これでデモが動くようになるはず。

オーディオデバイスを使いたい場合は、別にUSBサウンドボードを使えば良いみたいです。