公式Arduinoコマンドラインインターフェース版が公開

144Labの入江田です。

つい先日、公式のArduinoコマンドラインインターフェース版が公開されました!

アナウンスページ: https://blog.arduino.cc/2018/08/24/announcing-the-arduino-command-line-interface-cli/

ソースコード: https://github.com/arduino/arduino-cli

Go言語開発環境があれば、

$ go get github.com/arduino/arduino-cli

これだけでArduinoの基本セットアップ完了。

以下のコマンドでインデックスを更新。

$ arduino-cli core update-index

例えばJSONに関連するライブラリを探す・・・。

$ arduino-cli lib search json
Name: "ArduinoJson"
  Author:  Benoit Blanchon <blog.benoitblanchon.fr>
  Maintainer:  Benoit Blanchon <blog.benoitblanchon.fr>
  Sentence:  An efficient and elegant JSON library for Arduino.
  Paragraph:  ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation.
  Website:  https://arduinojson.org/?utm_source=meta&utm_medium=library.properties
  Category:  Data Processing
  Architecture:  *
  Types:  Contributed
  Versions:  [4.0.0, 5.0.0, 5.0.1, 5.0.2, 5.0.3, 5.0.4, 5.0.5, 5.0.6, 5.0.7, 5.0.8, 5.1.0-beta.1, 5.1.0-beta.2, 5.1.0, 5.1.1, 5.2.0, 5.3.0, 5.4.0, 5.5.0, 5.5.1, 5.6.0, 5.6.1, 5.6.2, 5.6.3, 5.6.4, 5.6.5, 5.6.6, 5.6.7, 5.7.0, 5.7.1, 5.7.2, 5.7.3, 5.8.0, 5.8.1, 5.8.2, 5.8.3, 5.8.4, 5.9.0, 5.10.0, 5.10.1, 5.11.0, 5.11.1, 5.11.2, 5.12.0, 5.13.0, 5.13.1, 5.13.2, 6.0.0-beta, 6.0.1-beta, 6.1.0-beta, 6.2.0-beta, 6.2.1-beta, 6.2.2-beta, 6.2.3-beta]
Name: "Json Streaming Parser"
  Author:  Daniel Eichhorn
  Maintainer:  Daniel Eichhorn <squix78@gmail.com>
  Sentence:  A very memory efficient library to parse (large) JSON objects on small devices
  Paragraph:  A very memory efficient library to parse (large) JSON objects on small devices
  Website:  https://github.com/squix78/json-streaming-parser.git
  Category:  Data Processing
  Architecture:  *
  Types:  Contributed
  Versions:  [1.0.0, 1.0.2, 1.0.3, 1.0.4, 1.0.5]

2種類見つかりました。「ArduinoJson」をインストールしてみます。

$ arduino-cli lib install ArduinoJson
ArduinoJson@6.2.3-beta downloaded
Installed ArduinoJson@6.2.3-beta

おお~。超らくちんですね。

ESP32の開発を始めるには、

$ arduino-cli config init
$ sketchbook_path=$(arduino-cli config dump | grep -oPe "(?<=sketchbook_path: ).*")
$ git clone --recursive https://github.com/espressif/arduino-esp32.git $sketchbook_path/hardware/espressif/esp32
$ ( cd $sketchbook_path/hardware/espressif/esp32/tools && python get.py )
$ arduino-cli sketch new sample
$ cd $sketchbook_path/sample
$ arduino-cli board attach espressif:esp32:m5stack-core-esp32
$ arduino-cli compile --fqbn espressif:esp32:m5stack-core-esp32 .
Build options changed, rebuilding all
Error: open /tmp/arduino-sketch-5058F1AF8388633F609CADB75A75DC9D/core/core.a: no such file or directory
Compilation failed.

あれ、なんか謎のエラーが。

まぁ、まだアルファリリースだからかな。 arduino:avr:unoとかなら問題なくビルドできた。

CLIベースだと依存解決や環境構築がテキパキできていいですね!