Skip to content

Latest commit

 

History

History
127 lines (108 loc) · 5.64 KB

File metadata and controls

127 lines (108 loc) · 5.64 KB

Here is the updated, rigorous implementation plan. It is divided into two main parts: Phase A (Hardware Validation) and Phase B (System Implementation).

This plan is designed to be fed directly to an AI coding agent or followed by a firmware engineer.


Phase A: Hardware Validation (The "Smoke Tests")

Objective: Verify that every physical component is soldered correctly and functioning before writing complex system logic. Hardware Target: Seeed Studio XIAO ESP32-S3 (Custom Pinout).

Test 1: The "Heartbeat" (Status LED)

  • Goal: Verify the board boots and the Status LED (D6) works.
  • Complexity: Extremely Low.
  • Procedure:
    1. Write a simple blink sketch using pin D6 (GPIO 43).
    2. Flash to the XIAO.
  • Success Criteria: The Red LED blinks at 1Hz.

Test 2: The "Rainbow" (NeoPixels)

  • Goal: Verify the LED wiring, power stability, and level shifting (if applicable).
  • Complexity: Low.
  • Procedure:
    1. Install FastLED or Adafruit_NeoPixel.
    2. Configure for Pin D3 (GPIO 4).
    3. Set brightness to 50% (to test battery load safely).
    4. Run a "Cyclon" or "Rainbow" animation.
  • Success Criteria: All pixels light up with correct colors. No flickering or "glitching" at the end of the strip.

Test 3: The "Voltage Check" (Battery Monitor)

  • Goal: Verify the voltage divider on Pin D4 (GPIO 5) is reading correctly.
  • Complexity: Low.
  • Procedure:
    1. Read analogRead(5).
    2. Apply formula: voltage = (raw_value / 4095.0) * 3.3 * 2.0.
    3. Print voltage to Serial Monitor every second.
  • Success Criteria: Serial monitor shows ~3.7V - 4.2V (match with a multimeter to calibrate the 2.0 multiplier if needed).

Test 4: The "Filesystem Check" (SD Card)

  • Goal: Verify SPI wiring and SD card mount.
  • Complexity: Medium.
  • Procedure:
    1. Use the SD library.
    2. Configure SPI pins explicitly: SCK=7, MISO=8, MOSI=9, CS=44.
    3. Attempt SD.begin(44).
    4. List all files on the card to Serial.
    5. Create a text file, write "test", read it back.
  • Success Criteria: Serial prints "SD Card Mount: Success" and lists files.

Test 5: The "Tone Test" (I2S Audio Amp)

  • Goal: Verify MAX98357A wiring and I2S bus.
  • Complexity: High (requires I2S generator).
  • Procedure:
    1. Use ESP8266Audio library (works on ESP32) or a simple I2S sine wave generator.
    2. Configure I2S Pins: BCLK=1, LRC=2, DIN=3.
    3. Generate a 440Hz Sine Wave tone via I2S.
  • Success Criteria: A clean, loud tone plays from the speaker. (If it sounds like static, check BCLK/LRC wiring order).

Test 6: The "Input Check" (Rescue Button)

  • Goal: Verify the button on D5 (GPIO 6) works.
  • Complexity: Low.
  • Procedure:
    1. Set Pin 6 to INPUT_PULLUP.
    2. Loop: Print "Pressed" when digitalRead is LOW.
  • Success Criteria: Serial prints "Pressed" only when you hold the button.

Phase B: System Implementation (The "Isochron" System)

Objective: Build the firmware that combines these components into a synchronized swarm.

Step 1: Network & Telemetry Foundation

  • Task: Connect to Wi-Fi and report status.
  • Logic:
    1. Boot up.
    2. Connect to Hardcoded Wi-Fi credentials.
    3. Start UDP Listener on Port 4444 (Command).
    4. Start Heartbeat Loop: Send JSON to Server Port 5555 every 1s (jittered).
    5. Payload: {"id": "mac_address", "bat": 4.10, "state": "IDLE"}.
  • Verification: Server console shows incoming JSON from the device.

Step 2: Time Synchronization (NTP)

  • Task: Get all nodes on the same clock.
  • Logic:
    1. Implement NTPClient (pool.ntp.org or local server).
    2. Sync every 60 seconds.
    3. Add timestamp to the Heartbeat JSON.
  • Verification: Two devices output their time to Serial; they must match within ~10-50ms.

Step 3: The Audio Player (SD + I2S)

  • Task: Play files from SD card via I2S.
  • Logic:
    1. Integrate ESP8266Audio library (specifically AudioFileSourceSD and AudioOutputI2S).
    2. Create a function playTrack(filename).
    3. Ensure this runs on Core 1 (pinned task) to avoid Wi-Fi stutter.
  • Verification: Hardcode a track to play on boot. Ensure music plays clearly.

Step 4: Visuals (The RMS Reactor)

  • Task: Make LEDs react to audio.
  • Logic:
    1. Implement the "Envelope Follower" (Attack/Release/Gain) struct.
    2. In the Audio Loop (Core 1), intercept the audio buffer.
    3. Calculate RMS (Root Mean Square).
    4. Update LED brightness based on the Envelope settings.
  • Verification: Play music; LEDs pulse in time with the beat.

Step 5: The "Isochron" Trigger (Synced Start)

  • Task: Execute the "Play at Time X" command.
  • Logic:
    1. Receive UDP: {"cmd": "PLAY", "file": "/track.mp3", "time": 1715005000}.
    2. Check current_ntp_time.
    3. Calculate delay_ms = target_time - current_ntp_time.
    4. Wait delay_ms.
    5. Start Audio Task.
  • Verification: Send command. Device waits, then starts exactly at the target second.

Step 6: The "Stretch Goal" (HTTP Downloader)

  • Task: Update content remotely.
  • Logic:
    1. Receive UDP: {"cmd": "DOWNLOAD", "url": "http://server/file.mp3"}.
    2. Stop Audio/LEDs (Pause Task).
    3. Initialize HTTPClient.
    4. Stream data from URL to SD Card file path.
    5. Send Heartbeat {"state": "DOWNLOADING", "progress": 50}.
    6. On finish, SD.close() and return to IDLE.
  • Verification: Upload a file to the server, trigger download, verify file exists on SD card and plays correctly.