NeoFlashをCircuitPythonで動かす
2020/5/28
CircuitPython NeoFlash
CircuitPython NeoFlash
概要
以下のNeoFlashをCircuitPythonで動かす。 ここでは、Feather-M4-ExpressのCircuitPythonを使用する。なお、NeoFlashは、M5StickC用であるが、neopixel互換なので neopixelとして動かす。 (以下、ホストPCとしてはubuntuを想定している)
## 接続 以下のように接続する:
NeoFlash | FeartherM4 |
---|---|
GND | GND |
5V0 | 3.3V |
G26 | D4 |
本来、5V動作のようだが、3.3Vでも動作する。
デモ・スクリプト
import time
import board
import neopixel
# On CircuitPlayground Express, and boards with built in status NeoPixel -> board.NEOPIXEL
# Otherwise choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D1
#pixel_pin = board.NEOPIXEL
pixel_pin = board.D4
# The number of NeoPixels
num_pixels = 126
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB
pixels = neopixel.NeoPixel(
pixel_pin, num_pixels, brightness=0.2, auto_write=False, pixel_order=ORDER
)
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
r = g = b = 0
elif pos < 85:
r = int(pos * 3)
g = int(255 - pos * 3)
b = 0
elif pos < 170:
pos -= 85
r = int(255 - pos * 3)
g = 0
b = int(pos * 3)
else:
pos -= 170
r = 0
g = int(pos * 3)
b = int(255 - pos * 3)
return (r, g, b) if ORDER in (neopixel.RGB, neopixel.GRB) else (r, g, b, 0)
def rainbow_cycle(wait):
for j in range(255):
for i in range(num_pixels):
pixel_index = (i * 256 // num_pixels) + j
pixels[i] = wheel(pixel_index & 255)
pixels.show()
time.sleep(wait)
while True:
# Comment this line out if you have RGBW/GRBW NeoPixels
pixels.fill((255, 0, 0))
# Uncomment this line if you have RGBW/GRBW NeoPixels
# pixels.fill((255, 0, 0, 0))
pixels.show()
time.sleep(1)
# Comment this line out if you have RGBW/GRBW NeoPixels
pixels.fill((0, 255, 0))
# Uncomment this line if you have RGBW/GRBW NeoPixels
# pixels.fill((0, 255, 0, 0))
pixels.show()
time.sleep(1)
# Comment this line out if you have RGBW/GRBW NeoPixels
pixels.fill((0, 0, 255))
# Uncomment this line if you have RGBW/GRBW NeoPixels
# pixels.fill((0, 0, 255, 0))
pixels.show()
time.sleep(1)
rainbow_cycle(0.001) # rainbow cycle with 1ms delay per step
circuitpythonの標準的なサンプルプログラムの出力ポートとneopixelの数をNeoFlashに合わせて変更したもの.
表示した印象では、添付のアクリル板を付けないと眩しすぎるで、取り付けたほうが良いと思う。
参照情報
Adafruit Feather M4 Express PINOUTS
Adafruit Feather M4 Express Overview
Adafruit-Feather-M4-ExpressにCircuitPythonをインストールする
Build CircuitPython
Adding Frozen Modules
Adafruit CircuitPython API Reference(v5.x)
CircuitPython Essentials
Example Code
以上
| 固定リンク
「linux」カテゴリの記事
- platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法(2021.03.10)
- micro:bit Yotta開発ツール(linux版)(2021.01.09)
- PlatformIOをRaspberryPi4で動かしてみる(実験)(2020.10.20)
- headless RaspberryPiインストール方法(v2)(2020.10.20)
- wio-terminalのファームウェア・アップデートについて(linux版)(2020.10.15)
「CircuitPython」カテゴリの記事
- MicroPython/CircuitPython Performance Test(2021.02.07)
- PicoボードにMicropython/CircuitPythonをインストールする(2021.02.03)
- XIAOでMPL3115A2(気圧・高度・気温センサ)を使用する(CircuitPython版)(2020.07.02)
- XIAOでMCP9808(温度センサ)を使用する(CircuitPython版)(2020.07.02)
- XIAOにCircuitPythonをインストールする(2020.06.09)
コメント