Circuit-Playground-ExpressにCircuitPythonをインストールする
2020/5/22+
Circuit-Playground-Express CircuitPython Install
Circuit-Playground-Express CircuitPython Install
概要
Circuit-Playground-ExpressにCircuitPythonをインストールする方法について記載する。 以下、Circuit-Playground-ExpressをCPXとする。 (ホストPCとしてはubuntuを想定している)
事前準備
(1)picocomのインストール
sudo apt-get install picocom
bootloader mode
CPXにfirmwareを書き込めるモードを「bootloader mode」といい、このモードでは、USBストレージとしてCPLAYBOOTが現れる。 CPXに事前に、どんなプログラムが書かれていたかで、やり方が異なる。 arduinoのプログラムかCircuitPythonのプログラムが書き込まれている場合、resetをdouble-clickのように2度押すと このモードに入りUSBストレージとしてCPLAYBOOTが現れる。その他の場合、resetを1度押すと、このモードに入る。
ただし、本家サイトの説明ではdouble-clickのようにと説明があるが 実際には、2度目のリセットは少し長めに押してから離さないとbootloader-modeには入らない。 失敗するとボード上のneopixelが緑ではなく赤になる。
工場出荷の状態では、arduinoのデモプログラムが入っているようなので 実際にはresetの2度押しで、このモードに入る。
bootloader update
以下の手順でbootloaderをアップデートする:
# download
wget https://github.com/adafruit/uf2-samdx1/releases/download/v3.10.0/update-bootloader-circuitplay_m0-v3.10.0.uf2
# CPXをホストPCにUSB接続して、リセットを2度押して、bootloader-modeに入る。
# このモードに入ると、CPLAYBOOTのディレクトリが現れる。
# ファイルをドラッグ&ドロップするか、以下のコマンドを実行してファイルをコピーする
cp update-bootloader-circuitplay_m0-v3.10.0.uf2 /media/USER_NAME/CPLAYBOOT/
# ファームウェアの書き込みが実行されて、完了後、CPLAYBOOTが現れるまで待つ
「USER_NAME」は実際の環境に合わせること。
CircuitPythonの書き込み
以下の手順でCircuitPythonを書き込む:
wget https://downloads.circuitpython.org/bin/circuitplayground_express/en_US/adafruit-circuitpython-circuitplayground_express-en_US-5.3.0.uf2
# ファイルをドラッグ&ドロップするか、以下のコマンドを実行してファイルをコピーする
cp adafruit-circuitpython-circuitplayground_express-en_US-5.3.0.uf2 /media/USER_NAME/CPLAYBOOT/
# ファームウェアの書き込みが実行されて、完了後、CIRCUITPYが現れるまで待つ
「USER_NAME」は実際の環境に合わせること。
動作確認(REPL)
以上、CircuitPythonのインストールが終わったので、picocomを使いCPXとシリアルで通信する。(REPL)
以下、通信(REPL)例:
$ picocom /dev/ttyACM0 -b115200
Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit CircuitPlayground Express with samd21g18
>>> import os
>>> os.uname()
(sysname='samd21', nodename='samd21', release='5.3.0', version='5.3.0 on 2020-04-29', machine='Adafruit CircuitPlayground Express with samd21g18')
>>>
>>> import gc
>>> gc.collect()
>>> gc.mem_free()
20816
>>>
>>> list(5 * x + y for x in range(10) for y in [4, 2, 1])
[4, 2, 1, 9, 7, 6, 14, 12, 11, 19, 17, 16, 24, 22, 21, 29, 27, 26, 34, 32, 31, 39, 37, 36, 44, 42, 41, 49, 47, 46]
>>>
>>>
>>> help('modules')
__main__ adafruit_hid/gamepad builtins random
_os adafruit_hid/keyboard busio re
_pixelbuf adafruit_hid/keyboard_layout_us collections rotaryio
_time adafruit_hid/keycode digitalio rtc
adafruit_bus_device/__init__ adafruit_hid/mouse errno storage
adafruit_bus_device/i2c_device adafruit_lis3dh gamepad struct
adafruit_bus_device/spi_device adafruit_thermistor gc supervisor
adafruit_circuitplayground/__init__ analogio math sys
adafruit_circuitplayground/bluefruit array microcontroller time
adafruit_circuitplayground/circuit_playground_base audiobusio micropython touchio
adafruit_circuitplayground/express audiocore neopixel usb_hid
adafruit_hid/__init__ audioio neopixel_write usb_midi
adafruit_hid/consumer_control bitbangio os
adafruit_hid/consumer_control_code board pulseio
Plus any modul
>>>
mpy library install
以下の手順でmpyライブラリをインストールする:
wget https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/download/20200522/adafruit-circuitpython-bundle-5.x-mpy-20200522.zip
unzip adafruit-circuitpython-bundle-5.x-mpy-20200522.zip
cd adafruit-circuitpython-bundle-5.x-mpy-20200522
# ドラッグ&ドロップか、以下を実行して、libの内容をCIRCUITPY/libにコピーする
cp -r lib /media/USER_NAME/CIRCUITCPY/lib
# 実際に使用するライブラリだけが必要になるが、容量に余裕があるので、全部コピーする
# 将来、容量が不足した不要なライブラリを削除すること
「USER_NAME」は実際の環境に合わせること。
sample#1(neopixelデモ)
以下にあるサンプルを動かしてみる:
CircuitPython NeoPixel
以下の手順でサンプルをダウンロードとする:
# dewnload example
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Introducing_CircuitPlaygroundExpress/CircuitPlaygroundExpress_NeoPixel.py
cp CircuitPlaygroundExpress_NeoPixel.py CIRCUITPY/
# resetで自動起動させる場合は以下を実行する:
cp CircuitPlaygroundExpress_NeoPixel.py CIRCUITPY/code.py
「CIRCUITPY」は「/media/USER_NAME/CIRCUITPY/」に読み換えること。
実行すると、ボード上のneopixelが色を変えて光る。
sample#2(ドラムマシン)
以下にあるプログラムを実行してみる:
Playground Drum Machine
以下の手順でサンプルをダウンロードとする:
# プログラムで使用するwavファイルをダウンロードする
mkdir wav
cd wav
wget https://cdn-learn.adafruit.com/assets/assets/000/047/298/original/drumSamples.zip
unzip drumSamples.zip
cp *.wav CIRCUITPY/
# dewnload example
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Introducing_CircuitPlaygroundExpress/CircuitPlaygroundExpress_808_Drum_Machine.py
cp CircuitPlaygroundExpress_808_Drum_Machine.py CIRCUITPY/
# resetで自動起動させる場合は以下を実行する:
cp CircuitPlaygroundExpress_808_Drum_Machine.py CIRCUITPY/code.py
「CIRCUITPY」は「/media/USER_NAME/CIRCUITPY/」に読み換えること。
実行すると、ボード上のワニ口用パッドを触るとドラム音が出る。(サイトの説明では、ワニ口クリップとコインでタッチパッドを作っているが、そのまま触っても音が鳴る)
Performance Test
performanceCircuitPython.py
# Peformace Test for CircuitPython
from time import monotonic_ns
def performanceTest():
endTime = monotonic_ns() + 10000000000 # 10 sec
count = 0
while monotonic_ns() < endTime:
count += 1
print("Count: ", count)
performanceTest()
実行すると以下のような結果が得られる:
Count: 121800
参照URL
Adafruit Circuit Playground Express - PINOUT
Adafruit Circuit Playground Express - Overview
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)
「Circuit-Playground-Express」カテゴリの記事
- Circuit-Playground-ExpressボードでTinyGOを動かす(v2)(2020.05.29)
- プログラミング言語RustをCircuit-Playground-Expressで動かす(2020.05.28)
- Nucleo-F103RBボードでTinyGOを動かす(v2)(2020.05.26)
- 開発ツールPlatformIOをCircuit-Playground-Expressで使う(arduino版)(2020.05.25)
- Circuit-Playground-ExpressにCircuitPythonをインストールする(2020.05.23)
この記事へのコメントは終了しました。
コメント