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 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;
- TinyGo Homepage — https://tinygo.org/
- TinyGo Github — https://github.com/tinygo-org/tinygo
- Go Homepage — https://golang.org/
- TinyGo on Windows — https://tinygo.org/getting-started/windows/
- AVR-GCC compiler — Stanford.edu
- Download AVR-GCC for Windows — https://blog.zakkemble.net/avr-gcc-builds/
The avr-gcc compiler takes high-level code and creates a binary source that can be uploaded into an AVR microcontroller.
If you are still undecided about getting into microcontroller development then check out the following links which may help whet the appetite.
- Thinking About Getting an Arduino — https://www.youtube.com/watch?v=5F054MNB1QI
- Building a Life-Size BB8 droid — https://www.youtube.com/watch?v=-QbFvDIyy1k
- Arduino Command Cheatsheet — https://www.makeuseof.com/arduino-commands-cheat-sheet/
- Udemy Arduino course — https://www.udemy.com/course/arduino-sbs-17gs/?altsc=79846
- Arduino Buying Guide — https://www.youtube.com/watch?v=AmRtkXFu3IE&t=1s
Components & Dev Environment
I’ll be using the following components for our starter project.
- Arduino Uno board
- USB 2.0 A-Male to B-Male cable
- Go v1.16+
- TinyGo binary for Windows
- AVR-GCC for Windows — https://blog.zakkemble.net/avr-gcc-builds/
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.
- Place our LED in the 13th PIN on our Arduino board with the negative (shorter) leg placed into the ground pin.
- Flash using command — tinygo flash -target arduino -port COM5 blinky1/blinky1.go
The LED will illuminate and then extinguish every 5000 milliseconds.
Ensure you are using a version of Go that is supported by the TinyGo compiler.