arduino-cli-基本使用

Arduino CLI 文档

安装

在 ArchLinux 上, 可直接用 pacman 安装;

1
sudo pacman -S arduino-cli

初始化

1
arduino-cli config init

其会在 ~/.arduino15 目录下生成 arduino-cli.yaml 等配置文件.

查看开发板的连接

1
arduino-cli board list

编译代码

假设 Blink 目录下有 blink.ino 文件, 则:

1
arduino-cli compile --fqbn arduino:avr:uno Blink

注意目录下需要有一个同名文件作为主文件才行, 比如这里是 Blink.ino.

编译成功的输出如:

1
2
3
4
5
6
7
8
Sketch uses 5028 bytes (15%) of program storage space. Maximum is 32256 bytes.
Global variables use 400 bytes (19%) of dynamic memory, leaving 1648 bytes for local variables. Maximum is 2048 bytes.

Used library Version Path
Wire 1.0 /home/jie/.arduino15/packages/arduino/hardware/avr/1.8.6/libraries/Wire

Used platform Version Path
arduino:avr 1.8.6 /home/jie/.arduino15/packages/arduino/hardware/avr/1.8.6

上传代码到开发板

如果 arduino-cli board list 的输出为:

1
2
Port         Protocol Type              Board Name         FQBN                     Core
/dev/ttyACM1 serial Serial Port (USB) Arduino Nano Every arduino:megaavr:nona4809 arduino:megaavr

查看开发板可用的 programmer:

1
arduino-cli board details --fqbn arduino:avr:uno

部分输出如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Programmers:   ID                     Name
arduinoasisp Arduino as ISP
arduinoasispatmega32u4 Arduino as ISP (ATmega32U4)
arduinoisp ArduinoISP
arduinoisporg ArduinoISP.org
atmel_ice Atmel-ICE (AVR)
avrisp AVR ISP
avrispmkii AVRISP mkII
buspirate BusPirate as ISP
jtag3 Atmel JTAGICE3 (JTAG mode)
jtag3isp Atmel JTAGICE3 (ISP mode)
parallel Parallel Programmer
stk500 Atmel STK500 development board
usbGemma Arduino Gemma
usbasp USBasp
usbtinyisp USBtinyISP

则上传时指定这个接口:

1
arduino-cli upload -v -p /dev/ttyACM1 --fqbn arduino:avr:uno --programmer atmel_ice Blink

示例

Arduino Nano Every 板子以及用 Onboard Atmel mEDBG (UNO WiFi Rev2) 为 Programmer.

确保安装了 megaAVR 系列核心

1
arduino-cli core list

输出如:

1
2
3
ID              Installed Latest Name
arduino:avr 1.8.6 1.8.6 Arduino AVR Boards
arduino:megaavr 1.8.8 1.8.8 Arduino megaAVR Boards

若没安装, 则:

1
2
arduino-cli core update-index
arduiono-cli core install arduino:megaavr

查看当前板子和端口

将开发板连接到电脑后, 可用下面命令查看:

1
arduino-cli board list

输出如:

1
2
Port         Protocol Type              Board Name         FQBN                     Core
/dev/ttyACM0 serial Serial Port (USB) Arduino Nano Every arduino:megaavr:nona4809 arduino:megaavr

也可查看更详细信息如:

1
arduino-cli board details --fqbn arduino:megaavr:nona4809

输出如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Board name:                Arduino Nano Every
FQBN: arduino:megaavr:nona4809
Board version: 1.8.8

Official Arduino board: ✔

Identification properties: pid=0x0058
vid=0x2341

Identification properties: board=nona4809

Package name: arduino
Package maintainer: Arduino
Package URL: https://downloads.arduino.cc/packages/package_index.tar.bz2
Package website: http://www.arduino.cc/
Package online help: http://www.arduino.cc/en/Reference/HomePage

Platform name: Arduino megaAVR Boards
Platform category: Arduino
Platform architecture: megaavr
Platform URL: http://downloads.arduino.cc/cores/core-ArduinoCore-megaavr-1.8.8.tar.bz2
Platform file name: core-ArduinoCore-megaavr-1.8.8.tar.bz2
Platform size (bytes): 868150
Platform checksum: SHA-256:4ffba95eef2c217dfadbe545a81c898a184e8dc0ad3a963f15ef4f627de608de

Required tool: arduino:arduinoOTA 1.3.0
Required tool: arduino:avr-gcc 7.3.0-atmel3.6.1-arduino5
Required tool: arduino:avrdude 6.3.0-arduino17

Option: Registers emulation mode
ATMEGA328 ✔ mode=on
None (ATMEGA4809) mode=off
Programmers: ID Name
medbg Onboard Atmel mEDBG (UNO WiFi Rev2)

上传 code

1
arduino-cli upload -v -p /dev/ttyACM0 --fqbn arduino:megaavr:nona4809 Disk/Arduino/RTOS_Lab2-I2C

上传成功如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
...
Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of fuse5 written
avrdude: reading input file "0x00"
avrdude: writing fuse8 (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of fuse8 written

avrdude done. Thank you.

New upload port: /dev/ttyACM0 (serial)

arduino-cli-基本使用
http://example.com/2024/10/17/arduino-cli-基本使用/
作者
Jie
发布于
2024年10月17日
许可协议