MCH2022

Programming microcontrollers in Go using TinyGo
2022-07-24, 10:40–11:10, Battery 🔋

Go is often thought of as a server programming language, especially one used for microservices. However, I argue that it can also be a good language for much smaller systems: microcontrollers. Especially with the Internet of Things there is a need for a language that is safer, easier to use (harder to misuse) and easier to build and test.


For many years, C has been the dominant language in the embedded world and especially microcontrollers. Almost all embedded systems are written in C. The last few years this has been changing, with new languages being used for this purpose:

  • Rust has seen rapid growth in embedded systems with its focus on safety and expressiveness. It is in fact a great replacement for C, as it is just as low level and efficient as C but without all the footguns. However, many people find this language hard to learn.
  • Another language that's sometimes used is Python, in the form of MicroPython. This is in fact what powers the SHA2017 and MCH2022 badges. While the project is an amazing accomplishment, it still suffers from the fact that the language is interpreted and there are limits to how fast it can be.
  • Some people have also used other languages, such as Lua, JavaScript, Oberon, Forth, Ada, and probably others. I'm not aware of a language that got much further than experimental or very specific uses.
  • Then there is TinyGo, which is a new compiler for the Go language and primarily targets baremetal embedded systems and WebAssembly. This is what I will talk about.

TinyGo is a new compiler for the Go programming language. Its goal is to implement the Go language specification, be able to compile most of the Go standard library, but still optimize well enough so that binaries can run on a range of large and small embedded systems. It optimizes much more aggressively than the main Go implementation and the resulting binaries are able to run on systems ranging from the Arduino Uno, to the BBC micro:bit, to the MCH2022 badge with an ESP32 chip. I believe TinyGo offers most of the ease-of-use benefits of interpreted languages while providing most of the performance benefits of languages such as C.

In this talk, I will cover what kinds of problems C can cause, why Go can be a great fit on embedded systems, an explanation of some optimizations that it does that help lower its code size and RAM consumption, and some examples of projects written using TinyGo. Oh, and of course some demos.

I have been working on TinyGo for the last few years. Before that, I worked on the MicroPython Python interpreter and worked on the IRMA project.

As a child, I have long been interested in electronics. At some point I started to learn programming Python (around the age of 12 or 13) and I have been programming ever since. Around six years ago I learned about the Arduino environment, where my previous interest in electronics was revived with a new power: programmable microcontrollers. I didn't like C much so I started looking into alternatives and found MicroPython. But that wasn't exactly what I was looking for either so I did the naive thing and started the TinyGo project with the goal of making the Go language available for microcontrollers.