- flash-sketch.sh: compile + flash a sketch dir onto a board's MCU over adb (push → arduino-cli compile with TMPDIR=/tmp → arduino-flash @ 0x80F0000). Defaults to sketches/matrix_rain; includes a fleet loop over adb devices. DRYs up the recipe and makes "set the board default" one command. - Designate matrix_rain as the boot animation boards ship with (the flashed MCU sketch persists across power cycles). Documented in the sketches README + parent Files list. Flashed matrix_rain to the board via the helper (821 bytes, verified E2E). Co-Authored-By: Claude Opus 4.8 <[email protected]>
37 lines
1.7 KiB
Bash
Executable File
37 lines
1.7 KiB
Bash
Executable File
#!/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 <adb-serial> [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 <adb-serial> [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"
|