Examples can be built for either:
-
Full fledged Go which can run on all platforms supported by Go and the periph peripherals I/O module.
-
TinyGo which has limited Go functionality and built-in peripheral libraries for various microcontrollers.
You need a supported port controller hardware to run these examples. The only one currently supported by this module is the popular FUSB302 by ON Semiconductor. The easiest way to use this chip is to purchase a breakout/development board.
Your best bet here is to run the examples on a platform that provides low latency I2C access such as Raspberry Pi. Following is a partial guide on how to prepare your Pi and hook it up to FUSB302 breakout board:
- Install a linux OS on RPi (easiest method is to use the official RPi Imager.
- Configure I2C
- Ensure
i2c-toolsare installed andi2cdetect -ldetects and lists your I2C bus. - Install
goSDK usingapt update && apt install golang.
| RaspberryPi | FUSB302 |
|---|---|
| Pin 6 (GND) | GND |
| Pin 3 (I2C1 SDA) | SDA |
| Pin 5 (I2C1 SCL) | SCL |
| Pin 1 (3.3v) | VDD |
You also need to pull up SDA and SCL lines individually with 4.7KΩ
resistors to 3.3v rail.
Each example has a global const mpn = ... that may need to be changed
to the correct manufacturer part number of your specific FUSB302 chip as
some MPNs have different I2C addresses.
To build and run an example, run the following in the example directory:
$ go build -o example
$ ./example
The easiest way to run TinyGo examples is to use Raspberry Pi Pico. It is cheap, widely available, well supported and easy to use and work with.
Following guide takes you through how to setup, wire up and run the examples:
| RaspberryPi Pico | FUSB302 |
|---|---|
| Pin 3 (GND) | GND |
| Pin 4 (I2C1 SDA) | SDA |
| Pin 5 (I2C1 SCL) | SCL |
| Pin 36 (3.3v) | VDD |
You also need to pull up SDA and SCL lines individually with 4.7KΩ
resistors to 3.3v rail.
Each example has a global const mpn = ... that may need to be changed
to the correct manufacturer part number of your specific FUSB302 chip as
some MPNs have different I2C addresses.
You should use TinyGo >= 0.25 which has support for USB UART. For older TinyGo versions, you will need to hook up extra wires to a UART bridge to be able to see the logs.
-
Disconnect the Pico from power.
-
Hold down the BOOT button on the board.
-
Connect the USB from your computer to the Pico.
-
Wait until the
RPI-RP2USB drive shows up. -
Run the following to build and flash the example program:
tinygo flash -target=pico -serial usb -
Open the USB serial port using your favorite terminal (e.g. on linux, you can run
screen /dev/ttyACM0). -
Connect the FUSB302 board to a USB-PD power source.