How small can you Go?

Can you use Go on a microcontroller or small system? Don’t answer before you see what TinyGo can do. It’s unconventional, it’s small, it pushes the boundaries of Golang. See what this project is and how you can help it reach its future goals.

Honey, I shrunk Go. TinyGo is a Go compiler for small devices. Go on a microcontroller? Simply phrased: Why?

According to GitHub, the creator Ayke van Laëthem came up with the idea for TinyGo based off Python’s versatility. “My original reasoning was: if Python can run on microcontrollers, then certainly Go should be able to and run on even lower level micros.”

Go, go gadget!

TinyGo is a Go compiler for micocontrollers. With its small memory model, it can run on a single processor core.

From GitHub: “TinyGo uses LLVM internally instead of emitting C, which hopefully leads to smaller and more efficient code and certainly leads to more flexibility.”

Some of the supported features listed are:

control flow

many (but not all) basic types: most ints, floats, strings, structs

function calling

interfaces for basic types (with type switches and asserts)

goroutines (very initial support)

function pointers (non-blocking)

interface methods

standard library (but most packages won’t work due to missing language features)

slices (partially)

maps (very rough, unfinished)

defer

closures

bound methods

complex numbers (except for arithmetic)

It currently supports: ARM (Cortex-M), AVR (Arduino Uno), Linux, and WebAssembly.

Future goals for TinyGo include: web support for WebAssembly and support for more microcontroller boards and new peripherals.

SEE ALSO: Meet zygomys — An embedded scripting language for Go

Check out the blog by Ayke van Laëthem: “Code size optimization for micocontrollers” as a companion course to your tiny programming.

Browse the documentation here. TinyGo installs with Docker.

Helping TinyGo flourish

However, TinyGo still has some goals on the roadmap that it hasn’t yet met. As of right now, here is a list of features without support:

complex arithmetic

garbage collection

recover

channels

introspection

Of course, as you can see above a few of the implemented features are also rough and unfinished.

Go is not a programmer’s first choice when it comes to microcontrollers, and so TinyGo faces a few limitations because of its language. (That award goes to C, which dominates the world of embedded devices and will most likely continue to do so.)

Support for the ESP8266/ESP32 chips may or may not come. From the FAQ: “There are two ways these chips might be supported in the future, and both will take a considerable amount of work”. Read more on that here.

The creator is looking for help on this project, so if you find some bugs or would like to help please pitch in! Help this tiny project grow. Explore the wishlist and see where you can dig into first.

Other alternatives?

If Go is not your speed, there are other solutions.

C and C++ are the top programming languages for embedded devices according to a 2016 survey by IEEE Spectrum. It is a safe bet to say that C will not be dethroned by any other language when it comes to this particular use case. While playing around and pushing the limits of other languages is great, at the end of the day C is there for you.

Rust is a good alternative language for embedded devices. The embedded devices Working Group on GitHub is a great place to get started.

Love Go but want something other than TinyGo for your embedded system? Emgo is an alternative. EMBD is also an embedded programming framework in Go.

Go on and see how small TinyGo is.