Go for Particle Argon, Boron or Xenon
Tags: particle, tinygo, go, beginners
Published: 2020-04-16 13:57:30

---
title: Go for Particle Argon, Boron or Xenon
published: true
date: 2020-04-16 13:28:57 UTC
tags: Particle,TinyGo,Golang,beginners
canonical_url: https://suda.pl/go-on-particle-argon-boron-or-xenon/
---

 ![Go for Particle Argon, Boron or Xenon](https://suda.pl/content/images/2020/04/Argon_tinygo.png)

With the release of **TinyGo** 0.13, you can now **write firmware for Particle Argon, Boron and Xenon in Go**:

{% twitter 1250125364321533952 %}

There are some caveats for now, namely:

1. TinyGo can't coexist with the Particle Device OS. Meaning flashing your Go app to the device will erase Particle bootloader and system. It is still possible to restore the device to "stock" but it requires manual flashing of all necessary parts.
2. TinyGo doesn't support Argon's WiFi coprocessor nor Boron's cellular modems yet, meaning for now you can only use the devices offline. Ayke is making progress on support for the [nRF Soft Device](https://github.com/aykevl/go-bluetooth/pull/2#issuecomment-595768670) that allows BLE support (and Mesh in the future) but it's still experimental.
3. You need to use the [Particle Debugger](https://store.particle.io/products/particle-debugger) to do all the flashing. It might be possible to use [Adafruit nRF52 Bootloader](https://github.com/adafruit/Adafruit_nRF52_Bootloader) (same as used for CircuitPython) in the future to allow flashing over the USB.

That being said, running TinyGo might be a nice alternative to [CircuitPython](https://docs.particle.io/tutorials/learn-more/xenon-circuit-python/) if you need more speed. How fast is it? Well, it can handle a real-time flight controller for a drone on Arduino Nano33 IoT with SAMD21 Cortex-M0 at 48 MHz:

{% youtube uWK5jyE0Rm4 %}

Or drive six 32x32 RGB LED matrices on Cortex-M4:

{% twitter 1238889662804045826 %}

Additionally, a strong advantage of TinyGo is that **TinyGo is written in Go** itself! Meaning, you don't need to know C/C++ to understand/contribute or write low-level code.

Got you interested? Let's proceed to the...

# Instructions

### Prerequisites

- [Particle Argon/Boron/Xenon](https://store.particle.io/collections/bluetooth) $11-$55
- [Particle Debugger](https://store.particle.io/products/particle-debugger) $12

### Necessary software

1. Install OpenOCD. If you have [Particle Workbench](https://www.particle.io/workbench/) installed, it should already download it for you to `~/.particle/toolchains/openocd` directory. Make sure the `openocd` binary is in your `PATH`.
2. [Install TinyGo](https://tinygo.org/getting-started/)

### Blinky

Well, that's it really. Now you're ready to go write Go:

```go
package main

import (
	// machine package exposes all hardware available on the microcontroller
	"machine"
	"time"
)

func main() {
	// All the pins are listed here: https://tinygo.org/microcontrollers/machine/particle-xenon/
	led := machine.LED
	// Make it an output
	led.Configure(machine.PinConfig{Mode: machine.PinOutput})
	// Repeat forever
	for {
		// Turn it on (it's active low)
		led.Low()
		time.Sleep(time.Millisecond * 500)

		// And off
		led.High()
		time.Sleep(time.Millisecond * 500)
	}
}

```

Now you can flash your app with:

```sh
$ tinygo flash -target=particle-xenon blink

```

(assuming you save the Go code above in `blink` directory). Also, you should set the `-target` flag to the module you're using.

# Summary

Even although Argon and Boron can't connect to the internet yet, peripherals like UART, GPIO, SPI, I2C, ADC, and PWM are working, and there are already [plenty of drivers](https://github.com/tinygo-org/drivers) for devices like displays, sensors, etc.

I hope you'll have fun with TinyGo and if you like to chat about it or contribute, feel free to join the [Slack channel](https://gophers.slack.com/messages/CDJD3SUP6/) and check out the [GitHub repos](https://github.com/tinygo-org).