Go handles IoT and embedded work in two ways. On Linux-capable devices such as a Raspberry Pi, standard Go cross-compiles to a single static binary for ARM or RISC-V. On microcontrollers with kilobytes of RAM, you use TinyGo, a separate compiler based on LLVM that supports a large subset of Go. Standard Go is excellent for gateways, edge services and device fleets; TinyGo is for firmware.
The choice between the two decides which libraries, memory limits and concurrency features you can use.
| Aspect | Standard Go (gc) | TinyGo |
|---|---|---|
| Target hardware | Linux, Windows, macOS, BSDs on 32-bit ARM, arm64, amd64, RISC-V and more | Microcontrollers (RP2040, ESP32, nRF52, STM32, AVR boards) and WebAssembly |
| Minimum practical memory | Tens of MB of RAM | Kilobytes to a few hundred KB |
| Runtime | Full garbage collector and scheduler | Small runtime, conservative GC |
| Standard library | Complete | Partial; check the supported packages list |
| Typical use | Gateways, edge agents, device servers | Sensors, actuators, firmware |
TinyGo supports goroutines and channels, but not every package and reflection feature. Always check the TinyGo documentation for your board before designing around a library.
Go builds for another platform by setting environment variables. No toolchain installation on the device is needed, and the output is one file you can copy over SSH or ship in a container.
Use CGO_ENABLED=0 where you can, so the binary has no dependency on the device's C library. Pure Go builds are easy to run in minimal containers.
MQTT is the common protocol for IoT telemetry. The Eclipse Paho client github.com/eclipse/paho.mqtt.golang is widely used. The program below publishes a reading every five seconds, reconnects automatically and shuts down cleanly on Ctrl+C or SIGTERM.
QoS 1 means the broker acknowledges the message at least once. On unreliable links, store readings locally and retry rather than dropping them.
TinyGo exposes hardware through the machine package. This blink program runs on boards that define machine.LED, such as the Raspberry Pi Pico.
Build and flash with tinygo flash -target=pico .. The -target value is the board name, and tinygo targets lists them. The TinyGo Drivers project provides ready-made packages for common sensors, displays and radios.
On Linux boards, libraries such as periph.io and Gobot give access to GPIO, I2C and SPI from standard Go.
GOMEMLIMIT on edge Linux devices and avoid unbounded buffers or queues.context for every goroutine and shut down cleanly on SIGTERM, so updates and restarts do not corrupt state.log/slog and keep log volume bounded on flash storage.go test -race.Yes, with TinyGo, which targets many boards such as the Raspberry Pi Pico, ESP32 and Arduino-class chips. Standard Go needs an operating system and much more memory.
For tight real-time or very small devices, C and Rust still give more control. Go wins on developer speed, safety and networking, which is why it is strong on gateways and edge services.
Yes, but it costs RAM and some CPU. Limit allocations, set GOMEMLIMIT, and test under realistic memory limits.
MQTT is the usual choice for telemetry because it is light and supports QoS levels. HTTP or gRPC suit request and response control paths, and CoAP suits constrained devices.
Use standard Go to build static binaries for Linux-based edge devices and TinyGo for microcontrollers. Pair them with MQTT for telemetry, clean shutdown with context, bounded memory and secure connections. Hide hardware behind interfaces so most of your code is testable on a normal computer.