« NUCLEO-F767ZIにMicropythonをインストールする(v2) | トップページ | PyPortalにCircuitPythonをインストールする »

2020年5月23日 (土)

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

Circuit Playground Express

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

以上

|

« NUCLEO-F767ZIにMicropythonをインストールする(v2) | トップページ | PyPortalにCircuitPythonをインストールする »

linux」カテゴリの記事

CircuitPython」カテゴリの記事

Circuit-Playground-Express」カテゴリの記事

コメント

この記事へのコメントは終了しました。