DEV Community

Cover image for What No One Tells You About TinyGo: Running Go on an Arduino Changed How I Think About Embedded Programming
Yevhen Kozachenko ๐Ÿ‡บ๐Ÿ‡ฆ
Yevhen Kozachenko ๐Ÿ‡บ๐Ÿ‡ฆ

Posted on • Originally published at ekwoster.dev

What No One Tells You About TinyGo: Running Go on an Arduino Changed How I Think About Embedded Programming

What No One Tells You About TinyGo: Running Go on an Arduino Changed How I Think About Embedded Programming

When I first heard about TinyGo, I thought: โ€œCool, Go for microcontrollers... I doubt itโ€™s practical.โ€ Fast forward a month, and Iโ€™m blinking LEDs and handling button inputs with Go on my Arduino Uno โ€” and loving every minute of it.

This blog post isn't just another overview โ€” I'm diving deep into what it's actually like to work with TinyGo, what problems it solves (and doesn't), and how it changes the way you can think about embedded systems development. I'll walk you through a complete example with real code, compare the experience to classic Arduino C/C++, and share how switching to Go on microcontrollers made me a better developer both in the embedded world and fullstack web development.

๐Ÿง  Why TinyGo Is a Game-Changer

Letโ€™s set the scene.

Traditionally, embedded programming means clunky C code, opaque compilers, memory juggling, and lots of trial and error. Yes, itโ€™s powerful, but the learning curve is steep and debugging is often a form of digital voodoo.

Hereโ€™s why TinyGo flips that on its head:

  • โœ… Type safety and powerful tooling from Go
  • โœ… No garbage collection overhead at runtime (TinyGo uses escape analysis to include the smallest possible runtime)
  • โœ… Works on Arduino, ESP32, BBC micro:bit, and WebAssembly
  • โœ… Compiles blazing fast compared to gcc toolchains

As a developer who is also working in web backend systems using Go, being able to reuse knowledge in the embedded space is cosmic-level productivity alignment.

๐Ÿคฏ Real World: Blinking an LED with Button Input in Go

Letโ€™s look at how the same behavior (toggle an LED with a button press) is written in C vs Go.

๐Ÿคข The C Way (Traditional Arduino)

const int buttonPin = 2;
const int ledPin = 13;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ˜ The TinyGo Way

package main

import (
    "machine"
    "time"
)

func main() {
    led := machine.LED
    button := machine.D2   // pin 2

    led.Configure(machine.PinConfig{Mode: machine.PinOutput})
    button.Configure(machine.PinConfig{Mode: machine.PinInput})

    for {
        if button.Get() {
            led.High()
        } else {
            led.Low()
        }
        time.Sleep(10 * time.Millisecond)
    }
}
Enter fullscreen mode Exit fullscreen mode

What do you notice?

  • The structure is cleaner, type-checked, and takes advantage of Goโ€™s standard libraries.
  • No main() void awkwardness โ€” the structure feels like writing any regular Go CLI app.

๐Ÿ”ง How to Get Started

Setting up TinyGo is surprisingly smooth.

Step 1: Install TinyGo

brew tap tinygo-org/tools
brew install tinygo
Enter fullscreen mode Exit fullscreen mode

Or grab it from the official downloads.

Step 2: Install AVR tools (for Arduino Uno)

brew install avr-gcc
Enter fullscreen mode Exit fullscreen mode

Step 3: Write Your .go File (like above)

Step 4: Compile and Flash

tinygo flash -target=arduino uno-led-blink.go
Enter fullscreen mode Exit fullscreen mode

Your Arduino will restart and start running your compiled Go program! Yes โ€” youโ€™re running freaking statically compiled Go code on an 8-bit microcontroller!

๐Ÿ“Š TinyGoโ€™s Secret Weapon: Code Size

Compare these code sizes:

  • Arduino C++ binary for our LED app: ~3.2 KB
  • TinyGo binary for same app: ~2.4 KB

How? TinyGo aggressively compiles only used packages/functions (leveraging Go's linker and escape analysis). And it's not some kind of toy language runtime โ€” apps scale as you'd expect.

๐Ÿš€ Advanced: Using TinyGo with WebAssembly

That same Go code can be compiled and run in the browser. Donโ€™t believe me?

tinygo build -o main.wasm -target wasm yourfile.go
Enter fullscreen mode Exit fullscreen mode

Then serve it using a web app and call Go functions from your JavaScript glue code. Same syntax, shared logic. Itโ€™s a dream come true for teams building fullstack web apps with heavy IOT integrations.

TinyGo opens the door to fully isomorphic Go codebases, spanning browser apps, backend REST services, and tiny embedded devices.

๐Ÿ›‘ Watch Out: Language Limitations

TinyGo isnโ€™t a full Go implementation โ€” it supports a major (and growing) subset of features:

  • No reflection
  • No interface{} (not yet robust, mostly for simple uses)
  • No goroutines on most targets (they compile but run sequentially)
  • No map support in many cases

But you still get:

  • Great error handling (if err != nil)
  • Type-safe APIs
  • Structs and modules
  • Hardware abstraction for GPIO, I2C, SPI, UART, etc

๐Ÿ™Œ Why Use TinyGo Over MicroPython or Arduino C?

Let's be honest, MicroPython is great โ€” but performance is lacking. You donโ€™t want to run real-time sensor loops with tight timing on a MicroPython interpreter.

Arduino C is fast, but unstructured, especially for larger programs.

TinyGo gives you:

Feature Arduino C MicroPython TinyGo
Type Safe โŒ โœ… โœ…
Compile Speed ๐Ÿ˜ โœ… (none) โœ…
Performance โœ… โŒ โœ…
WebAssembly โŒ โŒ โœ…
Modern Syntax โŒ โœ… โœ…

๐Ÿง  Final Verdict: Is TinyGo Worth It?

Absolutely โ€” if you:

  • Already use Golang and want to go to hardware
  • Want safer, more maintainable embedded projects
  • Hate thinking about pointers and memory management in C
  • Want multiple target platforms (microcontrollers, browsers, servers)

TinyGo is not just a developer toy โ€” itโ€™s a serious rethink in how we approach embedded development. Itโ€™s about time we started seeing microcontrollers as part of the modern dev stack, not some archaic island.

๐Ÿ”ฎ Bonus: Hardware You Can Use with TinyGo

  • Arduino Uno
  • ESP32/ESP8266
  • Raspberry Pi Pico (RP2040)
  • BBC micro:bit
  • Adafruit Circuit Playground
  • STM32 chips
  • And moreโ€ฆ

See the full TinyGo supported hardware list here.

๐Ÿงช Try it Now

Donโ€™t just read this โ€” write your first blinking LED in Go! Itโ€™ll change how you view the boundary between software and hardware.

Happy hacking!


๐Ÿ’ก If you need help with bringing your idea to life or building embedded and web connected products using Go โ€“ we offer fullstack development.

Top comments (1)

Collapse
 
leena_malhotra profile image
Leena Malhotra

Running Go on an Arduino isnโ€™t just a hack. It forces you to rethink constraints, and thatโ€™s where real engineering clarity comes from.