はじめに
この記事は、Qiita では以下の記事を書いている「PlatformIO」関連の話です。今回は、以下の記事で使った VS Code用の拡張機能(PlatformIO for VSCode)ではなく、コマンドで使う「PlatformIO Core (CLI)」を試してみます。
●M5Stack の Tab5 を公式情報をもとに試す【VS Code + PlatformIO + M5Unified】 - Qiita
https://qiita.com/youtoy/items/a3d2fc9191d4c55d7905
●公式の手順を見ながら VS Code + PlatformIO + M5Unified での開発を少し試す(ATOMS3R を使う) - Qiita
https://qiita.com/youtoy/items/6b690fca202fb36c11f0
とりあえずのお試しとして、「PlatformIO Core のセットアップ」と「以前作ったコードの書き込み部分での PlatformIO Core の利用」をやってみます。
早速やってみる
早速、環境の準備から進めていきます。
PlatformIO Core のインストール
PlatformIO Core のインストールは、以下の公式ページに複数の方法が書いてあります。
●Installation Methods — PlatformIO latest documentation
https://docs.platformio.org/en/latest/core/installation/methods/index.html
自分はその中の、Mac用の手順で「curl」を使ったやり方にしました。
●Installer Script (Recommended) — PlatformIO latest documentation
https://docs.platformio.org/en/latest/core/installation/methods/installer-script.html#super-quick-macos-linux
具体的には、以下のコマンドを使うやり方です。
curl -fsSL -o get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
python3 get-platformio.py
上記を実行したところ、以下のようなメッセージが出て、インストールが完了しました。
コマンドの動作確認
インストールされたコマンドをオプション付きで実行して、ヘルプを表示させてみます。まだパスを通していないので、フルパスでコマンドを指定してやってみました。
出力された内容は以下のとおりです。
Usage: pio [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
-c, --caller TEXT Caller ID (service)
--no-ansi Do not print ANSI control characters
-h, --help Show this message and exit.
Commands:
access Manage resource access
account Manage PlatformIO account
boards Board Explorer
check Static Code Analysis
ci Continuous Integration
debug Unified Debugger
device Device manager & Serial/Socket monitor
home GUI to manage PlatformIO
org Manage organizations
pkg Unified Package Manager
project Project Manager
remote Remote Development
run Run project targets (build, upload, clean, etc.)
settings Manage system settings
system Miscellaneous system commands
team Manage organization teams
test Unit Testing
upgrade Upgrade PlatformIO Core to the latest version
パスを通す
次にパスを通しておきます。やり方は、以下の公式情報を見て進めます。
●Install Shell Commands — PlatformIO latest documentation
https://docs.platformio.org/en/latest/core/installation/shell-commands.html#piocore-install-shell-commands
自分の場合、上記ページ内の以下の部分を対応すれば良さそうです。
その対応のうちの 1つは ~/.zprofile
などに export PATH=$PATH:$HOME/.local/bin
を書く、というものがあります。これは、自分の環境では、別のタイミングで .zshrc
にこれに該当する記載があったので、残り 1つの対応だけをすれば良さそうでした。
具体的には、以下の ln -s
によるシンボリックリンク作成です。
ln -s ~/.platformio/penv/bin/platformio ~/.local/bin/platformio
ln -s ~/.platformio/penv/bin/pio ~/.local/bin/pio
ln -s ~/.platformio/penv/bin/piodebuggdb ~/.local/bin/piodebuggdb
上記の対応後は、コマンドをフルパスにしなくてもよくなりました。以下は pio -h
や pio --version
、 platformio --version
の実行を試した結果の画像で、無事、想定通りの動作になりました。
PlatformIO Core を使った書き込み
下準備はできたので、あとは PlatformIO Core を使った書き込みをやってみます。具体的には、以下のコンテスト応募作品で使った M5Stack Core2用のコードを流用して、書き込みの部分のみを PlatformIO Core でやってみます。
※ コードと platformio.ini が既に用意できている状態からの作業になります
●M5 GraviTimer - Hackster.io
https://www.hackster.io/youtoy/m5-gravitimer-942c64
具体的な手順・コマンド
まずは、M5Stack Core2 を USB で接続した状態で以下のコマンドを実行して、M5Stack Core2 に関する情報が表示されるかを確認します。
pio device list
出力結果は以下のとおりで、M5Stack Core2 に関する情報が出てきました。
あとは、以下のコマンドを実行するだけです。
pio run -t upload
この後、PlatformIO Core を使った上記のコマンドで、M5Stack Core2 への書き込みを完了させられました。