Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Last active November 26, 2020 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/d8b6a46245ce498b10217b6a3301891a to your computer and use it in GitHub Desktop.
Save mamemomonga/d8b6a46245ce498b10217b6a3301891a to your computer and use it in GitHub Desktop.
Arduino-CLI メモ

Arduino CLI メモ

セットアップ

Homebrew

$ brew update
$ brew install arduino-cli

Install Script

$ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh

パスの設定(zshの場合)

$ echo 'export PATH=$HOME/bin:$PATH' >> $HOME/.zshrc
$ exec $SHELL

設定

実行の確認

$ arduino-cli help core

configの作成

$ arduino-cli config init

コア一覧の更新

$ arduino-cli core update-index

インストールされているボードリストの表示

$ arduino-cli board listall

インストールされているコアの表示

$ arduino-cli core list

Arduino Uno

Arduinoの代表。Atmel(Microchip) ATmega328P(8ビットマイコン 32kBメモリ)を搭載する。

接続されているArduinoの確認

$ arduino-cli board list
Port         Type              Board Name  FQBN            Core
/dev/ttyACM0 Serial Port (USB) Arduino Uno arduino:avr:uno arduino:avr
/dev/ttyS0   Serial Port       Unknown
/dev/ttyS1   Serial Port       Unknown
/dev/ttyS2   Serial Port       Unknown
/dev/ttyS3   Serial Port       Unknown

コアのインストール FQBNを指定する

$ arduino-cli core install arduino:avr
$ arduino-cli core list
ID          Installed Latest Name
arduino:avr 1.8.2     1.8.2  Arduino AVR Boards

スケッチを書く

$ arduino-cli sketch new UnoBlink
$ cat > UnoBlink/UnoBlink.ino << 'EOS'
void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
}
EOS

スケッチのコンパイル

$ arduino-cli compile --fqbn arduino:avr:uno UnoBlink
Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

スケッチのアップロード

$ arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno UnoBlink

アップロード時にPermission Deniedがでる場合

$ ls -al /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Mar 11 03:58 /dev/ttyACM0

$ sudo usermod -aG dialout $USER

再起動または再ログインが必要

ESP-WROOM-02

espressif ESP8266EX を搭載したWiFi対応マイコン。tensilica L106(32Bitマイコン)コアを搭載する。技適対応。

設定

$HOME/.arduino15/arduino-cli.yaml の board_manager の項目に書き加える

$ vim $HOME/.arduino15/arduino-cli.yaml
board_manager:
  additional_urls:
  - https://arduino.esp8266.com/stable/package_esp8266com_index.json

コア一覧の更新

$ arduino-cli core update-index

コア検索

$ arduino-cli core search esp8266
ID              Version Name
esp8266:esp8266 2.6.3   esp8266

コアインストール

$ arduino-cli core install esp8266:esp8266
$ arduino-cli core list
ID              Installed Latest Name
arduino:avr     1.8.2     1.8.2  Arduino AVR Boards
esp8266:esp8266 2.6.3     2.6.3  esp8266

ボードリスト、とりあえずよくわかんないのでGenericを選ぶ

$ arduino-cli board listall | grep 'Generic ESP8266'
Generic ESP8266 Module           esp8266:esp8266:generic

スケッチを描く

$ arduino-cli sketch new ESPBlink
$ cat > UnoBlink/ESPBlink.ino << 'EOS'
void setup(void) {
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop(void) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
}
EOS

コンパイル

$ arduino-cli compile --fqbn esp8266:esp8266:generic ESPBlink

書込はそのうち

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment