Arduino builds using Command lines for teensy using PuTTy or the like

Status
Not open for further replies.

KurtE

Senior Member+
There are times, when I would like to be able to do Arduino builds with using a GUI. Often this is to ARM boards like the RPI, but other times it may be to a different Linux or windows machine.

I am currently using KiTTy on my machine which is simply an updated version of Putty.

There is information about the Arduino Command line up at: https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc

In my current case, I am trying to build for a Teensy 3.2 connected up to an RPI3 board. On the RPI3 I setup Arduino and Teensyduino (beta 2 as 3 was not up when I last tried). I setup Arduino using a VNC window to begin with. I then downloaded stuff to the RPI through command line or WinSCP.

I added the path to the Arduino install to my path: export PATH=~/arduino-1.8.1:$PATH

So I try building blink example program, using the command line:
Code:
arduino --verbose-build --upload --preserve-temp-files --port /dev/ttyACM0  ~/arduino-1.8.1/examples/01.Basics/Blink/Blink.ino
Some of this is not needed now like the preserve... But when I first started this, the command would successfully build the blink.hex file, but the teensy after build will fail to run as it does not have the GUI...

So: I downloaded the sources for: teensy_loader_cli
and built it. I was then able to program the T3.2 with it :D

But thought it would be nice to be able to do it from the main Arduino command line. First problem I ran into was was not sure how to convert from the build platform names (boards.txt) to the processor type names that this app wanted. So I edited the app and added option to instead use names like:
teensy_loader_cli --mcu:TEENSY31 ...

Edit: Forgot to mention: I put in Pull Request for this: https://github.com/PaulStoffregen/teensy_loader_cli/pull/36

I then edited platform.txt: I commented out the post build section:
Code:
## Post Build - inform Teensy Loader of new file
#recipe.hooks.postbuild.1.pattern="{compiler.path}/teensy_post_compile" "-file={build.project_name}" "-path={build.path}" "-tools={compiler.path}" "-board={build.board}"

And changed the Teensy Loader section:
Code:
## Teensy Loader
#tools.teensyloader.cmd.path={runtime.hardware.path}/../tools
#tools.teensyloader.upload.params.quiet=
#tools.teensyloader.upload.params.verbose=-verbose
#tools.teensyloader.upload.pattern="{cmd.path}/teensy_post_compile" -test "-file={build.project_name}" "-path={build.path}" "-tools={cmd.path}" "-board={build.board}" -reboot

## Teensy Loader Command line
# ~/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY31 -v -w -s /tmp/arduino_build_629456/Blink.ino.hex
tools.teensyloader.cmd.path={runtime.hardware.path}/../tools
tools.teensyloader.upload.params.quiet=
tools.teensyloader.upload.params.verbose=-verbose
tools.teensyloader.upload.pattern=/home/pi/teensy_loader_cli/teensy_loader_cli "--mcu={build.board}" -v -w -s "{build.path}/{build.project_name}.hex"

Right now it is not overly clean but it appeared like it worked :D

Next up try downloading real program to the RPI3 and see if that works...
Also learn more on proper parameters on command line to specify more of the options like Board, like cpu speed...

But progress!
 
Last edited:
Could FrankB's .def's file be used to fill in those items ( I never tried that myself yet ) - or is that uniquely pulled in by the IDE?

Would this same cmdline work on Windows - or is it linux specific?

Two instances of the IDE can do unique boards, but Sublime and Stino can only have one unique instance. Using external editor Sublime the IDE can be open to run to one board while Sublime does another. CmdLine would be a way to do multiple without always swapping board settings if it had full setting control.
 
Not sure, about Frank's stuff if it can do that part or not... Maybe worth a look.

As for windows. If you look at the Arduino command line reference link I showed, it mentions that for windows, you need to use the command: arduino_debug

I tried launching it from a command prompt and it ran all the way through and went to tyCommander to upload...

D:\arduino-1.8.1>arduino_debug.exe --verbose-build --upload c:\Users\kurte\Documents\Arduino\Github\Teensy_Arbotix_Pro\Teensy_Arbotix_Pro.ino
 
Thanks Kurt - Great that it still hands off to TyComm! ... Saw it work!

Added this to use a fixed TMP Build path so it doesn't recompile ALL each time - and also TyComm sees the same name and won't prompt for device to upload after the first:
I:\arduino-1.8.1\arduino_debug.exe --pref build.path=.\bld_tmp --verbose-build --upload d:\Users\defragster\Documents\GitHub\AutoCorr_Freq_detect\Acorr\Acorr.ino

Using that bare update it uses the last used Tool/Board info from preferences.txt - I had to Exit the IDE to get that to SAVE as it had changed. The edit to platform.txt works with all three:: CmdLine, IDE, Stino.

Interesting to see how .defs works - let me know if you try it first. I haven't found the scheme for this to work for a named Teensy## :: "--board package:arch:board:eek:ptions"

Kurt: Do you see this and a whole lot more on each compile - default startup loading ??
Loading configuration...
Initializing packages...
Index error: could not find referenced tool name=avr-gcc version=4.8.1-arduino5 packager=arduino
Index error: could not find referenced tool name=avrdude version=6.0.1-arduino5 packager=arduino
Index error: could not find referenced tool name=arm-none-eabi-gcc version=4.8.3-2014q1 packager=arduino
Index error: could not find referenced tool name=bossac version=1.6.1-arduino packager=arduino
 
Last edited:
Hi Defragster: Thanks for the hint for the fixed TMP build path to keep things from building over and over...

I have not yet played with the .defs. Again look interesting.

So far my main interests have to do with simple updates from Linux over a SSH connection. The idea is that have the boards on the Robot, might be nice to update directly without having to change the wiring and connect to my main pc... With current HAT board it may not be as interesting as I may not actually connect the USB of the Teensy to RPI, but instead do communications through UART... But I may still hook it up to make it easier to do remote debugging (Serial outputs)

I have not seen the messages you are mentioning... Maybe has something to do with different Board types and platforms you have downloaded?
 
It seems to rebuild as needed on speed change - and the problem I had trying the same was case match on naming - I see now it is the prefix. of the board in boards.txt - not any of the other variations.
--board teensy:avr:teensy36:speed=120

I updated to 1.36b4 and that forced a rebuild of course. Also that says that no edit was needed to platform.txt or boards.txt for it to work.

I scanned the defs.h file on the other thread - am I right it just puts defs.h everywhere as an added build item?

If I read this right:
--preferences-file filename
Read and store preferences from the specified filename instead of the default one.

Then a series of device/build specific preferences.txt files could be used and pointed to from the cmdline. Here's some of the obvious things I see look like this:
board=teensy36
sketchbook.path=i:\tcode
software=ARDUINO
target_package=teensy
target_platform=avr
custom_keys=teensy36_en-us
custom_opt=teensy36_o2std
custom_speed=teensy36_240
custom_usb=teensy36_serial

To get a full list doing a diff after exiting the IDE 2-3 times with different build setting should show them. Perhaps start UNO, then T_3.2, then T_3.6? Some could com from CMDLINE.

<edit>: I'll install SubLiMerge and do this as my first DIFF test.
 
Last edited:
And now for some other semi random thoughts here.

I think that I can make this work reasonably well for myself. But I also wonder if it would make sense to try to setup to do it somewhat differently. Sort of along the line I remember doing with Eclipse to Intel Edison.

That is suppose instead I simply build the Teensy program on the PC, then use some remote command shell, that uploads the hex file to the RPI (in this case), which then programs the Teensy... Either try to run a remote command. Or potentially have a simple program on the RPI, that if it finds some specific file has been updated, run the teensy_loader_cli to upload it... (or maybe it is the teensy_loader_cli that is running in background...)

Again I know that this may be somewhat random, but wonder if that would make sense.
 
Seems to make more sense than being random - if you don't need or want to build on RPI - and the RPI is connected - having it upload as needed would be much more straightforward.

One less dev environment to setup and maintain and manipulate - and you do the dev elsewhere as needed already. Pushing the HEX to upload then logging in to upload - or other auto method as justified.
 
So I thought this morning I would play around some with my Randomness ;)

So am doing some editing of my sketch on my PC and then I do a build... Actually I am doing the export compiled binary command, which puts the hex file in my sketch folder.

I have a WinSCP session running to my RPI3 (as well as a Kitty window or two)... So when the build finishes, I use winscp to copy the file to the RPI3...

On the RPI3 I install inotify tools: apt-get install inotify-tools

I also wrote a real stupid shell script:
Code:
#!/bin/sh

while :
do
	inotifywait Teensy_Arbotix_Pro.ino.TEENSY31.hex
	~/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY31 -v -w -s Teensy_Arbotix_Pro.ino.TEENSY31.hex 
done
Note: this is using my updated version of the teensy_loader_cli, which takes friendly names (PR was merged yesterday)
So in a putty window I started up the script:

Then when I used winscp to download the file to the RPI, I saw in my putty(KiTTY) window:
Code:
pi@raspberrypi:~/Arduino/Github/Teensy_Arbotix_Pro $ ./auto_upload.sh
Setting up watches.
Watches established.
Teensy_Arbotix_Pro.ino.TEENSY31.hex MODIFY
Teensy Loader, Command Line, Version 2.1
Read "Teensy_Arbotix_Pro.ino.TEENSY31.hex": 0 bytes, 0.0% usage
Soft reboot performed
Waiting for Teensy device...
 (hint: press the reset button)
Found HalfKay Bootloader
Read "Teensy_Arbotix_Pro.ino.TEENSY31.hex": 24304 bytes, 9.3% usage
Programming........................
Booting
Setting up watches.
Watches established.
So it looks like a possibility. Would be nice to hack up (or better yet) integrate a way to have Arduino and/or SublimeText with Stino to be able to do the part of winscp... i.e. a wifi uploader.
 
Would be nice to hack up (or better yet) integrate a way to have Arduino and/or SublimeText with Stino to be able to do the part of winscp... i.e. a wifi uploader.
Putty / Kitty include a command line scp version, pscp.exe. It can run without interaction, if you set up public key authentication.

You could replace the Teensy Loader invocation, just look at how TyTools modifies "arduino/hardware/teensy/avr/platform.txt".
 
Thx KurtE to point me to this solution (from this thread). Just downloading the hex file and using the cli loader seems a much simpler solution that switching development IDE.

Am I right that the cli loader doesn't reboot the Teensy into Halfkay like on Windows? If I try to the flash the Teensy, it stays waiting until I manually press the program button (with or without -w flag).
Code:
root@test:/bin/teensy_loader_cli-master# ./teensy_loader_cli --mcu=mk20dx256 -w -v  blink_slow_Teensy32.hex
Teensy Loader, Command Line, Version 2.1
Read "blink_slow_Teensy32.hex": 14324 bytes, 5.5% usage
Waiting for Teensy device...
 (hint: press the reset button)
I'm using a NanoPi Neo in stead of a Rasp Pi, with Ubuntu Core kernel version 4.11.2
 
Last edited:
I am not sure about the reset into program mode... I have not experimented for awhile with this. I need to get back to it.
I do have an RPI3, which I was experimenting with, but prefer Odroids... However currently most of my small linux playing around with is for UP boards and they are Intel based.

Edit: I also keep meaning to try the ty commander tools to see if they work better at the command line as well.

Probably would have to build for this? May look again to see if he has ARM based archives
 
I decided to revive an old thread as I am running into this again. This time with a different Arduino board (Robotis OpenCR) Where I plug the board into UP board (or RPI3 or ...)

Also I have seen others with similar questions about how to remotely update update their Teensy...

What would be nice, is if there was somewhere in the Arduino IDE some dialog maybe somewhat like the Wifi101 firmware updater where it might allow you to enter some stuff for the remote machine:
Hostname/IP address, User name, optional passowrd, maybe remote directory ...

Then it would be great if Arduino had something in it like the pscp, that would copy the hex file to the remote machine. Maybe it could be setup as a "Programmer" so if you select that programmer, you could have the it hopefully update remote.

First pass might be to do SCP and maybe prior to that setup a demon on the remote to do the commands for you. Or maybe better yet, maybe have a remote shell (RSH) defined that runs the appropriate commands on the remote board.

Anyway maybe I am just dreaming, but maybe someone has done some better automation of this?

Or wonder if this is something that should be asked up on Arduino developers list?
 
Quick update (WIP) - But wonder ...

Yesterday, I was able to get my Robotis OpenCR board type, to be able to upload the compiled binary to my UP board :D, I still don't have pieces in place to have up board program it (more on that). Unless interest will probably mainly continue conversation on Robotis or RobotSource forum. But would like some ideas and wonder about maybe how TyCommander is currently integrated.

The OpenCR's boards.txt already had a menu item: Upload method:
Code:
menu.upload_method=Upload method

Which had one item in it, defined like:
Code:
OpenCR.menu.upload_method.UploadMethod=OpenCR Bootloader
OpenCR.menu.upload_method.UploadMethod.upload.protocol=opencr_ld
OpenCR.menu.upload_method.UploadMethod.upload.tool=opencr_ld

So I added another menu item by adding new section like:
Code:
OpenCR.menu.upload_method.pscp=PSCP UP Turtle
OpenCR.menu.upload_method.pscp.upload.protocol=pscp
OpenCR.menu.upload_method.pscp.upload.tool=pscp

When I restart Arduino IDE it shows this new menu item.

Then I added definition for this command in platform.txt... Currently it looks like:
Code:
######
tools.pscp.cmd=pscp
tools.pscp.cmd.windows=pscp.exe
tools.pscp.path=C:/Program Files/PuTTY

tools.pscp.upload.params.verbose=-d
tools.pscp.upload.params.quiet=n
tools.pscp.upload.pattern="{path}/{cmd}" "-pw" "ThePassword" "{build.path}/{build.project_name}.bin" "kurt@192.168.2.12:/home/kurt/Opencr"
Note: I edited the password here.... Also I should tun on the -batch flag to make sure it does not try to prompt...

With this I was able to select my new Upload method and when I do an upload command, it actually used pscp (of Putty install) and sent the file over to my up board :D

So First Question I wonder about is Tycommander integration. Wonder if we could add this menu to Teensy boards.txt and TyCommander could add in second method the user could choose.... May have to try that! That would make it user select able and not all or nothing! Also then add network case as well...

Next Question: Is there an easy way to not have to hard code, the other computers IP address, user name, password... Would be nice if Arduino IDE had way to add menu item that allowed you to enter string to save away...

My quick look at ESP... integration, to update using a Java app, that maybe allows them to select some stuff? Wonder if need to do same... Or maybe start off, can I use environment variables... Or maybe to start off with, maybe can edit Arduino's preferences.txt file and add keys for this...

Next Question: Ok I now have the binary file over on the board that the the OpenCR (and/or maybe Teensy) is plugged into. How to get it to now program the board with the binary. Maybe a few options:
a) Could do like I mentioned above and have simple batch script run on the computer that waits for file changes and then runs the appropriate commands.
b) Wonder if I could add one or more additional command patterns to the upload option, that maybe uses something like plink to generate a command to run on the host... Potentially if the answer to earlier question is to use some external app, like one in Java, than probably it could handle that as well?

Anyway making progress! Suggestions very much hoped for ;)
 
Status
Not open for further replies.
Back
Top