LoginSignup
0
0

More than 3 years have passed since last update.

WindowsでArduino CLI環境(arduino-cli + Teratermコンソール)

Posted at

ArduinoIDEと同じようなことをCLIだけでやる方法。
ArduinoIDEは入っている前提

ここでは、
 ツールインストールを C:\Users\you\Documents\hoge\
 スケッチ作業場所を C:\Users\you\Documents\sketches\
にする

仕組みとして
 TTLマクロでロックファイルを監視し接続/切断
 コンパイル用batでロックファイルを作成/削除

arduino-cli

ダウンロード

https://arduino.github.io/arduino-cli/installation/
->Windows 64 bit

インストール先とする適当なフォルダを作る (ここではC:\Users\you\Documents\hoge\)
zipを解凍した中のarduino-cli.exeをhoge\へ置く

hoge\の下に build\ フォルダと build_cache\フォルダを作る

Pathを通す

hoge\ フォルダへパスを通す。やり方はググる。

arduino-cliの初期設定

コマンドプロンプトを上げて、hoge\フォルダへ移動し、以下コマンド

arduino-cli --dest-dir . config init

arduino-cli.yamlが出来るのでディレクトリ部分を書き換える
追加のボードマネージャがある場合はadditional_urlsに追加(ここではMightyCoreを追加)

arduino-cli.yaml
    board_manager:
      additional_urls:
      - https://mcudude.github.io/MightyCore/package_MCUdude_MightyCore_index.json
    daemon:
      port: "50051"
    directories:
    ★data: C:\Users\you\Documents\hoge\Arduino15
    ★downloads: C:\Users\you\Documents\hoge\staging
    ★user: C:\Users\you\Documents\hoge

Arduinoボードをインストール

arduino-cli --config-file .\arduino-cli.yaml core update-index

追加のボードマネージャがある場合は追加する (ここではMightyCoreを追加)

arduino-cli --config-file .\arduino-cli.yaml core install arduino:avr
arduino-cli --config-file .\arduino-cli.yaml core install MightyCore:avr
arduino-cli --config-file .\arduino-cli.yaml core update-index

TTLマクロ+BAT準備

hoge\ の下にTTLマクロを作る
ロックファイルの場所を自分のインストールフォルダに書き換え(★1)
COM番号を自分の環境、BaudrateをスケッチのSerial.begin()指定とあわせる(★2)

teraterm_console_watch.ttl
while 1
  filesearch 'C:\Users\you\Documents\hoge\uploading.lock' ★1

  if result=1 then
    call disconnect_console
  else
    call connect_console
  endif

  pause 1
endwhile

end

;;------------------------------
:connect_console

testlink
if result=1 then
  connect '/C=8 /BAUD=115200' ★2
endif

return

;;------------------------------
:disconnect_console

testlink
if result=2 then
  disconnect 0
endif

return

hoge\ の下にBATを作る

  • NO_SUCH_IPに存在しないホストのIPを記載(ms単位waitのためpingで使う) (★1)
  • --fqbnを自分のボードに書き換え(★2)。分からない場合はArduinoIDEを上げ、「ファイル」->「環境設定」->「より詳細な~~」をチェックし、コンパイルログから引用
  • 自作ライブラリがある場合は--librariesでそのフォルダのパスを追加 (★3)
  • --build-pathと--build-cache-pathを先ほど作ったフォルダに書き換え(★4)
  • ロックファイルの場所を自分のインストールフォルダに書き換え(★5)
arduino-compile.bat
@echo off

set NO_SUCH_IP = 192.168.123.123 ★1
set SLEEP_MS = 1400

arduino-cli.exe compile ^
★2 --fqbn MightyCore:avr:1284:bootloader=uart0,pinout=standard,variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external ^
★3 --libraries ..\libraries ^
★4 --build-path C:\Users\you\Documents\hoge\build ^
★4 --build-cache-path C:\Users\you\Documents\hoge\build_cache ^
  %2

if %ERRORLEVEL% == 0 (
★5 copy NUL C:\Users\you\Documents\hoge\uploading.lock >NUL

  ping -w %SLEEP_MS% -n 1 %NO_SUCH_IP% >NUL

  arduino-cli upload ^
    -p %1 ^
    --fqbn MightyCore:avr:1284:bootloader=uart0,pinout=standard,variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external ^
  %2

★5 del C:\Users\you\Documents\hoge\uploading.lock >NUL
)

スケッチコンパイル&アップロード

Teratermを起動し、teraterm_console_watch.ttlマクロを起動

コマンドプロンプトでスケッチを置いてあるフォルダへ移動 (ここではC:\Users\you\Documents\sketches\)

コンパイルする

arduino-compile.bat COM1 test
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0