Sorry, if not the appropriate place (CLI vs IDE) and if all of this has been discussed.
But I thought I would mention a few things here while I am experimenting. And thought I would write down a few notes here, as to not forget and on the rare occasion, it might be of some use to a few others.
Installing it - Is it already installed as part of the IDE? Quick search did not find arduino-cli when I search the daily build zip file (Windows 11 in this case).
So went to: arduino/arduino-cli: Arduino command line tool (github.com) Clicked on the latest release on the right hand side of screen. And made sure add the location to the Path.
Compiling
Doing the command: arduino-cli --help
Gives you a clue to use the compile: compile Compiles Arduino sketches.
Likewise, the help on that command helps some:
C:\Users\kurte>arduino-cli compile --help
Compiles Arduino sketches.
Usage:
arduino-cli compile [flags]
Examples:
arduino-cli compile -b arduino:avr:uno /home/user/Arduino/MySketch
arduino-cli compile -b arduino:avr:uno --build-property "build.extra_flags=\"-DMY_DEFINE=\"hello world\"\"" /home/user/Arduino/MySketch
arduino-cli compile -b arduino:avr:uno --build-property "build.extra_flags=-DPIN=2 \"-DMY_DEFINE=\"hello world\"\"" /home/user/Arduino/MySketch
arduino-cli compile -b arduino:avr:uno --build-property build.extra_flags=-DPIN=2 --build-property "compiler.cpp.extra_flags=\"-DSSID=\"hello world\"\"" /home/user/Arduino/MySketch
Flags:
--board-options strings List of board options separated by commas. Or can be used multiple times for multiple options.
--build-cache-path string Builds of 'core.a' are saved into this path to be cached and reused.
--build-path string Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.
--build-property stringArray Override a build property with a custom value. Can be used multiple times for multiple properties.
--clean Optional, cleanup the build folder and do not use any cached build.
--discovery-timeout duration Max time to wait for port discovery, e.g.: 30s, 1m (default 1s)
--dump-profile Create and print a profile configuration from the build.
--encrypt-key string The name of the custom encryption key to use to encrypt a binary during the compile process. Used only by the platforms that support it.
-e, --export-binaries If set built binaries will be exported to the sketch folder.
-b, --fqbn string Fully Qualified Board Name, e.g.: arduino:avr:uno
-h, --help help for compile
--keys-keychain string The path of the dir to search for the custom keys to sign and encrypt a binary. Used only by the platforms that support it.
--libraries strings Path to a collection of libraries. Can be used multiple times or entries can be comma separated.
--library strings Path to a single libraryβs root folder. Can be used multiple times or entries can be comma separated.
--only-compilation-database Just produce the compilation database, without actually compiling. All build commands are skipped except pre* hooks.
--optimize-for-debug Optional, optimize compile output for debugging, rather than for release.
--output-dir string Save build artifacts in this directory.
-p, --port string Upload port address, e.g.: COM3 or /dev/ttyACM2
--preprocess Print preprocessed code to stdout instead of compiling.
-m, --profile string Sketch profile to use
-P, --programmer string Programmer to use, e.g: atmel_ice
-l, --protocol string Upload port protocol, e.g: serial
--quiet Optional, suppresses almost every output.
--show-properties Show all build properties used instead of compiling.
--sign-key string The name of the custom signing key to use to sign a binary during the compile process. Used only by the platforms that support it.
-u, --upload Upload the binary after the compilation.
-t, --verify Verify uploaded binary after the upload.
--vid-pid string When specified, VID/PID specific build properties are used, if board supports them.
--warnings string Optional, can be: none, default, more, all. Used to tell gcc which warning level to use (-W flag). (default "none")
Global Flags:
--additional-urls strings Comma-separated list of additional URLs for the Boards Manager.
--config-file string The custom config file (if not specified the default will be used).
--format string The output format for the logs, can be: text, json, jsonmini, yaml (default "text")
--log-file string Path to the file where logs will be written.
--log-format string The output format for the logs, can be: text, json
--log-level string Messages with this level and above will be logged. Valid levels are: trace, debug, info, warn, error, fatal, panic
--no-color Disable colored output.
-v, --verbose Print the logs on the standard output.
So what is the FQBN (yet another TLA actually FLA) for a Teensy?
One way to get an idea is to use the command:
C:\Users\kurte>arduino-cli board list
Port Protocol Type Board Name FQBN Core
usb:0/140000/0/8/4 teensy Teensy Ports Teensy 4.0 teensy:avr:teensy40 teensy:avr
So found out both the FQBN and the port name, in this case it was T40 compiled with a USB type that does not include USB Serial. Another run with a Teensy MicroMod
C:\Users\kurte>arduino-cli board list
Port Protocol Type Board Name FQBN Core
COM27 serial Serial Port (USB) Unknown
usb:0/140000/0/8/1/1 teensy Teensy Ports Teensy MicroMod teensy:avr:teensyMM teensy:avr
Now how to do I compile a sketch: first attempt (actually probably 10th) :
Note: one of my first attempts failed to find any of the libraries. Turns out the CLI does not look into the same configuration stuff as either IDE... And it was defaulting to default location which is under the onedrive... on my W11 machine. My sketchbook is not there. So fiddled around with it for a while and found:
arduino-cli config init
Then edited the file mentioned and set the correct location.
But now that is working, In this case I changed directory to the location of sketch
D:\github\mtp_tft_picture_view>arduino-cli compile -b teensy:avr:teensyMM
D:\github\mtp_tft_picture_view\mtp_tft_picture_view.ino:18:17: note: '#pragma message: Note Built without MTP support'
18 | #pragma message "Note Built without MTP support"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\github\mtp_tft_picture_view\mtp_tft_picture_view.ino:147:17: note: '#pragma message: Display: ILI9341_t3n'
147 | #pragma message "Display: ILI9341_t3n"
| ^~~~~~~~~~~~~~~~~~~~~~
Memory Usage on Teensy MicroMod:
FLASH: code:140840, data:33204, headers:8224 free for files:16332804
RAM1: variables:102080, code:135240, padding:28600 free for local variables:258368
RAM2: variables:12384 free for malloc/new:511904
Used library Version Path
SPI 1.0 C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.58.3\libraries\SPI
SD 2.0.0 D:\github\SD
SdFat 2.1.2 D:\github\SdFat
JPEGDEC 1.2.8 C:\Users\kurte\Documents\Arduino\libraries\JPEGDEC
PNGdec 1.0.1 C:\Users\kurte\Documents\Arduino\libraries\PNGdec
ILI9341_t3n 1.1.0 D:\github\ili9341_t3n
XPT2046_Touchscreen 1.4 C:\Users\kurte\Documents\Arduino\libraries\XPT2046_Touchscreen
Used platform Version Path
teensy:avr 0.58.3 C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.58.3
How do I define Build Options?
That is how do I Build with using not the default options? The CLI help gave a couple examples of using a larger hammer to replace major settings, but nothing appears to apply (at least to me)
So it built, but not with MTP support, how do I enable it. More fumbling around but finally found:
D:\github\mtp_tft_picture_view>arduino-cli compile -b teensy:avr:teensyMM --build-property="build.usbtype=USB_MTPDISK_SERIAL"
D:\github\mtp_tft_picture_view\mtp_tft_picture_view.ino:147:17: note: '#pragma message: Display: ILI9341_t3n'
147 | #pragma message "Display: ILI9341_t3n"
| ^~~~~~~~~~~~~~~~~~~~~~
c:/users/kurte/appdata/local/arduino15/packages/teensy/tools/teensy-compile/11.3.1-beta2/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\kurte\AppData\Local\Temp\arduino-sketch-479771791AB690CB5AEED20B64877CBE\libraries\MTP_Teensy\MTP_Teensy.cpp.o: in function `MTP_class::begin()':
C:\Users\kurte\Documents\Arduino\libraries\MTP_Teensy\src/MTP_Teensy.cpp:91: undefined reference to `usb_mtp_rxSize'
c:/users/kurte/appdata/local/arduino15/packages/teensy/tools/teensy-compile/11.3.1-beta2/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\kurte\AppData\Local\Temp\arduino-sketch-479771791AB690CB5AEED20B64877CBE\libraries\MTP_Teensy\MTP_Teensy.cpp.o: in function `MTP_class::receive_bulk(unsigned long)':
C:\Users\kurte\Documents\Arduino\libraries\MTP_Teensy\src/MTP_Teensy.cpp:1593: undefined reference to `usb_mtp_recv'
Which mostly built be link failed. FIgured out, because it did not rebuild the core using the new option. So needed to add the --clean option
D:\github\mtp_tft_picture_view>arduino-cli compile -b teensy:avr:teensyMM --build-property="build.usbtype=USB_MTPDISK_SERIAL" --clean
D:\github\mtp_tft_picture_view\mtp_tft_picture_view.ino:147:17: note: '#pragma message: Display: ILI9341_t3n'
147 | #pragma message "Display: ILI9341_t3n"
| ^~~~~~~~~~~~~~~~~~~~~~
Memory Usage on Teensy MicroMod:
FLASH: code:167972, data:36440, headers:8576 free for files:16302084
RAM1: variables:105632, code:162360, padding:1480 free for local variables:254816
RAM2: variables:28800 free for malloc/new:495488
Used library Version Path
SPI 1.0 C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.58.3\libraries\SPI
SD 2.0.0 D:\github\SD
SdFat 2.1.2 D:\github\SdFat
MTP_Teensy 1.0.0 D:\github\MTP_Teensy
JPEGDEC 1.2.8 C:\Users\kurte\Documents\Arduino\libraries\JPEGDEC
PNGdec 1.0.1 C:\Users\kurte\Documents\Arduino\libraries\PNGdec
ILI9341_t3n 1.1.0 D:\github\ili9341_t3n
XPT2046_Touchscreen 1.4 C:\Users\kurte\Documents\Arduino\libraries\XPT2046_Touchscreen
Used platform Version Path
teensy:avr 0.58.3 C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.58.3
Next up Upload: More on this later. Where I am mostly interested in the CLI is for remote builds on an RPI, and I wish to this headless.
So far in the case of Teensy builds, headless uploads are not fully supported yet.
So I end up using teensly_loader_cli, but that is another topic.
To make it easier I thought I would use the --export-binaries
When I was first doing this on my Windows 11 machine using KiTTy to talk to RPI, my quick first look I thought the export did not work as I did not see the .hex file in the same directory.
But looking again the files are put into a subfolder
D:\github\mtp_tft_picture_view>arduino-cli compile -b teensy:avr:teensyMM --build-property="build.usbtype=USB_MTPDISK_SERIAL" --export-binaries
...
D:\github\mtp_tft_picture_view>dir build\teensy.avr.teensyMM
Volume in drive D is DATA
Volume Serial Number is 5C92-8524
Directory of D:\github\mtp_tft_picture_view\build\teensy.avr.teensyMM
12/23/2022 11:50 AM <DIR> .
12/23/2022 11:50 AM <DIR> ..
12/23/2022 11:50 AM 34 mtp_tft_picture_view.ino.eep
12/23/2022 11:50 AM 525,944 mtp_tft_picture_view.ino.ehex
12/23/2022 11:50 AM 3,166,792 mtp_tft_picture_view.ino.elf
12/23/2022 11:50 AM 599,181 mtp_tft_picture_view.ino.hex
12/23/2022 11:50 AM 4,035,276 mtp_tft_picture_view.ino.lst
12/23/2022 11:50 AM 74,302 mtp_tft_picture_view.ino.sym
6 File(s) 8,401,529 bytes
2 Dir(s) 756,272,873,472 bytes free
But on PC was able to upload like:
D:\github\mtp_tft_picture_view>arduino-cli upload -p usb:0/140000/0/8/1/1
Now back to playing