How to program the teensy without pushing the button

bc10000

Member
Hello, I am working on a project that requires me to upload new code onto the teensy without using the push-button.

I know there are some IDE addons (visual micro for visual studio) that can automatically upload the code to the teensy by configuring the
Teensy Loader to function in automatic mode and send a programming request over USB port.

I am not sure how to duplicate this functionality.


I investigated the log output of the teensy loader when visual micro programs the chip and here is what I see.

Code:
11:30:13.572: remote connection opened
11:30:13.572: remote cmd: "comment: Teensyduino 1.37 - WINDOWS (teensy_post_compile)"
11:30:13.573: remote cmd: "status"
11:30:13.573: status data sent
11:30:13.574: remote cmd: "dir:C:\Users\Mark\AppData\Local\Temp\VMBuilds\FUM\teensy36\Debug\"
11:30:13.575: remote cmd: "file:FUM.ino.hex"
11:30:13.585: File "FUM.ino.hex". 63860 bytes, 6% used
11:30:13.591: remote cmd: "status"
11:30:13.591: status data sent
11:30:13.602: remote connection closed

11:31:11.436: remote connection opened
11:31:11.439: remote cmd: "comment: Teensyduino 1.37 - WINDOWS (teensy_reboot)"
11:31:11.440: remote cmd: "status"
11:31:11.442: status data sent
11:31:11.449: remote cmd: "status"
11:31:11.450: status data sent
11:31:11.552: remote cmd: "status"
11:31:11.554: status data sent
11:31:11.655: remote cmd: "status"
11:31:11.656: status data sent
11:31:11.757: remote cmd: "status"
11:31:11.758: status data sent
11:31:11.859: remote cmd: "status"
11:31:11.860: status data sent

//Data transfer happens after this point


Any help would be greatly appreciated. I am not sure if someone else has asked this before, but I tried to look it up and I couldnt find much useful information.

My entire goal is to duplicate the visual micro upload functionality without using visual micro.

I hope I am being clear.

Thank you
 
This works as default on Windows with IDE and TeensyDuino, as long as the sketch on the Teensy has an active USB interface running.

Note: The 'Auto' indicator on Teensy must also be 'Green' selected and not Grayed.

Try it with BLINK example and make sure that when compiled that this is selected on menu: Tools / USB Type: "Serial"

Any subsequent uploads should work without the Button, as long as USB was part of the compile ( it doesn't have to be only "Serial" ) and the Teensy is properly running ( bad code can take the Teensy offline and the USB functionality with it. )
 
Thank you for the reply.

I am currently programming the teensy using visual micro and the process you mentioned above.

However, sometimes I am required to ship out new code to my clients. Those clients have no idea how to program or what a teensy is.

my entire goal is to give them a hex file that they can upload using the teensy loader program.

however the teensy loader program requires the push button on the teensy to work. The client does not have access to this push button, so i am trying to figure how to how upload the code automatically without pushing a button (like visual micro does).

Thanks.
 
Visual Micro is different IDE - but not in regard with the IDE's ability to upload with no button.

Not using the IDE as noted is the difference. If the Teensy is online with active USB then Teensy.exe should see it and be able to Load a HEX file to it with no button.

Is there a program active that is connected over USB to the Teensy? That connection must be closed to allow Teensy.exe to communicate.
 
Thank you for the quick reply.

There are no other programs running on my machine besides the Teensy loader, so the port should be ready to be used by the loader.

It is to my knowledge that the "The Teensy Loader program communicates with your Teensy board when the HalfKay bootloader is running", and in order to run the halfkey the push button on the teensy must be pressed.

I confirmed this in practice as well.

The PC detects the teensy, however the loader does not until i press the push button.

Thanks again.
 
What OS? Somehow TeensyLoader is not seeing the Teensy over USB.

My machine is in an odd state just now - I need to reboot - I am not seeing the Teensy online properly ... have you tried a reboot?
 
I am on windows 10 (with the latest updates), and I have rebooted yes.

So you are saying that the teensy loader detects your teensy and is able to upload hex files to it without pushing the button on the teensy?
 
It seems I see the same behavior on Teensy Loader as you - without the IDE to push the upload the option to upload even a named HEX is gray.

The tool I use most often for many reasons - is Koromix/tytools/releases - it just runs from a directory and can upload a HEX and see the Teensy and RESET it or Upload when connected. It is documented on the forum here : Teensy-Qt
 
Hi all, I found a way to remote update Teensy boards with the following setup. Thank you defragster for the tip about the tytools software. My solution is a bit hacky but it works, so I thought I should share for anyone else interested:

- `tycmd reset` will set the Teensy in bootloader mode. The terminal message will state the reset failed, but you will see the Teensy is now in the "constant red lamp" mode.
- `teensy_loader_cli --mcu=TEENSY41 -wv main.ino.hex` will upload the new sketch to the Teensy. For some reason the first upload attempt will return Programming...error writing to Teensy, but running the same command again will succeed.

As preparation I had to compile the sketch and get the resulting `.hex` version of the Arduino sketch, as well as install the tytools package and the teensy_loader_cli package.
- I had to use both programs because the "teensy_loader_cli" requires the user to press the pushbutton before the program can be uploaded. The tycmd software is able to circumvent the physical button press with the reset command, and so the two of them together makes it possible to remote update the Teensy :)

I am doing this on a collection of Teensy 4.1 boards connected via a USB hub to a Linux computer. To manage uploads to several boards, you can type `tycmd list` to get the list of connected Teensy serial numbers. `tycmd reset --board SERIAL_NUMBER` will set the specific board in bootloader mode. As far as I know, the teensy_loader_cli tool will simply upload the sketch to the first board it registers, but it will only register the boards in bootloader mode. So once you've reset all the desired boards, you can run the teensyloader repeatedly until all boards are updated.
 
I should have mentioned that I am working on a headless Linux computer, so I can't use GUI software since I'm forced to do everything through the command line. If I understand correctly the teensy_reboot is a software tool included when you install the teensy_loader GUI version (?), but I am forced to use the teensy_loader_cli version which seems to not be able to set the Teensy in bootloader mode.

However just for curiosity's sake I did connect a Teensy to my Windows PC and ran the teensy_reboot.exe. Couldn't get it to run.
- If I run teensy_reboot.exe, there is no response (I have the teensy.exe windows open).
- If I manually press the program button, and then run teensy_reboot.exe, the teensy.exe GUI window tells me "Arduino is attempting to put Teensy into Program Mode", but it's stuck there and won't proceed.
 
`teensy_loader_cli --mcu=TEENSY41 -sv main.ino.hex` works for me, without anything else. It uses the -s flag instead of -w, which means it will attempt to reboot the first Teensy it finds. Might not be suitable for all situations, but works fine for me with no additional commands. It also works without the GUI, which teensy_reboot does require.
 
Hi DaveAK, thanks a lot, you are absolutely right. I tried it now, and it works fine. There is one small catch: I can't seem to choose which board to reset.

That is the last thing that tycmd offers that I don't think the teensy_loader_cli is able to: I can list each connected Teensy from their serial numbers with tycmd list, and choose which ones to set into bootloader mode. I have a system with multiple Teensies connected to the same USB hub, so if I want to just update one of them, I can type e.g. tycmd reset --board 1234567 if the serial number is 1234567. Once I have reset all the chosen boards, I just run teensy_loader repeteadly to update each of them in turn, leaving the non-reset boards alone.

If you know whether this precision can also be achieved with teensy_loader_cli, then I would be very happy to learn about it. It would save me the need of installing the tycmd package.
 
There is one small catch: I can't seem to choose which board to reset.
Yeah, it does have that limitation as noted in the documentation. It works for me as I only have one Teensy to choose from. The -r flag allows you to select the Teensy using additional hardware to control the Teensy PROGRAM pin, but I haven't implemented this yet, and it probably wouldn't work in your scenario unless you wanted to add an additional device to control each Teensy.

I have a seamless setup where my project runs a Teensy 4.0 and a Raspberry Pi Zero W. I develop and compile on my desktop PC using VS Code and arduino-cli and then transfer the hex file to the Pi, which in turn uploads it to the Teensy via a Python script running teensy_loader_cli. This Pi could, (and eventually will in my case), control the PROGRAM pin, and so could control many PROGRAM pins. It just all depends on your overall requirements. I'm really pleased with my setup but realize it may not fit anyone else's needs. (The Pi runs headless with the Lite Pi OS, so no desktop and no GUI Loader. Since I compile on my desktop for the speed this isn't a problem for me.)
 
Back
Top