An Introduction to TinyGo, and The Tools That Will Help You Flourish

An Introduction to TinyGo, and The Tools That Will Help You Flourish

TLDR (Skip to Avoid Spoilers)

Introduction

How does a satellite tell the time? How does a doorbell use more Wi-Fi than watching a cat video? How does a pregnancy test run Doom? I don’t know.

But I'm pretty sure it has something to do with microcontrollers, the Internet of Things and perhaps, one day, TinyGo.

TinyGo Logo attached to a picture of a satellite
(To go big you gotta start small, this and other puns coming soon to an article near you)

What’s TinyGo?

Now, if you’re already a TinyGo aficionado do feel free to skip ahead to where I talk about some tooling that could help you to create the next small thing.

In short (lol), TinyGo is a “Go Compiler For Small Places”. It allows you to create and run Go programs on a vast array of popular microcontrollers (including the Raspberry Pi Pico), as well as produce WebAssembly (WASM) Code.

If you’re like me, you’re probably not entirely sure what this all means. This talk “Small is Going Big: Go on Microcontrollers” is an excellent introduction.

TinyGo: Getting the upper hen (GopherCon UK 2022) shows that the size of “Hello World” compiled using Go 1.18.5 was 1.8MB, but using TinyGo 0.24.0 was only 29KB (Over 60x smaller, and small enough to run on an 8-bit computer!).

I'd also highly recommend checking out the full video of the talk, once it has been fully released.

Why is this useful?

With modern phones being able to store entire operas in 4k, do you really need a program that’s only a few KBs? That was one of my early thoughts.

But microcontrollers are everywhere. Think about your old scientific calculator, or digital clocks, heck even your microwave has a microcontroller in it and it's probably using C.

Go, as a language, has largely been restricted from this realm of microcomputing because it was simply too chonky!

(And cute!)

However, even with the explosion in popularity of hobbyist microcomputing there are still significant barriers to entry. Especially as the more dominant languages in the space are C and C++.

This is why TinyGo is really starting to make some waves. Go is notorious for being relatively easy to pick up. TinyGo could be the key to getting more developers interested in microcomputing, and even WebAssembly, though let’s not dare to dream.

The easier it is for people to get involved, the greater the chance there is for creativity, collaboration and completely different points of view which can lead to incredible innovations.

Sounds exciting right? Good! Are you ready to get started?

Awesome Tools For Getting Started

Tiny Go PlayGround

An excellent starting point. Modeled after the Go Playground. You get to try out TinyGo in your browser, along with a UI of some of the supported microcontrollers. You can see how your code might play out in the real world. Additionally the Playground is even using TinyGo for WebAssembly.

VsCode TinyGo Plugin

Code Completion, Auto Imports, Automatic GoRoot and GoFlags Setup

If the last part about GoRoot/GoFlags may seem a bit odd, check out this explanation on IDE Integration. As a newcomer I’m glad the VSCode and GoLand plugins (spoilers) can handle this for you.

TinyGo Preview

The same preview that can be found on the Playground, has now recently been added into the plugin. Make sure you are working with the supported microcontrollers and you should be able to see the preview window.

GoLand TinyGo Plugin

Code Completion, Auto Imports, Automatic GoRoot and GoFlags Setup and much more!

Now, this one is pretty neat as it allows you to work with TinyGo while having an entire Go IDE at your disposal. Once you have the plugin installed the process of creating a TinyGo Application becomes built into GoLand itself.

This means while working on your application not only do you get the usual quality of life benefits mentioned above, as well as a few hidden gems and shortcuts. You can also create TinyGo Applications in the IDE and select from a wide range of ‘Hello World’ examples.


TinyGo Code Inspections

The plugin also includes code inspections to highlight packages that are not yet implemented in TinyGo. This can be found in Preferences/Settings -> Editor -> Inspections.

Save Multiple Run Configurations

You can build and create multiple different run configurations that can be easily accessed from the editor. (The below image displays some of the defaults)

So, if you ever do need custom variables or different tweaks at runtime you can have them saved and easily alternate between your configurations.

Join The TinyGo Community!

One thing that’s in common with all the above is that they were all built by the community, for the community.

Each tool is open source (TinyGo PlayGround, VSCode Plugin, GoLand Plugin) and open to feedback and contributions. I believe GoLand has an Issue Tracker you can submit to and the #goland channel in the Gophers Slack

Similar to TinyGo, they are all in their early stages, so will only improve as time goes on, but the first step is getting involved!

It’s definitely trickier to build your own gameboy game using TinyGo, than creating your first web application in Go. However, microcomputing is still a niche space, so don’t worry if you ever get stuck or find it difficult and there’s no need to Go alone!

The TinyGo community is growing every day. You can join them in the Gophers Slack on the #tinygo channel and follow them on Twitter to keep track of the many wondrous things being built, on what may truly be the next big frontier in Go.

Good luck out there!