Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Last active April 9, 2026 21:08
Show Gist options
  • Select an option

  • Save deadprogram/2f3705fefa9ea5eb28522f2312ace673 to your computer and use it in GitHub Desktop.

Select an option

Save deadprogram/2f3705fefa9ea5eb28522f2312ace673 to your computer and use it in GitHub Desktop.
TinyGo and Arduino UNO Q

Flashing the Arduino UNO Q using TinyGo

Here are some helpful tips to use TinyGo with and an Arduino UNO Q board that is connected either via Android Debug Bridge (adb) or via SSH.

adb

adb is useful for when you want to connect the Arduino UNO Q directly to your computer without a monitor or keyboard.

You can install the adb command line tool for your platform here: https://developer.android.com/tools/releases/platform-tools

macOS/Linux

To start a new session, plug the board into your computer using a USB-C cable, then run this command:

tinygo_setup_arduino_q.sh

You must run that command once after plugging in your Arduino after being powered down.

Now you can use the tinygo flash command on your board.

If you want to see the serial output from the microcontroller, you must run the tinygo_monitor_arduino_q.sh command.

Windows

To start a new session, plug the board into your computer using a USB-C cable, then run this command:

tinygo_setup_arduino_q.ps1

You must run that command once after plugging in your Arduino after being powered down.

Now you can use the tinygo flash command on your board.

If you want to see the serial output from the microcontroller, you must run the tinygo_monitor_arduino_q.ps1 command.

ssh

ssh is useful for when you want to connect to an Arduino UNO Q that is already on a network.

If you haven't set up SSH keys, the script will prompt you for the arduino user's password multiple times (once for every ssh and scp command). To avoid this, set up SSH keys by running ssh-copy-id arduino@<target_ip> on your local machine first.

macOS/Linux

./tinygo_flash_arduino_uno_q_ssh.sh ./examples/unoqmatrix/ 192.168.1.159

Windows

.\tinygo_flash_arduino_uno_q_ssh.ps1 .\examples\unoqmatrix\ 192.168.1.159
param(
[Parameter(Mandatory=$true, Position=0)]
[string]$SourcePath,
[Parameter(Mandatory=$true, Position=1)]
[string]$TargetHost,
[Parameter(Position=2)]
[string]$TargetUser = "arduino"
)
$AllowSSHAuthWithPassword = @("-o", "PreferredAuthentications=password", "-o", "PasswordAuthentication=yes")
$Target = "$TargetUser@$TargetHost"
# 1. Use tinygo to build the firmware and generate a .hex file
$HexOutputPath = [System.IO.Path]::ChangeExtension($SourcePath, ".hex")
Write-Host "Building firmware from source '$SourcePath'..."
& tinygo build -o $HexOutputPath -target=arduino-uno-q $SourcePath
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build firmware from $SourcePath"
exit 1
}
$HexFilename = Split-Path $HexOutputPath -Leaf
$TargetHexPath = "/home/arduino/$HexFilename"
# 2. Upload the .hex file
Write-Host "Uploading firmware '$HexFilename'..."
& scp @AllowSSHAuthWithPassword $HexOutputPath "${Target}:${TargetHexPath}"
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to upload $HexOutputPath"
exit 1
}
# 3. Run the OpenOCD command on the target to program the firmware
Write-Host "Flashing firmware..."
& ssh $Target @AllowSSHAuthWithPassword "/opt/openocd/bin/openocd -s /opt/openocd/share/openocd/scripts -s /opt/openocd -c `"adapter driver linuxgpiod`" -c `"adapter gpio swclk -chip 1 26`" -c `"adapter gpio swdio -chip 1 25`" -c `"adapter gpio srst -chip 1 38`" -c `"transport select swd`" -c `"adapter speed 1000`" -c `"reset_config srst_only srst_push_pull`" -f /opt/openocd/stm32u5x.cfg -c `"program $TargetHexPath verify reset exit`""
Write-Host "Done!"
#!/bin/bash
ALLOW_SSH_AUTH_WITH_PASSWORD="-o PreferredAuthentications=password -o PasswordAuthentication=yes"
# Ensure a source argument was provided
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
echo "Usage: $0 <path_to_source> <ip_address_or_hostname> [username]"
exit 1
fi
# 1. Use tinygo to build the firmware and generate a .hex file
SOURCE_PATH="$1"
TARGET_HOST="$2"
TARGET_USER="${3:-arduino}"
TARGET="$TARGET_USER@$TARGET_HOST"
HEX_OUTPUT_PATH="${SOURCE_PATH%.*}.hex"
echo "Building firmware from source '$SOURCE_PATH'..."
if ! tinygo build -o "$HEX_OUTPUT_PATH" -target=arduino-uno-q "$SOURCE_PATH"; then
echo "Error: Failed to build firmware from $SOURCE_PATH"
exit 1
fi
LOCAL_HEX_FILE="$HEX_OUTPUT_PATH"
HEX_FILENAME=$(basename "$LOCAL_HEX_FILE")
TARGET_HEX_PATH="/home/arduino/$HEX_FILENAME"
# 2. Upload the .hex file
echo "Uploading firmware '$HEX_FILENAME'..."
if ! scp $ALLOW_SSH_AUTH_WITH_PASSWORD "$LOCAL_HEX_FILE" "$TARGET:$TARGET_HEX_PATH"; then
echo "Error: Failed to upload $LOCAL_HEX_FILE"
exit 1
fi
# 3. Run the OpenOCD command on the target to program the firmware
echo "Flashing firmware..."
ssh "$TARGET" $ALLOW_SSH_AUTH_WITH_PASSWORD "/opt/openocd/bin/openocd -s /opt/openocd/share/openocd/scripts -s /opt/openocd -c \"adapter driver linuxgpiod\" -c \"adapter gpio swclk -chip 1 26\" -c \"adapter gpio swdio -chip 1 25\" -c \"adapter gpio srst -chip 1 38\" -c \"transport select swd\" -c \"adapter speed 1000\" -c \"reset_config srst_only srst_push_pull\" -f /opt/openocd/stm32u5x.cfg -c \"program $TARGET_HEX_PATH verify reset exit\""
echo "Done!"
#!/bin/bash
# Opens a serial console to the Arduino Q board via adb.
# Uses screen on the remote device at 115200 baud.
echo "Connecting to /dev/ttyHS1 at 115200 baud..."
SCREENRC='hardstatus alwayslastline "Serial: /dev/ttyHS1 @ 115200 | Exit: Ctrl+A then K"'
exec adb shell -t "echo '$SCREENRC' > /tmp/.screenrc_serial && screen -c /tmp/.screenrc_serial /dev/ttyHS1 115200"
# Opens a serial console to the Arduino Q board via adb.
# Uses screen on the remote device at 115200 baud.
Write-Host "Connecting to /dev/ttyHS1 at 115200 baud..."
$screenrc = 'hardstatus alwayslastline "Serial: /dev/ttyHS1 @ 115200 | Exit: Ctrl+A then K"'
& adb shell -t "echo '$screenrc' > /tmp/.screenrc_serial && screen -c /tmp/.screenrc_serial /dev/ttyHS1 115200"
#!/bin/bash
# 1. Stop the arduino-router service
echo "Stopping arduino-router..."
adb shell -t "sudo systemctl stop arduino-router"
# 2. Install screen utility
echo "Installing screen..."
adb shell -t "sudo apt-get update && sudo apt-get install -y screen"
echo "Done!"
<#
.SYNOPSIS
Sets up the Arduino UNO Q for use with TinyGo this session.
.DESCRIPTION
This script stops the arduino-router service, and installs the screen utility.
#>
# 1. Stop the arduino-router service
Write-Host "Stopping arduino-router..." -ForegroundColor Cyan
adb shell -t "sudo systemctl stop arduino-router"
# 2. Install screen utility
Write-Host "Install screen utility..." -ForegroundColor Cyan
adb shell -t "sudo apt-get update && sudo apt-get install -y screen"
Write-Host "Done!" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment