#!/usr/bin/env bash # Compile + flash an Arduino sketch onto an Uno Q's MCU over adb. The sketch is # written to MCU flash (0x80F0000) and runs on every boot/reset — so this is how # you set a board's default ("boot") animation. Attendees overwrite it when they # flash their own sketch during the workshop; re-run this to restore the default. # # ./flash-sketch.sh [sketch-dir] # ./flash-sketch.sh 65301572 # defaults to the boot animation # ./flash-sketch.sh 65301572 sketches/matrix_effects # # Fleet-wide (restore the default on every connected board): # for s in $(adb devices | awk 'NR>1 && $2=="device"{print $1}'); do ./flash-sketch.sh "$s"; done set -euo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" S="${1:?usage: flash-sketch.sh [sketch-dir]}" # The designated board default (boot animation). SKETCH_DIR="${2:-$HERE/sketches/matrix_rain}" NAME="$(basename "$SKETCH_DIR")" [ -r "$SKETCH_DIR/$NAME.ino" ] || { echo "no $SKETCH_DIR/$NAME.ino" >&2; exit 1; } REMOTE="/home/arduino/sketches/$NAME" echo "==> [$S] push $NAME" adb -s "$S" shell 'mkdir -p /home/arduino/sketches' >/dev/null adb -s "$S" push "$SKETCH_DIR" /home/arduino/sketches/ >/dev/null echo "==> [$S] compile (TMPDIR=/tmp dodges the adb shell's /data/local/tmp)" adb -s "$S" shell "cd $REMOTE && TMPDIR=/tmp arduino-cli compile --fqbn arduino:zephyr:unoq --export-binaries . 2>&1 | tail -3" echo "==> [$S] flash (OpenOCD @ 0x80F0000)" adb -s "$S" shell "BIN=\$(ls $REMOTE/build/arduino.zephyr.unoq/*.elf-zsk.bin 2>/dev/null | head -1); \ [ -n \"\$BIN\" ] || { echo 'no .elf-zsk.bin — compile failed' >&2; exit 1; }; \ /usr/local/bin/arduino-flash \"\$BIN\" 2>&1 | tail -3" echo "==> [$S] done — $NAME flashed and running"