Working with TinyGo on Arduino

Building microcontroller projects is a great way to level up your electronics and programming skills.

The purpose of this post is to share some setup instructions to get you up and running with your Arduino Uno and TinyGo as quickly as possible.

TinyGo

TinyGo is an open-source project designed to bring the Go programming language to microcontroller devices. It reuses libraries in Go language tools along with LLVM to compile languages written in Go for various target microcontrollers. At the time of writing the TinyGo project supports 53 different boards however this post focuses on the Arduino Uno board.

Here are some useful resources for getting started;

The avr-gcc compiler takes high-level code and creates a binary source that can be uploaded into an AVR microcontroller.

Getting Started

If you are still undecided about getting into microcontroller development then check out the following links which may help whet the appetite.

Components & Dev Environment

I’ll be using the following components for our starter project.

Installation & Setup

The TinyGo Getting Started page contains instructions for installing TinyGo on various OS, including Docker.

Configuring Goland IDE

When TinyGo is installed on your local machine it includes a number of example projects discoverable under the src/examples folder. We will use the project named blinky1. Open the project using your Goland IDE.

Once you have imported the project we have a couple of settings to update to ensure the IDE recognizes the TinyGo libraries our project is using. Navigate to File -> Settings -> Go -> GOPATH

Now let's get the build flags for our TinyGo compiler. Do this by running the command tinygo info -target arduino ( Swap out arduino if using another board)

In Goland once again navigate to File -> Settings -> Go -> Build Tags & Vendoring. Update the build flags which we discovered in the previous command.

Flash to Hardware Device

After installing Go, TinyGo, and configuring Golang our blinky1.go source should now appear without errors in our editor.

We can now flash the code to our target device.

  • Determine target port by opening Device Manager -> Ports and check which port your device is connecting on.

The LED will illuminate and then extinguish every 5000 milliseconds.

Troubleshooting

Ensure you are using a version of Go that is supported by the TinyGo compiler.

Tech Lead | AWS Community Builder | AWS Solutions Architect Pro | Passionate about learning | Languages include Java, Go, Typescript, and more recently Rust