2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WSLでarduino-cliを使う

Last updated at Posted at 2022-12-30

WSLでArduino IDEを使う記事をいくつか読みましたが,書き込みをするためにデバイスをWSLに接続して,とかいろいろ難しそうです...

WSLでは exe を直接実行できますので,デバイス接続せずに,WSLから書き込み「操作」を行うことで,うまくいきました。

arduino-cli.exe を入手し,以下ではデスクトップ上にzipを展開して,WSLでそこに移動して実行しています。

$ cd /mnt/c/Users/aaaaa/Desktop/arduino-cli_0.29.0_Windows_64bit
$ ./arduino-cli.exe upload -p COM8 --fqbn arduino:avr:leonardo blink_monitor

arduino-cli 好きです! ボード定義やライブラリーの追加がコマンドラインでできますので,環境の構築や復元がしやすいですね。
こんな感じのMakefileを作って利用しています。WSL用に少し手直ししました。

# usage:
#
# make                 # build only
# make upload          # build and upload
# make upload monitor  # build, upload and then monitor
# make setup

BIN=./arduino-cli.exe

# TARGET = blink
TARGET = blink_monitor

CORE = arduino:avr:leonardo
PORT = COM8

compile:
	${BIN} compile --fqbn ${CORE} ${TARGET}

upload: compile
	${BIN} upload -p ${PORT} --fqbn ${CORE} ${TARGET}

monitor:
	sleep 1;
	${BIN} monitor -p ${PORT}

CORE_URL = https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json

setup:
	${BIN} core update-index
	# ${BIN} core search M5 --additional-urls ${CORE_URL}
	# ${BIN} core install m5stack:esp32 --additional-urls ${CORE_URL}
	# ${BIN} board listall # show available board
	# ${BIN} board list # show connected board
	# ${BIN} lib search M5
	# ${BIN} lib install M5StickCPlus
	# ${BIN} lib install LovyanGFX
	${BIN} core install arduino:avr

実行例

$ make upload monitor
./arduino-cli.exe compile --fqbn arduino:avr:leonardo blink_monitor
最大28672バイトのフラッシュメモリのうち、スケッチが4210バイト(14%)を使っています。
最大2560バイトのRAMのうち、グローバル変数が161バイト(6%)を使っていて、ローカル変数で2399バイト使うことができます。


Used platform Version Path
arduino:avr   1.8.6   C:\Users\aaaaa\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6

./arduino-cli.exe upload -p COM8 --fqbn arduino:avr:leonardo blink_monitor
Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

sleep 1;
./arduino-cli.exe monitor -p COM8
Connected to COM8! Press CTRL-C to exit.
Count 1
Count 2
Count 3
Count 4
make: *** [Makefile:24: monitor] Error 58
$
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?