Arduino CLI And IDE now Released - Teensy Supported!

Very little has happened on this. A very long list of features needed on Teensy 4.0 has taken precedence. If you look at the pretty incredible number of changes in 1.48 and 1.49, it's pretty clear to see progress is being made (on those features, not arduino-cli). But much more remains to be done, so 1.50 & 1.51 are going to focus on features for Teensy 4.0, like USB audio, Wire lib slave mode, and a few remaining libs not yet ported, like OctoWS2811.

One tiny thing that did just recently happen is this commit, which will be released in 1.8.11.

https://github.com/arduino/Arduino/commit/0f5d22c67c3ccaeb7fd52aa3576e089d4caa3c85

Teensy's platform.txt uses "{runtime.platform.path}" in its recipes for pluggable discovery. Hopefully after 1.8.11 releases, the Arduino devs will also support this syntax in arduino-cli. We either need that support, or a different pluggable discovery recipe would be needed for arduino-cli. I'm not excited about maintaining 2 different platform.txt files, which is the reason why I went to the trouble to submit that pull request.

So there is some tiny & incremental progress, but the honest reality is nearly all dev time is going into Teensy 4.0 software support at this time.
 
Hi,

I am using arduino_cli but I am a bit confused when I try to used it with my teensy 3.2. Arduino_cli reports that the platform is not installed but I couldn't find how I can add the teensy in the arduino_cli environment.

Charles
 
That's unfortunate. Arduino CLI is the only solution that allows using programmers editors like Sublime, EMeditor, Epsilon etc.
 
That's unfortunate. Arduino CLI is the only solution that allows using programmers editors like Sublime, EMeditor, Epsilon etc.

You can switch the Arduino-IDE to use an external Editor.
- Defragtster has a solution "TSET".
- Luni has a solution, too.
- Then, there is Platformio.
..etc
 
I have been looking for a better GUI / enviroment for coding my Teensy boards than using the Arduino GUI. Currently using Visual Code with PlatformIO, this loads to Windows 10 very quickly and compiling code is very fast and it auto loads the hex file via the Teensy Loader to a connected Teensy board. The management of scr files to be #included in the main .cpp file is straight forward. The only thing that caught me out was understanding what library files it is using, but clicking on the library tab shows installed libs and allows new libs to be added, so any lib conflicts can be easiily managed. It also supports a very long list of DEV boards and I plan to connect some of my older dev boards soon and see if they work as well as Teensy boards. The GUI layout is well thought out and the enviroment easy to work in, so reccommend it for any Teensy coder.
 
Sorry but imho these solutions even though they work to some extent cannot be considered a solid, trouble - free bridge between arduino build system and user's editing tools.
Arduino CLI although still has minor problems due to its alpha stage, it is one of the best build-library-deploy tools I have come across in embedded development systems.
 
They're more soild than that alpha that doesn't even work, or that so called Aduino-"IDE" that is worse than a early 80ies texteditor.
Had no issues so far.
 
FrankB found a WINDOWS way to trigger IDE build from command line. That is the base of the github.com/TeensyUser/doc/wiki/TSet mentioned above by @luni and @FrankB.

It triggers a Full and Standard IDE build with a Windows batch file. All source and libraries build with that the same as they do from the IDE … bit for bit … with IDE installed and then TeensyDuino - with a couple of path indicators it runs from the sketch folder for any Teensy with all build options stored in the batch file created after answering a few questions in a DOS box for :: Teensy #, Speed, Compile Type ,USB Type.

Code:
"%arduino%\arduino-builder" -verbose=1 -warnings=more -compile -logger=human -hardware "%arduino%\hardware" -hardware "%LOCALAPPDATA%\Arduino15\packages" -tools "%arduino%\tools-builder" -tools "%arduino%\hardware\tools\avr" -tools "%LOCALAPPDATA%\Arduino15\packages" -built-in-libraries "%arduino%\libraries" -libraries "%libs%" -fqbn=%fqbn% -build-path %temp1% -build-cache "%temp2%"  %ino%

Then using 'editor of choice' that can run a batch file - TSET documents the SublimeText in use here. It can run normally with IDE SerMon and Teensy Loader, or TyCommander with or without Integration ( without integrations when used as SerMon it takes a Button press or Ctrl+B in TyComm to trigger upload )

Build command Options: BUILD, BUILD CLEAN, BUILD VERIFY, NEW Sketch, Build Board CMD file.
 
If anyone is following this for a workaround until arduino-cli adds support for the `{runtime.hardware.path}` pattern in Teensy's platform.txt, I managed to get arduino-cli to successfully work with Teensyduino with the following steps.

Note that I did not have the Arduino IDE installed at all, so these steps assume a fresh install of both Arduino IDE 1.8.13 and Teensyduino 1.53. Also these steps were performed on Ubuntu Linux 20.04, but should work in principle anywhere:

  1. Install Arduino IDE 1.8.13 (I used /usr/local/lib/arduino1.8.13)
  2. Install Teensyduino 1.53. Select the Arduino IDE install path above when prompted.
  3. Install arduino-cli. I built from source, and it shouldn't matter where this is installed. What does matter is where the data directory is defined in your arduino-cli YAML configuration file. For example, I use this very simple configuration file, with data directory defined as /usr/local/lib/arduino:
    Code:
    board_manager:
      additional_urls: ['https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json', 'https://adafruit.github.io/arduino-board-index/package_adafruit_index.json']
    daemon:
      port: "50051"
    directories:
      data: /usr/local/lib/arduino                 <--- NOTE THIS DIRECTORY
      downloads: /usr/local/lib/arduino/staging
      user: /usr/local/src/arduino
    logging:
      file: ""
      format: text
      level: trace
  4. Copy Teensyduino to arduino-cli data directory. Note that you'll need to do a bit of rearranging. Assuming the above paths are used, the following commands will create the expected directory structure:
    Code:
    $ mkdir -p /usr/local/lib/arduino/packages/teensy
    $ cp -r /usr/local/lib/arduino1.8.13/hardware/teensy /usr/local/lib/arduino/packages/teensy/hardware
    $ cp -r /usr/local/lib/arduino1.8.13/hardware/tools /usr/local/lib/arduino/packages/teensy/tools
  5. Now with toolchain installed, you'll need to make one ugly patch to address the mentioned feature missing from arduino-cli. Open /usr/local/lib/arduino/packages/teensy/hardware/avr/platform.txt, scroll down to the Teensy Loader section, and replace the commented line with a line specifying the hardcoded path to your tools directory:
    Code:
    ## Teensy Loader
    #tools.teensyloader.cmd.path={runtime.hardware.path}/../tools
    tools.teensyloader.cmd.path=/usr/local/lib/arduino/packages/teensy/tools
  6. Now, you simply need to open Teensyloader and run arduino-cli to build and upload your sketch. Unfortunately, it seems Teensyloader requires a graphical environment to run, so if you are running this remotely, you'll need to make sure the remote machine has an Xserver running. The following commands include "DISPLAY=:0" to account for this, but isn't necessary if you are running this locally on a machine with a graphical desktop. For example:
    Code:
    $ DISPLAY=:0 /usr/local/lib/arduino/packages/teensy/tools/teensy &
    $ arduino-cli --config-file "/usr/local/lib/arduino/config.yaml" compile --verbose --log-level trace --fqbn teensy:avr:teensy40 --upload --port /dev/ttyACM1  --build-path /home/andrew/.tmp/arduino-build/Arduino_Teensy4_test_script --build-cache-path /home/andrew/.tmp/arduino-build.cache/Arduino_Teensy4_test_script   /home/andrew/Code/arduino/Arduino-Teensy4/Arduino_Teensy4_test_script
 
If anyone is following this for a workaround until arduino-cli adds support for the `{runtime.hardware.path}` pattern in Teensy's platform.txt, I managed to get arduino-cli to successfully work with Teensyduino with the following steps.

hey @ardnew thank you very much for the suggestion, it works. I could customize your command to compile for a Teensy3.2

For a full CLI workflow you can remove the `--upload` parameter and upload the `.hex` generated manually using the Teensy CLI loader https://www.pjrc.com/teensy/loader_cli.html (need to be separately installed / compiled)

Example, in your case you can run:

Code:
$ cd /path/to/your/teensy_cli_loader
$ ./teensy_loader_cli -v --mcu=imxrt1062 -w /home/andrew/.tmp/arduino-build/Arduino_Teensy4_test_script/......hex

Looking forward to having Teensy support straight into `arduino-cli`

hope it helps

EDIT: one can also add an automatic upload feature customizing the following properties in the "platform.txt" file mentioned above

Code:
tools.teensyloader.cmd.path=/usr/local/lib/arduino/packages/teensy/tools
tools.teensyloader.upload.params.quiet=
tools.teensyloader.upload.params.verbose=-verbose
tools.teensyloader.upload.pattern="{cmd.path}/teensy_post_compile" "-file={build.project_name}" "-path={build.path}" "-tools={cmd.path}" "-board={build.board}" -reboot "-port={serial.port}" "-portlabel={serial.port.label}" "-portprotocol={serial.port.protocol}"
 
Last edited:
If this were on Windows machine check out :: github.com/Defragster/Tset
After installing IDE and TeensyDuino the IDE never needs to be opened - using TyCommander for SerMon ( and optionally upload ).

Not sure if those batch files can easily be scripted for linux to the same end?

It runs with no edits to IDE .txt files and does a normal IDE build from the command line with Board menu items set as selected in TSET prompts. Pending update to TyCommander allows sending Teensy into Bootloader for TeensyLoader programming. Or with TyCommander integration that does edit boards.txt - SerMon and Upload controlled by TyCommander.

Examples as programmed into Sublime text editor Build system here Use-Sublime-Text-as-an-Arduino-IDE-replacement

Once Compile.CMD created by TSET.CMD it can be double clicked or run in an MS-Dos Box. With Sublime build output captured in a console window.
 
If anyone is following this for a workaround until arduino-cli adds support for the `{runtime.hardware.path}` pattern in Teensy's platform.txt, I managed to get arduino-cli to successfully work with Teensyduino with the following steps.

Note that I did not have the Arduino IDE installed at all, so these steps assume a fresh install of both Arduino IDE 1.8.13 and Teensyduino 1.53. Also these steps were performed on Ubuntu Linux 20.04, but should work in principle anywhere:

  1. Install Arduino IDE 1.8.13 (I used /usr/local/lib/arduino1.8.13)
  2. Install Teensyduino 1.53. Select the Arduino IDE install path above when prompted.
  3. Install arduino-cli. I built from source, and it shouldn't matter where this is installed. What does matter is where the data directory is defined in your arduino-cli YAML configuration file. For example, I use this very simple configuration file, with data directory defined as /usr/local/lib/arduino:
    Code:
    board_manager:
      additional_urls: ['https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json', 'https://adafruit.github.io/arduino-board-index/package_adafruit_index.json']
    daemon:
      port: "50051"
    directories:
      data: /usr/local/lib/arduino                 <--- NOTE THIS DIRECTORY
      downloads: /usr/local/lib/arduino/staging
      user: /usr/local/src/arduino
    logging:
      file: ""
      format: text
      level: trace
  4. Copy Teensyduino to arduino-cli data directory. Note that you'll need to do a bit of rearranging. Assuming the above paths are used, the following commands will create the expected directory structure:
    Code:
    $ mkdir -p /usr/local/lib/arduino/packages/teensy
    $ cp -r /usr/local/lib/arduino1.8.13/hardware/teensy /usr/local/lib/arduino/packages/teensy/hardware
    $ cp -r /usr/local/lib/arduino1.8.13/hardware/tools /usr/local/lib/arduino/packages/teensy/tools
  5. Now with toolchain installed, you'll need to make one ugly patch to address the mentioned feature missing from arduino-cli. Open /usr/local/lib/arduino/packages/teensy/hardware/avr/platform.txt, scroll down to the Teensy Loader section, and replace the commented line with a line specifying the hardcoded path to your tools directory:
    Code:
    ## Teensy Loader
    #tools.teensyloader.cmd.path={runtime.hardware.path}/../tools
    tools.teensyloader.cmd.path=/usr/local/lib/arduino/packages/teensy/tools
  6. Now, you simply need to open Teensyloader and run arduino-cli to build and upload your sketch. Unfortunately, it seems Teensyloader requires a graphical environment to run, so if you are running this remotely, you'll need to make sure the remote machine has an Xserver running. The following commands include "DISPLAY=:0" to account for this, but isn't necessary if you are running this locally on a machine with a graphical desktop. For example:
    Code:
    $ DISPLAY=:0 /usr/local/lib/arduino/packages/teensy/tools/teensy &
    $ arduino-cli --config-file "/usr/local/lib/arduino/config.yaml" compile --verbose --log-level trace --fqbn teensy:avr:teensy40 --upload --port /dev/ttyACM1  --build-path /home/andrew/.tmp/arduino-build/Arduino_Teensy4_test_script --build-cache-path /home/andrew/.tmp/arduino-build.cache/Arduino_Teensy4_test_script   /home/andrew/Code/arduino/Arduino-Teensy4/Arduino_Teensy4_test_script

Thank you for your guide!
I followed every step. arduino-cli lists teensy in core and lists the board as unknown.
When I try to upload a sketch I get the following error
Code:
Error during build: incorrect FQBN: invalid fqbn: teensy:avr

Has anything changed since you made this tutorial?
 
I have made a plugin\tool to Arduino IDE
https://forum.arduino.cc/index.php?topic=706855.0

And available at github https://github.com/manicken/manicken.github.io/tree/master/API_WebServer

I have tested it with success with arduino 1.8.13 on windows 10, ubuntu 20.04 (VM), and macos catalina (VM)

In short it creates a webbserver that receives both code and commands verify/compile upload.
The code is received by POST with files stored in a JSON.
Commands is received by GET requests.
The code is written in java and can take full control of the IDE even nonpublic members by using reflection.
 
To install the plugin\tool copy whole folder API_webserver to the tools folder that is located inside the arduino install folder, in Mac that folder is inside the package in the java folder if I remember it correct. I use the plugin together with the audio design tool, more about that in a another thread because it will be big.
 
hey @ardnew thank you very much for the suggestion, it works. I could customize your command to compile for a Teensy3.2

For a full CLI workflow you can remove the `--upload` parameter and upload the `.hex` generated manually using the Teensy CLI loader https://www.pjrc.com/teensy/loader_cli.html (need to be separately installed / compiled)

Hi,

Does Teensyloader still need to be running if you don't have the '--upload' flag? it always starts up when I run arduino-cli. On the first try, arduino-cli quits during build


arduino-cli compile -e --fqbn teensy:avr:teensy36 /home/root/Arduino/KTZanR/Iot
Opening Teensy Loader...
Unable find Teensy Loader. (p) Is the Teensy Loader application running?
quit
Error during build: exit status 1

Builds fine on the second try because Teensyloader starts..

Thx

Kirk
 
Back
Top