#!/usr/bin/env bash # flash.sh — build + flash the ESP32-C3 F3 bridge from steel141. # The C3 is at /dev/ttyACM0 (native USB-Serial-JTAG). esptool is already present; # arduino-cli + the esp32 core are installed on first run if missing. set -euo pipefail PORT="${1:-/dev/ttyACM0}" SKETCH="$(cd "$(dirname "$0")" && pwd)/clar200_bridge.ino" FQBN="esp32:esp32:esp32c3:CDCOnBoot=cdc" # CDCOnBoot=cdc -> Serial == USB-CDC (required by sketch) command -v arduino-cli >/dev/null 2>&1 || { echo ">> installing arduino-cli to ~/.local/bin ..." mkdir -p ~/.local/bin curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh \ | BINDIR=~/.local/bin sh export PATH="$HOME/.local/bin:$PATH" } if ! arduino-cli core list 2>/dev/null | grep -q '^esp32:esp32'; then echo ">> installing esp32 Arduino core (this is the big download) ..." arduino-cli config init --overwrite >/dev/null 2>&1 || true arduino-cli config add board_manager.additional_urls \ https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json arduino-cli core update-index arduino-cli core install esp32:esp32 fi # arduino-cli wants the sketch in a dir named like the .ino; it already is. SKETCH_DIR="$(dirname "$SKETCH")" echo ">> compiling for $FQBN ..." arduino-cli compile --fqbn "$FQBN" "$SKETCH_DIR" echo ">> flashing to $PORT ..." arduino-cli upload --fqbn "$FQBN" --port "$PORT" "$SKETCH_DIR" echo ">> done. Open the terminal with: screen $PORT 115200 (Ctrl-A k to quit)" echo " USB-CDC baud is virtual; set the DRIVE baud with ~1/~2/~3/~4 inside the session."