Upload an Arduino sketch from Julia

To upload a sketch (i.e. an .ino file) to an Arduino I normally just use the Arduino IDE. But it would be amazing if there was a way to do this from Julia. Ideally, this would involve some wrapped binary that would work cross-platform (ehm, on an RPI) regardless of the system’s existing libraries. Some cool advantages would be the ability to generate the sketch as a function of some Julia parameters, upload the generated sketch, and have everything work like that. It would make the whole thing a lot more dynamic.

Does anyone have some input about that?

The easiest route is to call an existing external command-line tool, such as avrdude (comes with Ubuntu Linux, etc.) from Julia with run(). The installation scripts for that will already have taken care of USB library dependencies, setting up device permissions to access the right USB device files in /lib/udev/rules.d/60-avrdude.rules, etc. Why reinvent the wheel?

If you wanted to do it in pure Julia for some reason, without external processes, you’d have to read the relevant AVR application notes on their in-system programming protocols (e.g. STK500 protocol). If your device supports in-system programming via USB CDC, you could use LibSerialPort.jl to get there in a portable way.

2 Likes

Indeed. So what I meant was to add some program to GitHub - JuliaPackaging/Yggdrasil: Collection of builder repositories for BinaryBuilder.jl
and now I have a candidate program:

I found this: GitHub - raimue/avrdude: AVRDUDE – AVR Downloader/UploaDEr which might make it easier to add to Yggdrasil. Seems like the last release was 9 years ago.

“I found this [random github fork]” does not sound like best practice, if the latest release (16 Feb 2016) is available in the official repo with

svn checkout https://svn.savannah.nongnu.org/svn/avrdude/tags/RELEASE_6_3 avrdude-6.3

You could use git with

git svn clone --stdlayout https://svn.savannah.nongnu.org/svn/avrdude

but the clone will be very slow, and messy as their subversion repository doesn’t quite follow the standard trunk/branch/tag layout correctly.

Considering that the Linux incarnation will require root privileges to install the udev rules, I think encouraging the user to just install the OS provided version might be the preferable route here.

1 Like

ok, thank you very your solution!

You can compile C++ sources to arduino and upload directly with ino (python).

I’ve not used this for a long time, but in case, I’ve made a lib with tdd in c++ for arduino and documented a bit the way to do.

https://github.com/apieum/thermocouple

Having a tool in julia like ino would be nice.