0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RaspberryPi で WS281X LEDストリップをマルチチャンネル駆動する

Last updated at Posted at 2023-04-23

「Raspberry Pi 16-channel WS2812 NeoPixel LED driver – Lean」
https://iosoft.blog/2020/09/29/raspberry-pi-multi-channel-ws2812/

で、最大16チャンネルの WS281X LEDストリップを駆動する方法が記されている。

コード:https://github.com/jbentham/rpi

これは、 RaspberryPi の セカンダリメモリインターフェイス (SMI) を使って正確な信号を生成するもの。
SMI は 18ch 使えるらしいが、記事で紹介されているのは 8ch ないし 16ch 。 SMI バス信号は SD0〜SD17となっていて、GPIO 8~25 に割り当てられている。

今回はこの記事を元に GPIO8〜15 を使って 8ch を制御してみた。
試してみたらちょっとコツが必要だったので記事化。

環境

  • Raspberry Pi 3
  • Raspberry Pi OS Lite
  • Release date: February 21st 2023
  • System: 32-bit

ダウンロード

$ git clone https://github.com/jbentham/rpi_multichannel_ws281x.git

編集

Raspberry Pi 3 にあわせて rpi_dma_utils.h を編集

// Location of peripheral registers in physical memory
#define PHYS_REG_BASE   PI_01_REG_BASE
#define PI_01_REG_BASE  0x20000000  // Pi Zero or 1
#define PI_23_REG_BASE  0x3F000000  // Pi 2 or 3
#define PI_4_REG_BASE   0xFE000000  // Pi 4

//#define CLOCK_HZ      250000000   // Pi 2 - 4
#define CLOCK_HZ        400000000   // Pi Zero


// Location of peripheral registers in physical memory
#define PHYS_REG_BASE   PI_23_REG_BASE
#define PI_01_REG_BASE  0x20000000  // Pi Zero or 1
#define PI_23_REG_BASE  0x3F000000  // Pi 2 or 3
#define PI_4_REG_BASE   0xFE000000  // Pi 4

#define CLOCK_HZ      250000000   // Pi 2 - 4
//#define CLOCK_HZ        400000000   // Pi Zero


コンパイル

$ gcc -Wall -z muldefs -o rpi_pixleds rpi_pixleds.c rpi_dma_utils.c

実行

3つのチャンネルの1つのLEDをそれぞれ指定色で光らせます。

$ sudo ./rpi_pixleds 7f0000 007f00 00007f
VC mem handle 2, phys 0xfebf8000, virt 0x76fb2000
Setting 1 LED per channel, 8 channels
Closing

image.png

チャンネルごとに5つのLEDをテストパターンで光らせます。

$ sudo ./rpi_pixleds -n 5 -t
VC mem handle 2, phys 0xfebf8000, virt 0x76f0f000
Testing 5 LEDs per channel, 8 channels

アレンジ

フォークして新しいレポジトリを作ってみました。
https://github.com/nanbuwks/rpi_multichannel_ws281x

rpi_8chwave というコマンドで、8ch を波のように光らせることができます。

 $ sudo ./rpi_8chwave -n 100 -w 100 -B 10 FF0000 00FF00 0000FF FFFF00 00FFFF FF00FF 808080 FFFFFF 

image.png

それぞれのチャンネルごとに、RGB色コードを指定します。消灯の場合は色コード 00000 を与えます。

その他、主なオプションは以下の通りです。

  • -W ウェイトを指定することで、速度を調整できます。
  • -B 0~100% の明るさ
  • -n 1チャンネルでのLED数
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?