A Raspberry Pi Pico project template using TinyGo instead of the C/C++ SDK. This is a companion to the pico-template project, providing the same functionality with Go.
- LED blinking example with serial output
- Support for both standard Pico and Pico W boards
- OpenOCD debugging support
- Multiple flashing methods (picoprobe and UF2)
- Same Make targets as the C pico-template for consistency
-
TinyGo (v0.31.0 or later)
# macOS brew tap tinygo-org/tools brew install tinygo # Linux (Ubuntu/Debian) wget https://github.com/tinygo-org/tinygo/releases/download/v0.31.0/tinygo_0.31.0_amd64.deb sudo dpkg -i tinygo_0.31.0_amd64.deb # Or see https://tinygo.org/getting-started/install/
-
Go (1.21 or later)
# Install from https://golang.org/dl/ -
ARM GCC Toolchain (for debugging and binary utilities)
# Ubuntu/Debian sudo apt install gcc-arm-none-eabi gdb-multiarch # macOS brew install arm-none-eabi-gcc arm-none-eabi-gdb
-
OpenOCD (for flashing via picoprobe)
# Ubuntu/Debian sudo apt install openocd # macOS brew install openocd
- Raspberry Pi Pico or Pico W
- Picoprobe (another Pico configured as a debugger)
- USB cable
pico-tinygo-template/
├── cmd/
│ └── main/
│ └── main.go # Main application code
├── pkg/ # Reusable packages (if needed)
├── scripts/
│ ├── flash # Flash script using OpenOCD
│ └── reset # Reset script using OpenOCD
├── build/ # Build artifacts (created by make)
├── docs/ # Additional documentation
├── go.mod # Go module file
├── Makefile # Build automation
└── README.md # This file
git clone https://github.com/user/pico-tinygo-template.git
cd pico-tinygo-templatemake buildThis creates:
build/main.uf2- For drag-and-drop flashingbuild/main.hex- Intel hex formatbuild/main.elf- For debugging
make flash- Hold the BOOTSEL button while connecting the Pico via USB
- The Pico will appear as a USB mass storage device
- Run:
make flash-uf2
All the same targets from the C template are supported:
| Target | Description |
|---|---|
make or make dummy |
Shows available targets |
make build |
Compiles the TinyGo code |
make prep |
Prepares build directory and shows TinyGo info |
make flash |
Builds and flashes via OpenOCD/picoprobe |
make flash-uf2 |
Builds and flashes via UF2 (BOOTSEL mode) |
make clean |
Removes build artifacts |
make debug |
Starts GDB debugging session |
make openocd |
Starts OpenOCD server |
make reset |
Resets the Pico |
make size |
Shows binary size information |
make strip |
Strips debug symbols from ELF |
make monitor |
Opens serial monitor (115200 baud) |
make test-tinygo |
Verifies TinyGo installation |
make git |
Quick git add, commit, and push |
The main application (cmd/main/main.go) demonstrates:
package main
import (
"machine"
"time"
)
func main() {
// Configure UART for serial output
machine.UART0.Configure(machine.UARTConfig{
BaudRate: 115200,
})
// Configure LED pin
led := machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
// Blink LED forever
for {
led.High()
println("ON")
time.Sleep(100 * time.Millisecond)
led.Low()
println("OFF")
time.Sleep(100 * time.Millisecond)
}
}To view the serial output:
make monitorOr use your preferred serial terminal:
screen /dev/ttyACM0 115200 # Linux
screen /dev/tty.usbmodem* 115200 # macOS-
Start OpenOCD in one terminal:
make openocd
-
In another terminal, start GDB:
make debug
Edit the Makefile:
TARGET = pico # For standard Pico
# TARGET = pico-w # For Pico W (WiFi version)Modify TINYGO_FLAGS in the Makefile:
TINYGO_FLAGS = -target=$(TARGET) -size short -opt=z # Size optimized (default)
# TINYGO_FLAGS = -target=$(TARGET) -size short -opt=2 # Speed optimized
# TINYGO_FLAGS = -target=$(TARGET) -size short -opt=s # Balanced| Feature | C SDK | TinyGo |
|---|---|---|
| Language | C/C++ | Go |
| Build System | CMake | Go modules + Make |
| Binary Size | Smaller | Slightly larger |
| Development Speed | Slower | Faster |
| Memory Management | Manual | Garbage collected |
| Hardware Access | Direct | Via machine package |
| Libraries | Extensive | Growing |
make test-tinygo # Check installation
export PATH=$PATH:/usr/local/tinygo/bin # Add to PATH if needed- Check USB cable (must be data cable, not power-only)
- Try different USB port
- Verify with
lsusb(Linux) orsystem_profiler SPUSBDataType(macOS)
make clean # Clean build artifacts
go mod tidy # Update dependencies
tinygo version # Verify TinyGo version- Ensure picoprobe is properly connected
- Check OpenOCD configuration
- Try BOOTSEL mode as alternative
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Run
make buildto verify - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Original pico-template C project
- TinyGo project
- Raspberry Pi Foundation for the Pico