Arduino command line support
back to Robobot_B Back to Basebot
Arduino command line interface
See https://docs.arduino.cc/arduino-cli/
Install Arduino CLI
Get the install script and let it install arduino-cli into the directory ~/bin. It will detect the download platform and install an appropriate version.
cd curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh cd bin pwd
Add this directory to the PATH.
nano ~/.bashrc
Add at the end (assuming your login name is local)
export PATH=$PATH:/home/local/bin
Implement the new path
source ~/.bashrc
Add Teensy boards
Make a configuration file (in a hidden file called ~/.arduino15/arduino-cli.yaml).
arduino-cli config init
Copy the URL for Teensyduino https://www.pjrc.com/teensy/package_teensy_index.json and add it to the configuration file.
nano ~/.arduino15/arduino-cli.yaml
Make it look like this:
board_manager: additional_urls: ["https://www.pjrc.com/teensy/package_teensy_index.json"]
After this, update the index
arduino-cli core update-index
Install Teensy support
Find the install name of the board type to install
$ arduino-cli core search teensy ID Version Name teensy:avr 1.59.0 Teensy (for Arduino IDE 2.0.4 or later)
Then, install and configure the Teensy support
arduino-cli core install teensy:avr
Install libraries
Robobot need (especially) these libraries.
- Adafruit GFX Library
- MPU9250_asukiaaa
If the exact name is not known, then search, e.g.:
arduino-cli lib search name:"Adafruit GFX Library"
Install
arduino-cli lib install "Adafruit GFX Library" arduino-cli lib install "MPU9250_asukiaaa"
Compile
With the board connected, find the board type name:
$ arduino-cli board list Port Protocol Type Board Name FQBN Core /dev/ttyACM0 serial Serial Port (USB) Unknown /dev/ttyAMA10 serial Serial Port Unknown usb3/3-2 teensy Teensy Ports Teensy 4.1 teensy:avr:teensy41 teensy:avr
In this case, the key name is "teensy:avr:teensy41"
Command line compile the teensy_firmware_8.ino in the directory ~/svn/robobot/teensy_firmware_8
cd ~/svn/robobot/teensy_firmware_8 arduino-cli compile --fqbn teensy:avr:teensy41 --build-path build ../teensy_firmware_8
The compile for Teensy 4.1 is copied into a script called compile (remember to chmod +x compile).
$ cat compile #!/bin/bash arduino-cli compile --fqbn teensy:avr:teensy41 --build-path build ../teensy_firmware_8
It takes a while to compile and should have a few warnings only.
$ ./compile Memory Usage on Teensy 4.1: FLASH: code:149300, data:41316, headers:9060 free for files:7926788 RAM1: variables:60352, code:146136, padding:17704 free for local variables:300096 RAM2: variables:12640 free for malloc/new:511648 Used library Version Path ADC 9.1 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ ADC MPU9250_asukiaaa 1.5.13 /home/local/Arduino/libraries/MPU9250_asukiaaa Wire 1.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ Wire Adafruit GFX Library 1.11.11 /home/local/Arduino/libraries/Adafruit_GFX_Library Adafruit BusIO 1.16.2 /home/local/Arduino/libraries/Adafruit_BusIO SPI 1.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/SPI USBHost_t36 0.2 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ USBHost_t36 SdFat 2.1.2 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/ SdFat WS2812Serial /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/WS2812Serial EEPROM 2.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0/libraries/EEPROM Used platform Version Path teensy:avr 1.59.0 /home/local/.arduino15/packages/teensy/hardware/avr/1.59.0
The compiled code is in the build directory.
Upload
The arduino-cli upload for Teensy requires a graphical interface, but there is a command line alternative.
Install command line uploader
cd mkdir -p git cd git git clone https://github.com/PaulStoffregen/teensy_loader_cli.git cd teensy_loader_cli make
This makes the executable binary teensy_loader_cli. This compiled file can be copied to /usr/local/bin for easy access.
sudo cp ~/git/teensy_loader_cli/teensy_loader_cli /usr/local/bin
Make the Teensy device recognizable
Copy the needed udev rules:
cd /etc/udev/rules.d sudo wget https://www.pjrc.com/teensy/00-teensy.rules
They can also be found in ~/svn/robobot/setup and copied from there.
NB! The new rules will be implemented after a reboot or an unplug - plug of the Teensy USB, or:
sudo reboot
The upload
The hex file is in the build directory and can be uploaded using the commands
- cd ~/svn/robobot/teensy_firmware_8/build
- sudo teensy_loader_cli -v -w --mcu=TEENSY41 teensy_firmware_8.ino.hex
This command is available in the firmware directory as upload
$ cd ~/svn/robobot/teenst_firmware_8 $ ./upload Teensy Loader, Command Line, Version 2.3 Read "build/teensy_firmware_8.ino.hex": 201728 bytes, 2.5% usage Waiting for Teensy device... (hint: press the reset button)
The Teensy board will cut battery power during upload,
so, press and hold the "power" button before pressing the small reset button on the Teensy board.
Then it uploads:
Found HalfKay Bootloader Programming.................................................................. Booting
After booting, you can release the power button.