« GRAND-CENTRAL-M4-EXPRESSにCircuitPythonをインストールする | トップページ | 開発ツールPlatformIOをCircuit-Playground-Expressで使う(arduino版) »

2020年5月24日 (日)

Adafruit-Feather-M4-ExpressにCircuitPythonをインストールする

2020/5/24

Adafruit Feather M4 Express CircuitPython Install

Adafruit Feather M4 Express CircuitPython Installl

概要

以下のAdafruit-Feather-M4-ExpressにCircuitPythonをインストールする方法について記載する。
以降、Adafruit-Feather-M4-ExpressをFeatherM4とする。
(以下、ホストPCとしてはubuntuを想定している)

Adafruit Feather M4 Express

事前準備

(1)picocomのインストール

sudo apt-get install picocom

bootloader mode

FeatherM4にfirmwareを書き込めるモードを「bootloader mode」といい、このモードでは、USBストレージとしてFEATHERBOOTが現れる。 GCM4に事前に、どんなプログラムが書かれていたかで、やり方が異なる。 arduinoのプログラムかCircuitPythonのプログラムが書き込まれている場合、resetをdouble-clickのように2度押すと このモードに入りUSBストレージとしてFEATHERBOOTが現れる。その他の場合、resetを1度押すと、このモードに入る。

bootloader update

以下の手順でbootloaderをアップデートする:

# download wget https://github.com/adafruit/uf2-samdx1/releases/download/v3.10.0/update-bootloader-feather_m4-v3.10.0.uf2 # FeatherM4をホストPCにUSB接続して、リセットを2度押して、bootloader-modeに入る。 # このモードに入ると、FEATHERBOOTのディレクトリが現れる。 # ファイルをドラッグ&ドロップするか、以下のコマンドを実行してファイルをコピーする cp update-bootloader-feather_m4-v3.10.0.uf2 /media/USER_NAME/FEATHERBOOT/ # ファームウェアの書き込みが実行されて、完了後、FEATHERBOOTが現れるまで待つ

「USER_NAME」は実際の環境に合わせること。

CircuitPythonの書き込み

以下の手順でCircuitPythonを書き込む:

wget https://downloads.circuitpython.org/bin/feather_m4_express/en_US/adafruit-circuitpython-feather_m4_express-en_US-5.3.0.uf2 # ファイルをドラッグ&ドロップするか、以下のコマンドを実行してファイルをコピーする cp adafruit-circuitpython-feather_m4_express-en_US-5.3.0.uf2 /media/USER_NAME/FEATHERBOOT/ # ファームウェアの書き込みが実行されて、完了後、CIRCUITPYが現れるまで待つ

「USER_NAME」は実際の環境に合わせること。

REPL

次にpicocomを使ってREPLに入る。

以下、通信(REPL)例:

$ picocom /dev/ttyACM0 -b115200 Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit Feather M4 Express with samd51j19 >>> import os >>> os.uname() (sysname='samd51', nodename='samd51', release='5.3.0', version='5.3.0 on 2020-04-29', machine='Adafruit Feather M4 Express with samd51j19') >>> >>> import gc >>> gc.collect() >>> gc.mem_free() 158976 >>> >>> help('modules') __main__ busio microcontroller storage _os collections micropython struct _pixelbuf digitalio neopixel_write supervisor _time displayio network sys analogio errno os terminalio array fontio ps2io time audiobusio framebufferio pulseio touchio audiocore frequencyio random ulab audioio gamepad re usb_hid audiomixer gc rgbmatrix usb_midi audiomp3 i2cslave rotaryio wiznet bitbangio io rtc board json samd builtins math socket Plus any modules on the filesystem >>>

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」は実際の環境に合わせること。

サンプル・プログラム

neopixel_test.py

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 = 64 # 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

neopixelのDINをD4に接続して「import neopixel_test」でプログラムを実行するとneopixelが色々な色で光る。
また、プログラムを以下のように変更するとボード上のneopixelが色を変えて光る。

pixel_pin = board.NEOPIXEL ... num_pixels = 1

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: 438444

参照URL

Adafruit Feather M4 Express PINOUTS
Adafruit Feather M4 Express Overview

Build CircuitPython
Adding Frozen Modules

Adafruit CircuitPython API Reference(v5.x)

CircuitPython Essentials
Example Code

以上

|

« GRAND-CENTRAL-M4-EXPRESSにCircuitPythonをインストールする | トップページ | 開発ツールPlatformIOをCircuit-Playground-Expressで使う(arduino版) »

linux」カテゴリの記事

CircuitPython」カテゴリの記事

コメント

コメントを書く



(ウェブ上には掲載しません)




« GRAND-CENTRAL-M4-EXPRESSにCircuitPythonをインストールする | トップページ | 開発ツールPlatformIOをCircuit-Playground-Expressで使う(arduino版) »