Skip to content

Arduino

hasu@tmk edited this page Dec 9, 2021 · 8 revisions

arduino-cli

https://github.com/arduino/arduino-cli

Documents

https://arduino.github.io/arduino-cli/latest/

Command Reference

https://arduino.github.io/arduino-cli/commands/arduino-cli/

Installation

https://arduino.github.io/arduino-cli/latest/installation/

It seems that arduino-cli doesn't use Arduino IDE files. You don't have to install Arduino IDE, instead, install core files under ~/.arduino15 with arduino-cli core command.

Example

Serial Monitor Alternatives

  • cutecom - GUI App
  • microcom
  • picocom
  • jerm

https://alternativeto.net/software/minicom/?platform=linux

Serial Monitor:

$ picocom -b 115200 /dev/ttyACM0

Compile

Build files are located under build/ in sketch directory.

$ arduino-cli compile -v -b arduino:avr:uno ~/Arduino/Blink

You can omit -b option if FQBN is assigned to the sketch with board attach command.

$ arduino-cli compile -v ~/Arduino/Blink

Compile ESP8266 Arduino sketch.

$ arduino-cli compile -v -b esp8266:esp8266:generic ~/Arduino/NTPClock

...

Executable segment sizes:
IROM   : 247796          - code in flash         (default or ICACHE_FLASH_ATTR)
IRAM   : 27568   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...)
DATA   : 1344  )         - initialized variables (global, static) in RAM/HEAP
RODATA : 956   ) / 81920 - constants             (global, static) in RAM/HEAP
BSS    : 25144 )         - zeroed variables      (global, static) in RAM/HEAP
Sketch uses 277664 bytes (28%) of program storage space. Maximum is 958448 bytes.
Global variables use 27444 bytes (33%) of dynamic memory, leaving 54476 bytes for local variables. Maximum is 81920 bytes.

Compile example with library and Upload:

$ arduino-cli compile -b arduino:avr:uno --libraries .. examples/SwitchProUSB/ -u -p /dev/ttyACM0 && conp /dev/ttyACM0

Upload

Upload built firmware to board.

$ arduino-cli upload -v -b arduino:avr:uno ~/Arduino/Blink

You can omit -b option if FQBN is assigned to the sketch with board attach command.

$ arduino-cli upload -v ~/Arduino/Blink

Upload built firmware to ESP8266 board.

$ arduino-cli upload -v -b esp8266:esp8266:generic -p /dev/ttyUSB1 ~/Arduino/NTPClock

Waiting for upload port...
No new serial port detected.
"/home/noname/.arduino15/packages/esp8266/tools/python3/3.7.2-post1/python3" "/home/noname/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/upload.py" --chip esp8266 --port "/dev/ttyUSB1" --baud "115200" ""  --before default_reset --after hard_reset write_flash 0x0 "/home/noname/Arduino/NTPClock/build/esp8266.esp8266.generic/NTPClock.ino.bin"
esptool.py v2.8
Serial port /dev/ttyUSB1
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 5c:cf:7f:85:02:a9
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0340
Compressed 281840 bytes to 207360...
Wrote 281840 bytes (207360 compressed) at 0x00000000 in 18.2 seconds (effective 123.7 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

remove build cache

This will be required when changing core/library codes.

$ rm -r /tmp/arduino-sketch-??????????
$ rm -r build

arduino-cil cache clean doesn't removes object files.

Board list

This lists serial port and connectted boards if they are recognized.

$ 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/ttyUSB0 Serial Port (USB) Unknown
/dev/ttyUSB1 Serial Port (USB) Unknown

Board attach

This makes ~/Arduino/Blink/sketch.json file for board configuration.

$ arduino-cli board attach serial:///dev/ttyACM0 ~/Arduino/Blink
Board found: Arduino Uno...
Selected fqbn: arduino:avr:uno

$ cat Blink/sketch.json
{
  "cpu": {
    "fqbn": "arduino:avr:uno",
    "name": "Arduino Uno",
    "port": "serial:///dev/ttyACM0"
  }
}

Core

Install core: This installs core under ~/.arduino15/ apart from

$ arduino-cli core install arduino:avr

Board manager URLs

https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls

Config

$ arduino-cli config init
$ vi ~/.arduino15/arduino-cli.yaml

Completion

Usage:
  arduino-cli completion [bash|zsh|fish] [--no-descriptions] [flags]


$ arduino-cli completion bash > arduino-cli_completion.sh
$ sudo mv arduino-cli_completion.sh /etc/bash_completion.d/

avrdude

https://manpages.debian.org/testing/avrdude/avrdude.1.en.html

For ATmega32u4 with Atmel bootloader

$ avrdude -patmega32u4 -cflip1 -Uflash:w:example.hex

For Leonardo

$ avrdude -patmega32u4 -cavr109 -b57600 -Uflash:w:example.hex

For Uno

$ avrdude -patmega328p -cavrdude -b115200 -Uflash:w:example.hex -P/dev/ttyACM0