MicroPython + Jupyter 環境利用の基礎知識
ファームウェアの ESP32 マイコンへの書き込み
ESP32 マイコンの教育ボードを PC に接続する. デバイス名は /dev/ttyUSB0 とする.
MicroPython のファームウェアの書き込み
MicroPython でプログラミングする場合は, 以下の図のような処理の流れになる. このような処理を行う上での大前提は, あらかじめマイコン上に 仮想マシン (VM) をインストールすることである.

実習用 Linux には, ~/micropython 以下にファームウェア (≒ VM) が置かれている. micropython で ESP32 マイコンのプログラミングする場合には, 最初にそれを ESP32 内蔵のフラッシュメモリに書き込む必要がある. なお, ファームウェアは<URL:https://micropython.org>の「Download」よりダウンロードできる.
内蔵のフラッシュメモリのクリア
$ cd ~/micropython $ esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash
内蔵のフラッシュメモリへのファームウェアの書き込み
$ cd ~/micropython $ esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-idf3-20191220-v1.12.bin
MicroPython のリファレンス
<URL:http://docs.micropython.org/en/latest/esp32/quickref.html>
<URL:https://micropython-docs-ja.readthedocs.io/ja/latest/esp32/quickref.html>
Jupyter でノートの作成
ターミナルより jupyter notebook を起動する.
$ cd ~/micropython $ jupyter notebook
- ブラウザが自動的に立ち上がる. ブラウザ右上の New をクリックし, 「MicroPython - USB」を選択する.

- なお, セルに入力したプログラムが実行中のときは, セルの左側の [] 内が * になっている. 実行が終わると [] 内には番号 (実行したプログラムの通し番号) が入る.

- プログラムを最初から作り直した時やプログラムの実行がおかしい時などは, メニューの kernel から restart すべき.

- 文法ミスなどした場合には, 赤背景で表示される.

初めの一歩: Hello World
最初のセルで以下を入力. 上段の Run ボタンを押すか, シフトキーとエンターを一緒に押すと, 入力した内容が実行される.戻り値が表示されるので, エラーが発生していないことを確認すること.
%serialconnect to --port=/dev/ttyUSB0 --baud=115200
セルに hello world を表示するプログラムを入力し, 上段の Run ボタンを押すか, シフトキーとエンターを一緒に押す.
print('Hello World')
