Using Visual Studio Code, Arduino V2 IDE and Visual Teensy - K7MDL2/KEITHSDR GitHub Wiki

Using Visual Studio Code is a very big improvement over the default Arduino IDE. So many features to make coding more productive and enjoyable. Will list them some other time.

VS Code with the Arduino extensions and C/C++ extensions use the command line access to the supplied Arduino compiler and Arduino environment the same way the Arduino IDE does. This means it knows nothing about the Teensy CPU models since TeensyDuino plugs into Arduino IDE, not VSS Code, to bridge the IDE to the Teensy hardware specifics.

Feb 2023 Update: With VS Code 1.75.0 and Arduino IDE V2.0.3

As of today Feb 7, 2023 I updated VS Code and running this tool versions.
VS Code 1.75.0
TyCommander 0.9.8
Arduino IDE V2.0.3
TeensyDuino 0.58.3 (0.58.3 while beta in boards manager, in real life it is 1.58.3).

I configured the Arduino:Path and enabled Use_Arduino_CLI as before. On Compile, it opens TyCommander automatically, asking which Teensy serial port I wanted, the proceeds to upload the new hex file. With Verbose output and Terminal enabled, I have not seen a need to use the Arduino V2 IDE now. There are still some things related to IDE V2 to fix in VS Code extensions and in the TeensyDuino support for IDEv2, but none that stop me from using it today. The Path to the CLI is obscure: Use this path

Arduino:Path (in VS Code Settings)
D:\ArduinoIDE\Arduino IDE\resources\app\node_modules\arduino-ide-extension\build\

Further config: I edited the TeensyDuino supplied platform.txt file to this:

Commented out the Teensy tools and added the new lines for TyCommander and pointed it to my designated build path. On complie you wil be promted for which Teensy port to use.

 File is located at %AppData%\Local\Arduino15\packages\teensy\hardware\avr\0.58.3
# Arduino Boards Manager - original TeensyLoader lines, commented out for TyCommander below
#tools.teensyloader.cmd.path={runtime.tools.teensy-tools.path}
#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}"

# TyCommander alternative to TeensyLoader
tools.teensyloader.cmd.path=D:\Program Files\TyTools\TyCommanderC.exe
tools.teensyloader.upload.pattern="{cmd.path}" upload --autostart --wait --delegate "{build.path}/{build.project_name}.hex"

The last part is the folder I told VS Code to output build files so they are cached. Your path may be different or not exist yet. This path is in the arduino.json file as I recall.

I enable verbose output to watch what goes on, and the Serial terminal works.

Some of this is duplicated at this page https://github.com/K7MDL2/KEITHSDR/wiki/TyCommander-Integration-into-V2-IDE-and-VS-Code

December 2022 Update: With Arduino IDE v2 I no longer need Visual Teensy. TeensyDuino (1.57 and 1.58 or listed as 0.58.x while in beta in the package manager) is now a supported board package in IDE V2 and is picked up by VS Code Board Manager also. VS Code does not fully support IDE V2 yet (as of Jan 2023) but using the Arduino CLI option I have got it working to compile. The serial terminal works and so does the output. YO Ucan turn on verbose output to see how things are building, otherwise it stays dark unless there is an error or completion event. If you get Intellisense errors on libraries the usual answer is to add the path to that lib into the Include File path list in settings. I use TyCommander which helps. I configure an output folder so the build can be cached. IDE V2 uses a GUID named folder. You need to tell TyCommander where to find your output (build) folder. I have a write on this in the KeithsSDR forum, probably in my WIKI as well. You will also find how to setup DualSerial+Audio at 48Khz as a custom USB device and how to setup 48Khz USB audio in the Wiki Pages here.

Arduino IDE V1.8.19: To work around this a project called Visual Teensy was developed and is found at https://github.com/luni64/VisualTeensy.

The Verify and Upload buttons in the VS Code Arduino extension will not function but VS Code "tasks" are used to build, clean, upload and debug with menu and keyboard shortcut access. usually "Control-Shift-B" is made to launch a build and upload. Visual teensy will use either the Teensy.exe you are sued to seeing with Arduino IDE to upload or can use TyCommander which adds several features including a serial monitor, reset and upload buttons, and can see multiple Teensies.

Using Visual Teensy with VS Code does not change your Arduino IDE and you can use either to build with at any time. It does have a dedicated subfolder called .vsteensy with build files, settings and cached files used for the build. In the .vcsode folder are VS code settings files where the tasks are defined and other settings like search paths. In the main project folder (same as your .ino file) will be a file called "makefile". This is used by VSTeensy from either the command line or from the VS Code and has your .ino file name and a couple pathnames that must be changed to match your current working folder if you ever move/copy it. By default when first setting up VSTeensy it plugs in full pathnames. Over time I have made these entries generic and used relative pathnames or environment variables where possible. Now I just copy the makefile and the .vsteensy/setting.json file to a new project (sketch) folder and edit the makefile .ino filename at the top. The rest stays the same. I have the vsteensy build and cache folder moved out of the current folder to keep it cleaner for easier source control and sync with GitHub, no build folder trash to filter out.

Extensions loaded in VS Code: (TODO - create detailed list) C/C++ C/C++ extension pack Ardiuno Various GitHub extensions Several Arduino C/C++ Intellisense helpers.