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?

i2cでWS2812

0
Last updated at Posted at 2026-11-28

去年はWS2812をFT232HのBitbangで光らせたのですが、たかだか7つのLEDに虎の子のFT232Hを使うのはもったいないので、他の方法を考えてみました。

シングルワイヤーのサポートを使うとかSPIを変則的に使う方法があるようですが、あまりピンときません。

たまたまI2Cをいじっていたので、I2Cでコントロールする方法を調べてみました。

githubにattiny85のコードがありましたが、コンパイルできないので諦めました。

シングルワイヤーなのでできるだけ足の少ないチップを使いたいです。

それでLPC810を引っ張り出してきました。

googleさんがコードを教えてくれたのですが、いろいろ問題があります。これはNXPがいろいろなサポートを用意した結果、混乱しているようにも思えます。

いろいろ試行錯誤してとりあえず動くようになりました。

WS2812BのVCCは5Vを別に入れて、LPC810からのシングルワイヤーは3.3Vの信号になります。

IMG_20261129_072550.jpg

信号のタイミングはオシロで確認して調整しました。

mrubyで点灯してみます。

t = BsdIic.new(0)

arr = [0x80, 0x00, 0x00] * 7

t.write(0x40, arr)

sleep 5

arr = [0x00, 0x80, 0x00] * 7

t.write(0x40, arr)

sleep 5

arr = [0x00, 0x00, 0x80] * 7

t.write(0x40, arr)

sleep 5

arr = [0x00, 0x00, 0x00] * 7

t.write(0x40, arr)

LPC810は謎な動きをして結構やばいです。

去年の回るコードをちょっといじって動かしてみました。

t = BsdIic.new(0)

n =  0
arr = [0x40, 0x00, 0x00]

loop do
  pat = [0x00] * 3 * n
  pat += arr
  pat += [0x00] * 3 * (6 - n)
  t.write(0x40, pat)
  n += 1
  if n == 6
    n = 0
    arr.rotate!
  end
  usleep 100_000
end

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?