Posts | Comments

Planet Arduino

Archive for the ‘TinyGo’ Category

Go — a modern programming language with roots at Google — is one of the new generation languages that would like to unseat C (and C++) for what we think of as traditional programming. It is only for PCs, though, right? Not so fast! TinyGo provides a compiler that — in their words — is for small places. How small? They can target code for the Arduino Uno or the BBC micro:bit. It can also produce code for x86 or ARM Linux (both 32- and 64-bit) as well as WebAssembly. They claim that a recent project to add ESP8266 and EPS32 support to LLVM will eventually enable TinyGo to target those platforms, too.

As you would expect, there are some subtle differences between TinyGo and the full-blown version. The compiler handles the entire program at once which is slower but offers more for optimization. Certain optimizations for interface methods are not used in TinyGo, and global variable handling changes to accommodate moving data from flash to RAM efficiently. TinyGo passes parameters in registers.

Other changes are more profound. For example, there’s no garbage collection yet, so you are urged to not perform heap allocations after initialization. There are also a few other major features not supported. Concurrency in the form of goroutines and channels, cgo, reflection, and three index slices won’t work. Maps are available, but only with certain key types. Because of the missing pieces, many of the packages in the standard library won’t build.

Of course, the other modern language in the same position is Rust and if you were wondering why Go instead of Rust, there’s an FAQ for that. Do you need Go on the Arduino? Maybe not. However, if you are a Go programmer, maybe this opens up some possibilities for you.

We remember a hacker jukebox that used Go. We also remember someone using it on the ill-fated Intel Edison.

A few weeks ago, we announced that Arduino now works with TinyGo, the popular compiler that brings the Go programming language to microcontrollers. We had the opportunity to sit down with Ron Evans, Technologist for Hire, and learn more about the Arduino and TinyGo integration.

Some of our audience knows about Go (we ourselves use it to develop many of our tools). In a few words: what is TinyGo and how does it stand compared to Go itself?

TinyGo is a Go compiler for small places like microcontrollers. TinyGo is written in Go like the standard Go compiler, but TinyGo then uses the LLVM toolchain to compile Go programs to a fraction of their normal size. TinyGo also employs a different runtime implementation in order to target constrained environments.

Why choosing TinyGo over other languages?

If software is eating the world, then Go is eating the world of software. The popularity of Go is still rapidly expanding, and TinyGo helps bring the new “enterprise standard” language down to the smallest of processors. Also as a compiled language, TinyGo can offer substantially better performance and size efficiency than that of interpreted languages like JavaScript and Python.

How does TinyGo compare to embedded python and JavaScript implementations?

One good reason to use Go is the clear and maintainable code that Go insists that you create. Generally speaking, the normal Go tooling that is included with the language itself is what you use when writing TinyGo code. For example, the standard built-in code formatting. TinyGo includes implementations of the Go “net” package targeting the Arduino Nano33 IoT, so you can more easily reuse existing Go code for TCP/UDP or higher level protocols such as MQTT. This really makes it a lot easier to build commercial or industrial IoT solutions.

Another reason to use TinyGo is the ability to utilize Go’s concurrency. TinyGo implements “goroutines” which can greatly simplify your code to take the greatest performance advantage offered by modern 32-bit microcontrollers.

With security in IoT being one of today’s hottest topics, which tools does TinyGo offer that enable the development of secure projects?

There are a number of things that can make development, deployment, and operations using TinyGo good for edge computing applications that require greater security. Since the code is compiled to binary, it is possible to use code signing and other well known approaches for secure computing.

Another is that any device data must be encrypted while in transit from from the device to any cloud storage or analytics. TinyGo on the Arduino Nano33 IoT can use standard APIs for SSL communication to cloud services, such as using the Eclipse Foundation’s Paho MQTT client for Go. This makes it a lot easier for developers to do the right thing the first time when creating applications.

How can TinyGo improve the Arduino ecosystem? How will our existing audience benefit from using it? Will they be able to use the Arduino libraries already existing?

There is a very active community in the Arduino world, with lots of existing useful libraries. We are planning much deeper integration for TinyGo powered by Arduino, more on this in the near future…

Many people love TinyGo because it’s simple yet powerful. Do you see any similarity with the Arduino mission of ‘making technology simple for everybody?'”

Arduino has really pioneered the open hardware movement, and defining clear APIs to devices has been a huge contribution. TinyGo very much tries to embody this same spirit, while at the same time provide an idiomatic Go language programming experience. Combine the sensibilities that have made TinyGo so popular and that are fueling our continuing growth, alongside the amazing capabilities powered by Arduino, and there are no limits to what we can do!

If you want to learn more about TinyGo, click here and here. During Gophercon, Ron Evans ran a hacking session dedicated to the Arduino Nano 33 IoT and TinyGo — you can discover more on this dedicated page on GitHub



  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook