PyPortalにCircuitPythonをインストールする
2020/5/24
PyPortal CircuitPython Install
PyPortal CircuitPython Install
概要
以下のPyPortalにCircuitPythonをインストールする方法について記載する。
工場出荷時に既にCircuitPythonがインストール済みなので
正確に言えば最新版にアップデートすることになる。
(ホストPCとしてはubuntuを想定している)
Adafruit PyPortal - CircuitPython IoTディスプレイ
事前準備
(1)picocomのインストール
sudo apt-get install picocom
bootloader mode
PyPortalにfirmwareを書き込めるモードを「bootloader mode」といい、このモードでは、USBストレージとしてPORTALBOOTが現れる。 PyPortalに事前に、どんなプログラムが書かれていたかで、やり方が異なる。 arduinoのプログラムかCircuitPythonのプログラムが書き込まれている場合、resetをdouble-clickのように2度押すと このモードに入りUSBストレージとしてPORTALBOOTが現れる。その他の場合、resetを1度押すと、このモードに入る。
工場出荷の状態では、CircuitPythonが入っているので 実際にはresetの2度押しで、このモードに入る。
bootloader update
以下の手順でbootloaderをアップデートする:
# download
wget https://github.com/adafruit/uf2-samdx1/releases/download/v3.10.0/update-bootloader-pyportal_m4-v3.10.0.uf2
# PyPortalをホストPCにUSB接続して、リセットを2度押して、bootloader-modeに入る。
# このモードに入ると、PORTALBOOTのディレクトリが現れる。
# ファイルをドラッグ&ドロップするか、以下のコマンドを実行してファイルをコピーする
cp update-bootloader-pyportal_m4-v3.10.0.uf2 /media/USER_NAME/PORTALBOOT/
# ファームウェアの書き込みが実行されて、完了後、PORTALBOOTが現れるまで待つ
「USER_NAME」は実際の環境に合わせること。
CircuitPythonの書き込み
以下の手順でCircuitPythonを書き込む:
wget https://downloads.circuitpython.org/bin/pyportal/en_US/adafruit-circuitpython-pyportal-en_US-5.3.0.uf2
# ファイルをドラッグ&ドロップするか、以下のコマンドを実行してファイルをコピーする
cp adafruit-circuitpython-pyportal-en_US-5.3.0.uf2 /media/USER_NAME/PORTALBOOT/
# ファームウェアの書き込みが実行されて、完了後、CIRCUITPYが現れるまで待つ
「USER_NAME」は実際の環境に合わせること。
書き込んであるサンプルコードを最新版にアップデートする
以下の手順でアップデートする:
wget https://cdn-learn.adafruit.com/assets/assets/000/090/931/original/PyPortal_5x_demo_files.zip
unzip PyPortal_5x_demo_files.zip
cd boards/pyportal/5.x
nano secrets.py
#以下の内容を自分のネットワーク環境に合わせて変更する。
# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it
# which would be not great. So, instead, keep it all in this one file and
# keep it a secret.
secrets = {
'ssid' : 'CHANGE ME', # Keep the two '' quotes around the name
'password' : 'CHANGE ME', # Keep the two '' quotes around password
'timezone' : "America/New_York", # http://worldtimeapi.org/timezones
'aio_username' : 'YOUR_ADAFRUIT_ACCOUNT_USERNAME',
'aio_key' : 'YOUR_ADAFRUITIO_KEY',
}
変更箇所:
'CHANGE ME'は、それぞれ自分の環境のssid,passwordに置き換える。
timezoneの設定は以下のように変更する:
"America/New_York" → "Asia/Tokyo"
続き:
# CIRCUITPYの内容を全削除する
rm -r /media/USER_NAME/CIRCUITCPY/*.*
# 内容全部をコピーする
cd boards/pyportal/5.x
cp -r *.* /media/USER_NAME/CIRCUITCPY/
全コピーが上手く行かない場合、
全削除した段階で再起動する(リセットする)
再起動後、全コピーする。
全コピーが終わって再起動した段階で
デモプログラムが起動する。
動作としては、ネットワークにアクセスに行って
LCDに偉人の名言(英語)が、つぎつぎとLCDに表示される。
REPL
以上で、CircuitPythonの最新版のアップデートが終わったことになる。
次にpicocomを使ってREPLに入る。
以下、通信(REPL)例:
$ picocom /dev/ttyACM0 -b115200
#デモプログラムを実行中なので
#REPLに入るためにControl-Cを押す。
Traceback (most recent call last):
File "code.py", line 35, in <module>
KeyboardInterrupt:
Code done running. Waiting for reload.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
Press any key to enter the REPL. Use CTRL-D to reload.
#ここでEnterを押す。
Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit PyPortal with samd51j20
>>>
>>>
>>> import os
>>> os.uname()
(sysname='samd51', nodename='samd51', release='5.3.0', version='5.3.0 on 2020-04-29', machine='Adafruit PyPortal with samd51j20')
>>>
>>> import gc
>>> gc.collect()
>>> gc.mem_free()
221056
>>>
>>> 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
>>>
#Control-Dを押すとデモプログラムが再起動する。
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」は実際の環境に合わせること。
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: 474734
参照URL
PyPortal PINOUT
PyPortal Overview
Build the PyPortal Stand
Updating ESP32 Firmware
Uploading nina-fw with esptool
Build CircuitPython
Adding Frozen Modules
Adafruit CircuitPython API Reference(v5.x)
CircuitPython Essentials
Example Code
Cleveland Museum of Art PyPortal Frame
PyPortal IoT Weather Station
以上
| 固定リンク
« Circuit-Playground-ExpressにCircuitPythonをインストールする | トップページ | GRAND-CENTRAL-M4-EXPRESSにCircuitPythonをインストールする »
「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)
コメント