Blinking An Arduino LED, In Julia

The Julia programming language is a horrible fit for a no-frills microcontroller like the ATMega328p that lies within the classic Arduino, but that didn’t stop [Sukera] from trying, and succeeding.

All of the features that make Julia a cool programming language for your big computer make it an awful choice for the Arduino. It’s designed for interactivity, is dynamically typed, and leans heavily on its garbage collection; each of these features alone would tax the Mega to the breaking point. But in its favor, it is a compiled language that is based on LLVM, and LLVM has an AVR backend for C. Should just be a simple matter of stubbing out some of the overhead, recompiling LLVM to add an AVR target for Julia, and then fixing up all the other loose ends, right?

Well, it turns out it almost was. Leaning heavily on the flexibility of LLVM, [Sukera] manages to turn off all the language features that aren’t needed, and after some small hurdles like the usual problems with volatile and atomic variables, manages to blink an LED slowly. Huzzah. We love [Sukera’s] wry “Now THAT is what I call two days well spent!” after it’s all done, but seriously, this is the first time we’ve every seen even super-rudimentary Julia code running on an 8-bit microcontroller, so there are definitely some kudos due here.

By the time that Julia is wedged into the AVR, a lot of what makes it appealing on the big computers is missing on the micro, so we don’t really see people picking it over straight C, which has a much more developed ecosystem. But still, it’s great to see what it takes to get a language designed around a runtime and garbage collection up and running on our favorite mini micro.

Thanks [Joel] for the tip!

11 thoughts on “Blinking An Arduino LED, In Julia

  1. “By the time that Julia is wedged into the AVR, a lot of what makes it appealing on the big computers is missing on the micro…”

    Just because something is doable, doesn’t mean it should be done.

    1. This is HaD, where doing impractical stuff because you can is a tradition. I think transcompiling code before natively compiling it for the platform is a terrible idea but I applaud that someone managed to do it for Julia/AVR.

      That said, encouraging people to use transcompiled code on any MCU is something I would frown upon. Also, garbage collected languages are a really bad idea for small MCUs.

      1. Garbage collection is a feature that you can choose to use or not. If you don’t allocate memory (use only static variables) there will be nothing to collect, and no impact.

      2. Yeah, but if you go through the writeup, you can see that he’s pretty sensitive to what the end result is in machine code, and takes steps to make it come out like it should.

        I totally hear you about naive transcompilation, but this ain’t that.

  2. I thought this was going to be what i did just 2 weeks ago, which was to read a result file with Julia on a laptop and send the information to an Arduino board through (virtual) serial, which runs an effect library to show effects on LEDs based on those results.

    I was wrong.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.