Compiling Teensy Sketches with VisualCode (Win10)

FYI Here the arguments to the builder from the IDE and from vsTeensy.

Code:
ARDUINO:

C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\arduino-builder 
-dump-prefs 
-logger=machine 
-hardware C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\hardware 
-tools C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\tools-builder 
-tools C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\hardware\tools\avr 
-built-in-libraries C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\libraries 
-libraries C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\portable\sketchbook\libraries
-fqbn=teensy:avr:teensy40:usb=serial,speed=600,opt=o2std,keys=en-us -ide-version=10812 
-build-path C:\Users\lutz\AppData\Local\Temp\arduino_build_892177 
-warnings=none 
-build-cache C:\Users\lutz\AppData\Local\Temp\arduino_cache_53989 
-verbose 
C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\portable\sketchbook\sketch_oct30a\sketch_oct30a.ino


vsTeensy
C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/arduino-builder
-hardware="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/hardware"
-tools="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153\tools-builder"
-libraries="C:\Users\lutz\Documents\Arduino/libraries" 
-libraries="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/hardware/teensy/avr/libraries"
-libraries="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/portable/sketchbook/libraries" 
-fqbn=teensy:avr:teensy31:usb=serial,speed=96,opt=o2std,keys=en-us
-build-path=C:/Users/lutz/source/Teensy/01_scratch/portable/.vsTeensy/build
-warnings=all
-verbose=1 
portable.ino
 
FYI Here the arguments to the builder from the IDE and from vsTeensy.

Code:
ARDUINO:

C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\arduino-builder 
-dump-prefs 
-logger=machine 
-hardware C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\hardware 
-tools C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\tools-builder 
-tools C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\hardware\tools\avr 
-built-in-libraries C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\libraries 
-libraries C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\portable\sketchbook\libraries
-fqbn=teensy:avr:teensy40:usb=serial,speed=600,opt=o2std,keys=en-us -ide-version=10812 
-build-path C:\Users\lutz\AppData\Local\Temp\arduino_build_892177 
-warnings=none 
-build-cache C:\Users\lutz\AppData\Local\Temp\arduino_cache_53989 
-verbose 
C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino153\portable\sketchbook\sketch_oct30a\sketch_oct30a.ino


vsTeensy
C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/arduino-builder
-hardware="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/hardware"
-tools="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153\tools-builder"
-libraries="C:\Users\lutz\Documents\Arduino/libraries" 
-libraries="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/hardware/teensy/avr/libraries"
-libraries="C:\Users\lutz\Documents\arduino-1.8.12-Teensyduino 153/portable/sketchbook/libraries" 
-fqbn=teensy:avr:teensy31:usb=serial,speed=96,opt=o2std,keys=en-us
-build-path=C:/Users/lutz/source/Teensy/01_scratch/portable/.vsTeensy/build
-warnings=all
-verbose=1 
portable.ino

So it looks like that
Code:
libraries="C:\Users\lutz\Documents\Arduino/libraries"
is extra and should be removed from the make file?
Or am i misreading what you wrote?
 
Can you try the version I uploaded here: https://github.com/luni64/VisualTeensy/issues/29 ?

I already replied on github but fot thread completeness I will leave it here as well.

This fixes the issue

Code:
Opening Teensy Loader...
Using library Ethernet at version 2.0.0 in folder: C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\hardware\teensy\avr\libraries\Ethernet 
Using library MIDI at version 5.0.2 in folder: C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\hardware\teensy\avr\libraries\MIDI 
Using library SPI at version 1.0 in folder: C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\hardware\teensy\avr\libraries\SPI
Using library SD at version 1.2.2 in folder: C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\hardware\teensy\avr\libraries\SD
Using library ArduinoJson at version 5.13.5 in folder: C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\portable\sketchbook\libraries\ArduinoJson
Using library Artnet in folder: C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\hardware\teensy\avr\libraries\Artnet (legacy)
Using library EEPROM at version 2.0 in folder: C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\hardware\teensy\avr\libraries\EEPROM
"C:\\Users\\Lorenzo\\Desktop\\Arduinos\\Teensy\\arduino-1.8.13 - TeensyDuino 1.53\\arduino-1.8.13\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-size" -A "C:\\Users\\Lorenzo\\Desktop\\test_visualteensy\\Mm2q_V2.27_MidiBeatClock\\Mm2q_V2.27_MidiBeatClock\\.vsTeensy\\build/Mm2q_V2.27_MidiBeatClock.ino.elf"
Sketch uses 51956 bytes (4%) of program storage space. Maximum is 1048576 bytes.
Global variables use 8000 bytes (3%) of dynamic memory, leaving 254144 bytes for local variables. Maximum is 262144 bytes.
 
Thank you for the amazing response times and for the amazing tool! Very happy with it with the arduino-builder option, just use VScode as code editor and being able to quickly build and load

Now I have another question, when compiled, the standard teensy loader application loads.
I saw before that it should use TyCommander, which I never used but I would like to try, is TyCommander included in the package or do I need to install it manually?

Thanks
 
Thank you for the amazing response times and for the amazing tool! Very happy with it with the arduino-builder option, just use VScode as code editor and being able to quickly build and load

Glad you like it. Since you seem to be interested in long term stable projects you might also think of using the normal build mode (at least for new projects). You then have an option to embed the core files (i.e., Teensyduino) and used libraries into the project. Here some more info on what can be done: https://github.com/luni64/VisualTeensy/wiki/Self-Contained-Projects

saw before that it should use TyCommander, which I never used but I would like to try, is TyCommander included in the package or do I need to install it manually?
You need to install it manually and then point vsTeensy to the installation folder of the tyTools (see setup tab). After this you can choose which uploader you want to use in the vsCode build menu. If you switch between uploaders make sure to always close the other one otherwise you'll get interesting effects if one uploader tries to 'steal' the control over the Teensy from the other...

TyTools also handle the multiple serial modes very nicely. See here for details: https://github.com/TeensyUser/doc/wiki/Serial#multiple-serial-ports

EDIT If you use the arduino builder mode you will see that it will always start up Teensy.exe, even if you just build the project. This is not a bug but the normal behaviour as defined in platform.txt. If you want to use the TyTools together with the Arduino Builder mode you would need to always close Teensy.exe manually which is suboptimal. However, TyCommander has an option to integrate itself to the Arduino IDE which fixes this problem.
 
Last edited:
Amazing, I just set it up. Thank you
Don't know why it opens both TyCommander and the standard one, I guess because the arduino builder is set to do that, but not big deal.

I also reported a quick issue in Github, the latest release is missing make.exe, causing the build to fail.
 
Don't know why it opens both TyCommander and the standard one, I guess because the arduino builder is set to do that, but not big deal.
You might have overlooked my added comment in my last post showing how to fix this.

I also reported a quick issue in Github, the latest release is missing make.exe, causing the build to fail.
Thanks, fixed
 
@luni - looks like you got the Portable IDE working? I just updated TSET to detect that and seems the only diff needed is the one LIBS path comes from portable\sketchbook\libraries - seems to be working with the batch file.

Re: p#232 ::
If you switch between uploaders make sure to always close the other one otherwise you'll get interesting effects if one uploader tries to 'steal' the control over the Teensy from the other...
Also did you see the "--delegate" edit to TyCommander to not fight with IDE PJRC loader?

As expressed in TSET - assuming you could do something like this in your process:
Code:
REM when TyComm integrated this .model. file will exist
    if EXIST "%temp1%\%sketchname%.%model%.hex" (
      "%TyTools%\[B]TyCommanderC.exe" upload --autostart --wait  "%temp1%\%sketchname%.%model%.hex[/B]" ) else ( 
      "%TyTools%\[B]TyCommanderC.exe" upload --autostart --wait --delegate "%temp1%\%sketchname%.hex[/B]" )

It allows TSET to always build though IDE with command line and use TyCommander as SerMon.
> when Build is for TyComm integrated it does the first line after the if EXIST
> When Build not with integrated TyCommander the '--delegate' command tells it to release USB and wait for it to restart allowing PJRC loader to upload without issue.

Allows jumping back to IDE unchanged during Beta when issues are IDE SerMon or other. Also allows for TSET CMDline to use PJRC Loader to deliver a bootloader update should it be presented using PJRC loader, when TyComm not integrated.
 
Also did you see the "--delegate" edit to TyCommander to not fight with IDE PJRC loader?
No, that is new to me. Thanks for the pointer.
Just gave it a try by adding --delegate to the makefile manually and it works nicely. It can also be used to workaround the current TyTool confusion with the new (T1.54beta) composite serial device. I.e. uploading via Teensy.exe and using TyCommander as Sermon. I'll add a corresponding option to vsTeensy later today.
 
Sorry guys, I have to bother again for a probably idiot question I can't understand

trying to build a brand new project with the same portable IDE structure and I got this.

Code:
> Executing task: C:/Users/Lorenzo/Desktop/Arduinos/Teensy/VisualTeensy_v0_9_9_1/make.exe all   <

C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13/arduino-builder -verbose=1 -warnings=all -build-path=C:/Users/Lorenzo/Desktop/test_visualteensy/Midi Test/MIDI Matrix/.vsTeensy/build -fqbn=teensy:avr:teensy36:usb=serialmidi4,speed=180,opt=o2std,keys=en-us -hardware="C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\hardware" -tools="C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\tools-builder" -libraries="C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\portable\sketchbook\libraries" MIDI_Matrix.ino
Parameter 'hardware' is mandatory
Usage of C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13/arduino-builder:
  -build-cache string
        builds of 'core.a' are saved into this folder to be cached and reused
  -build-options-file string
        Instead of specifying --hardware, --tools etc every time, you can load all such options from a file
  -build-path string
        build path
  -built-in-libraries value
        Specify a built-in 'libraries' folder. These are low priority libraries. Can be added multiple times for specifying multiple built-in 'libraries' folders
  -code-complete-at string
        output code completions for sketch at a specific location. Location format is "file:line:col"
  -compile
        compiles the given sketch
  -core-api-version string
        version of core APIs (used to populate ARDUINO #define) (default "10600")
  -daemon
        daemonizes and serves its functions via rpc
  -debug-level int
        Turns on debugging messages. The higher, the chattier (default 5)
  -dump-prefs
        dumps build properties used when compiling
  -experimental
        enables experimental features
  -fqbn string
        fully qualified board name
  -hardware value
        Specify a 'hardware' folder. Can be added multiple times for specifying multiple 'hardware' folders
  -ide-version string
        [deprecated] use 'core-api-version' instead (default "10600")
  -jobs int
        specify how many concurrent gcc processes should run at the same time. Defaults to the number of available cores on the running machine
  -libraries value
        Specify a 'libraries' folder. Can be added multiple times for specifying multiple 'libraries' folders
  -logger string
        Sets type of logger. Available values are 'human', 'humantags', 'machine' (default "human")
  -prefs value
        Specify a custom preference. Can be added multiple times for specifying multiple custom preferences
  -preprocess
        preprocess the given sketch
  -quiet
        if 'true' doesn't print any warnings or progress or whatever
  -tools value
        Specify a 'tools' folder. Can be added multiple times for specifying multiple 'tools' folders
  -trace
        traces the whole process lifecycle
  -verbose
        if 'true' prints lots of stuff
  -version
        prints version and exits
  -vid-pid string
        specify to use vid/pid specific build properties, as defined in boards.txt
  -warnings string
        Sets warnings level. Available values are 'none', 'default', 'more' and 'all'
make.exe: *** [makefile:46: all] Error 1
The terminal process "C:\WINDOWS\System32\cmd.exe /d /c C:/Users/Lorenzo/Desktop/Arduinos/Teensy/VisualTeensy_v0_9_9_1/make.exe all  " terminated with exit code: 2.



My Makefile:
Code:
#******************************************************************************
# Generated by VisualTeensy (https://github.com/luni64/VisualTeensy)
#
# Board              Teensy 3.6
# USB Type           Serial + MIDIx4
# CPU Speed          180 MHz
# Optimize           Faster
# Keyboard Layout    US English
#
# 07/11/2020 11:13
#******************************************************************************
SHELL            := cmd.exe
export SHELL

SKETCH_NAME      := MIDI_Matrix.ino

BOARD_ID         := TEENSY36
MCU              := mk66fx1m0

BUILDER_BASE     := C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13
FLAGS            := -verbose=1 -warnings=all
FQBN             := teensy:avr:teensy36:usb=serialmidi4,speed=180,opt=o2std,keys=en-us
BUILD_PATH       := $(abspath .vsTeensy/build)
HARDWARE         := -hardware="C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13/hardware"
TOOLS            := -tools="C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\tools-builder"

LIBRARIES        := -built-in-libraries="C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13/libraries"
LIBRARIES        := -libraries="C:\Users\Lorenzo\Desktop\Arduinos\Teensy\arduino-1.8.13 - TeensyDuino 1.53\arduino-1.8.13\portable\sketchbook\libraries"
UPL_PJRC_B       := C:\Users\Lorenzo\Desktop\Arduinos\Teensy\ARDUIN~1.53\ARDUIN~1.13\hardware\tools
UPL_TYCMD_B      := C:\Users\Lorenzo\Desktop\Arduinos\Teensy\TyTools-0.9.2-win64\TyTools-0.9.2-win64
UPL_CLICMD_B     := 

TARGET_HEX       := $(BUILD_PATH)/$(SKETCH_NAME).hex

#******************************************************************************
# BINARIES
#******************************************************************************
BUILDER     := $(BUILDER_BASE)/arduino-builder
UPL_PJRC    := "$(UPL_PJRC_B)/teensy_post_compile" -test -file=$(SKETCH_NAME) -path=$(BUILD_PATH) -tools="$(UPL_PJRC_B)" -board=$(BOARD_ID) -reboot
UPL_TYCMD   := $(UPL_TYCMD_B)/tyCommanderC upload $(TARGET_HEX) --autostart --wait --multi
UPL_CLICMD  := $(UPL_CLICMD_B)/teensy_loader_cli -mmcu=$(MCU) -v $(TARGET_HEX) 

.PHONY:  all upload uploadTy uploadCLI clean 

all:  
	$(BUILDER) $(FLAGS) -build-path=$(BUILD_PATH) -fqbn=$(FQBN) $(HARDWARE) $(TOOLS) $(LIBRARIES) $(SKETCH_NAME)

upload: all
	$(UPL_PJRC)

uploadTy: all
	@$(UPL_TYCMD)

uploadCLI: all
	@$(UPL_CLICMD)

clean: 
	@echo Cleaning user binaries...
	@if exist $(BUILD_PATH)/core rd /s/q "$(BUILD_PATH)/core"
	@if exist $(BUILD_PATH)/libraries rd /s/q "$(BUILD_PATH)/libraries"
	@if exist $(BUILD_PATH)/pch rd /s/q "$(BUILD_PATH)/pch"
	@if exist $(BUILD_PATH)/preproc rd /s/q "$(BUILD_PATH)/preproc"
	@if exist $(BUILD_PATH)/sketch rd /s/q "$(BUILD_PATH)/sketch"

	@if exist "$(BUILD_PATH)/*.eep" del  $(subst /,\,$(BUILD_PATH)/*.eep)
	@if exist "$(BUILD_PATH)/*.elf" del  $(subst /,\,$(BUILD_PATH)/*.elf)
	@if exist "$(BUILD_PATH)/*.lst" del  $(subst /,\,$(BUILD_PATH)/*.lst)
	@if exist "$(BUILD_PATH)/*.sym" del  $(subst /,\,$(BUILD_PATH)/*.sym)
	@if exist "$(BUILD_PATH)/*.json" del  $(subst /,\,$(BUILD_PATH)/*.json)	
	@if exist "$(BUILD_PATH)/*.cache" del  $(subst /,\,$(BUILD_PATH)/*.cache)
	@echo done

"hardware" parameter is literally there, why arduino builder complains that is mandatory?
 
Funny, but I can reproduce it. I'll have a look.

Any chance I can talk you into using the normal vsTeensy build system for new projects? It is so much better, works out of the box, has all your libraries in the project folder ....
 
Ok, looks like this time your path with spaces strikes. Can you try to add double quotes to line 23 of the makefile like shown here? This fixes it for me.
Code:
BUILD_PATH       := "$(abspath .vsTeensy/build)"

I can also add caching if you think this speeds the otherwise quite slow builder up?
 
Any chance I can talk you into using the normal vsTeensy build system for new projects? It is so much better, works out of the box, has all your libraries in the project folder ....

as a person who always wants to learn I would say yes...
as a electronic engineer who never studied software development and but wants to play around 10 minutes here and there where the girlfriend is not bothering... my gut feeling tells me stuck to .ino and don't enter in a software loophole that I would struggle to understand

but probably I should stuck to arduino IDE completely, and don't dream about VScode :)
 
Ok, looks like this time your path with spaces strikes. Can you try to add double quotes to line 23 of the makefile like shown here? This fixes it for me.
Code:
BUILD_PATH       := "$(abspath .vsTeensy/build)"

I can also add caching if you think this speeds the otherwise quite slow builder up?

Yes seems to go through now, I will just remove all the spaces in folders for the long run... thanks you!
 
as a electronic engineer who never studied software development
Actually, the differences between a standard c/c++ program and an Arduino ino sketch are marginal. Mostly you need to take care that you declare your functions before you use them. Easiest is to write them on top of the sketch instead of the bottom as is often done in Arduino sketches. It is the same as you are used to when you use a variable in a function. You need to declare it before you use it.

Just give it a try. All you need to do is to chose "Makefile" on settings tab before you open an empty project folder. vsTeensy will generate a small blink sketch from which you can start working.

but probably I should stuck to arduino IDE completely, and don't dream about VScode
No, why? Until know all the bugs where on my side :). Don't hesitate to ask questions. There are a lot of nice people around here who are more than willing to help.

I will just remove all the spaces in folders for the long run
Spaces in paths are never a good idea, but of course vsTeensy should be able to handle this. I'll publish a new version with the fix later today.
 
See here https://github.com/luni64/VisualTeensy/releases for a version (v0.9.9.2) hopefully able to handle spaces in paths. I also activated the build cache which will accelerate Arduino-Builder builds a little bit. The cache is located at {projectFolder}/.vsteensy/cache. A build | clean will clean the cache additionally to cleaning the binaries in .vsteensy/build

Let me know if it works for you.
 
Apologises if it's already been said or it's offtopic to the actual state of the thread (didn't have time to read every post) but I'm using PlatformIO for compiling Teensy and Arduino stuff in VSCode and it works wonders. I set it up in under a minute and was ready to go, haven't given me any problems yet, so it's worth a try for simplicity
 
Nothing to apologise! PIO is well known around here. If you like it just use it. It is a really great piece of software.

If you are interested why VisualTeensy is around I recommend to read through the thread or the documentation. Well, the thread probably is too long now for reading through :)

The main difference between vsTeensy and PIO or the other build systems I'm aware of is that it was developed to remove dependency on your current environment as much as possible.
  • I.e., it doesn't install any extensions or other stuff which might be abandoned or doesn't work anymore in 5 years. Instead, it just uses the native vsCode capabilities to build and upload
  • It tries to keep all project and build relevant files, the Teensy core and the used libraries in the project folder.
  • It autogenerates makefiles for gnu make to do the actual build. Since gnu make is around since 1976, I'm sure it will be available for longer than one will get Teensy processors :) )
  • Actually, once a project is set up you don't need vsTeensy anymore.
  • Actually, you don't even need vsCode to build (but it makes life easier). If you want, a simple "make all" in the project folder will build your firmware.

For most of the hobby users all this might sound weird and not important at all. But, if you have stuff out in the wild and need to support it a couple of years later, the last thing you want to do is fiddling around with a then incompatible build environment. So, like always, I try to use the right tool for the job at hand.
 
After selecting "File->Save As" from VisualTeensy and creating the project - the default expectation (for me, in any case) would be that this new project is now opened in VisualTeensy. But this is not the case, VisualTeensy still has the "old" project open.

I'd recommend that VisualTeensy automatically switches to the "saved as" project.

I think that will also fix the following unexpected (for me, again) behavior when following this process in VisualTeensy:
1. File->New Project
2. Change project settings, add libraries, etc.
3. File->Save As...

I'd now expect to find a single project with my "saved as" name. But instead there are two projects: one called "newProject", one with my "saved as" name. And the libraries are added to "newProject", NOT my project!

(but perhaps these "funnies" are due to me installing a number of versions of these tools while trying to fix some other problems? So if you can't recreate this issue feel free to ignore.)
 
Thanks for spotting this. Actually, I always generate an empty folder and then 'open' this folder as project. This is probably the reason why I never stumbled over it. I'll have a look but this may take a few days.
 
Back
Top