Project Documentation


Created 7 project docs

Project Specification

View Document

Project Specification Project Overview
Status: Review
A compact, battery-powered tinyML audio and environmental data-collection board based on the RP2040. The device records digital microphone data to microSD, can attach a DHT11/DHT22 sensor, and reports status or summarized data over LoRaWAN through a LoRa-E5 module. It supports USB or solar-assisted charging of a single-cell Li-ion/Li-polymer battery and is packaged in a two-piece FDM enclosure.
Intended Use
  • Community development and field data collection for tinyML audio applications.
  • Local audio capture and storage where Wi-Fi is unavailable.
  • Periodic low-bandwidth LoRaWAN telemetry rather than streaming raw audio over LoRa.
  • Prototype and validation platform; the current revision is not yet production-qualified.

Power Budget

View Document

Power Budget Status and Method
Status: Preliminary engineering budget for review. It is grounded in the live schematic, but several load currents are planning allowances because the exact SD card, DHT sensor, firmware duty cycle, battery, and solar panel are not selected.
The power path is:
Confirmed Electrical Facts
  • Main regulated system rail: +3V3.
  • Internal RP2040 core rail: +1V1, generated by the RP2040 internal regulator.
  • Battery rail: VBAT, a single Li-ion/Li-polymer cell charged to 4.2 V by U5.
  • Charge-current intent: approximately 900 mA according to the schematic annotation and R7 = 2 kOhm.
  • U4 RT8059 is rated in project component data as a 1 A buck converter with 2.8 V to 5.5 V input.

Firmware Getting Started

View Document

Firmware Getting Started Platform and Toolchain
  • MCU: RP2040 U1
  • Framework: Arduino-Pico
  • Build system: PlatformIO
  • Debug: USB serial for logs, SWD through J8 for recovery and source-level debugging
  • Flash: W25Q128JVSIQ external QSPI, 16 MiB
Pin Mapping Recommended Firmware State Machine PlatformIO Configuration
The exact Arduino-Pico release and SDIO/I2S libraries must be pinned after a compile-tested implementation. The microSD wiring is 4-bit SD, not conventional SPI; do not silently substitute an SPI example without rewiring hardware.
Initial Bring-Up Source
This source is intentionally limited to peripherals that can be initialized with stable Arduino-Pico APIs from the confirmed schematic: USB logging, user LED, DHT, LoRa UART/reset,...

Board Bring-Up Plan

View Document

Board Bring-Up Plan Prerequisites
  • Current-limited bench supply, battery simulator or protected single-cell battery, DMM, oscilloscope, logic analyzer, USB cable, SWD probe, known-good microSD card, LoRa antenna, and optional DHT11/DHT22.
  • Start without battery, SD card, antenna pigtail stress, or external sensor fitted unless the step requires it.
  • Use ESD precautions for U1, U2, U6, MK3, and RF connector J4.
  • Never transmit U6 without an appropriate antenna connected.
  • Initial current limit: 100 mA for static rail checks; raise only after the rail is verified.
1. Visual and Unpowered Inspection
  • Verify orientation and solder quality of U1, U2, U4, U5, U6, D1, Q2, LEDs, and polarized connectors.
Show 3 More
Created and verified seven detailed project files grounded in the current schematic, BOM, PCB layout, firmware history, and enclosure design:
Open items
  • Battery capacity, protection, and permitted charge rate remain unspecified.
  • Solar-panel rating, recording duty cycle, LoRa interval, and runtime target are unspecified.
  • The buck-only 3.3 V supply may lose regulation as the Li-ion cell discharges.
  • SDIO and I²S firmware still require compile-tested library implementations.
  • Charge current, power consumption, thermal behavior, RF performance, and enclosure fit require physical measurements.
Suggested next steps
  1. Select the battery and solar panel, then finalize the power budget.
  2. Run a complete schematic/ERC and power-path review.
  3. Implement and compile-test the audio and SDIO firmware.
  4. Execute the board bring-up and validation plans on assembled hardware.

Firmware Getting Started
Platform and Toolchain
  • MCU: RP2040 U1
  • Framework: Arduino-Pico
  • Build system: PlatformIO
  • Debug: USB serial for logs, SWD through J8 for recovery and source-level debugging
  • Flash: W25Q128JVSIQ external QSPI, 16 MiB
Pin Mapping

Table


FunctionRP2040 pinConnected hardwareDirection
LoRa UART RXGPIO0U6 PB6, net LoRA_RXInput
LoRa UART TXGPIO1U6 PB7, net LoRa_TXOutput
Microphone WSGPIO9MK3 WS through R17Output
Microphone SDGPIO10MK3 SD through R12Input
Microphone SCKGPIO11MK3 SCK through R16Output
LoRa resetGPIO12U6 RST, net LORA_NRSTOutput, active low
DHT dataGPIO16J6 pin 2, 5 kOhm pull-upBidirectional
SD clockGPIO17J1 pin 5Output
SD commandGPIO18J1 pin 3Bidirectional
SD data 0GPIO19J1 pin 7Bidirectional
SD data 1GPIO20J1 pin 8Bidirectional
SD data 2GPIO21J1 pin 1Bidirectional
SD data 3GPIO22J1 pin 2Bidirectional
User LEDGPIO25D2Output
ResetRUNSW2Active low
SWD dataSWDJ8 pin 1Debug
SWD clockSWCLKJ8 pin 3Debug

Diagram


"Reset" "Safe GPIO and USB log" "Rail peripheral and storage self-test" "Load configuration" "LoRaWAN join or offline mode" "Idle scheduler" "Capture audio and write SD" "Read environmental sensor" "Send summary over LoRa" "Low-power wait" "Fault log and degraded mode"
PlatformIO Configuration

Ini


[env:avocaudio_rp2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = generic_rp2040
framework = arduino
board_build.core = earlephilhower
board_build.filesystem_size = 1m
monitor_speed = 115200
build_flags =
    -D PICO_STDIO_USB=1
    -D USE_TINYUSB=1
lib_deps =
    adafruit/DHT sensor library@^1.4.6
    adafruit/Adafruit Unified Sensor@^1.1.15
The exact Arduino-Pico release and SDIO/I2S libraries must be pinned after a compile-tested implementation. The microSD wiring is 4-bit SD, not conventional SPI; do not silently substitute an SPI example without rewiring hardware.
Initial Bring-Up Source
This source is intentionally limited to peripherals that can be initialized with stable Arduino-Pico APIs from the confirmed schematic: USB logging, user LED, DHT, LoRa UART/reset, and basic AT communication. I2S DMA and 4-bit SD require a compile-tested library choice before they can be represented as production-ready code.

Cpp


#include <Arduino.h>
#include <DHT.h>

static constexpr uint8_t PIN_LORA_RX = 0;
static constexpr uint8_t PIN_LORA_TX = 1;
static constexpr uint8_t PIN_MIC_WS = 9;
static constexpr uint8_t PIN_MIC_SD = 10;
static constexpr uint8_t PIN_MIC_SCK = 11;
static constexpr uint8_t PIN_LORA_RST_N = 12;
static constexpr uint8_t PIN_DHT = 16;
static constexpr uint8_t PIN_SD_CLK = 17;
static constexpr uint8_t PIN_SD_CMD = 18;
static constexpr uint8_t PIN_SD_D0 = 19;
static constexpr uint8_t PIN_SD_D1 = 20;
static constexpr uint8_t PIN_SD_D2 = 21;
static constexpr uint8_t PIN_SD_D3 = 22;
static constexpr uint8_t PIN_LED = 25;

static constexpr uint32_t LORA_BAUD = 9600;
static constexpr uint32_t SENSOR_PERIOD_MS = 5000;

DHT dht(PIN_DHT, DHT22); // Change to DHT11 only when that sensor is fitted.
uint32_t lastSensorMs = 0;

void loraReset() {
    digitalWrite(PIN_LORA_RST_N, LOW);
    delay(20);
    digitalWrite(PIN_LORA_RST_N, HIGH);
    delay(500);
}

bool loraCommand(const char* command, const char* expected, uint32_t timeoutMs) {
    while (Serial1.available()) Serial1.read();
    Serial1.print(command);
    Serial1.print("\r\n");

    String response;
    const uint32_t start = millis();
    while (millis() - start < timeoutMs) {
        while (Serial1.available()) {
            response += static_cast<char>(Serial1.read());
            if (response.indexOf(expected) >= 0) {
                Serial.printf("LoRa response: %s\n", response.c_str());
                return true;
            }
        }
        delay(1);
    }
    Serial.printf("LoRa timeout for %s; response=%s\n", command, response.c_str());
    return false;
}

void setup() {
    pinMode(PIN_LED, OUTPUT);
    digitalWrite(PIN_LED, LOW);

    pinMode(PIN_LORA_RST_N, OUTPUT);
    digitalWrite(PIN_LORA_RST_N, HIGH);

    // Hold uninitialized interfaces in benign states.
    pinMode(PIN_MIC_SCK, OUTPUT);
    pinMode(PIN_MIC_WS, OUTPUT);
    digitalWrite(PIN_MIC_SCK, LOW);
    digitalWrite(PIN_MIC_WS, LOW);

    Serial.begin(115200);
    const uint32_t usbStart = millis();
    while (!Serial && millis() - usbStart < 3000) delay(10);
    Serial.println("AvocAudio bring-up starting");

    dht.begin();
    Serial1.setRX(PIN_LORA_RX);
    Serial1.setTX(PIN_LORA_TX);
    Serial1.begin(LORA_BAUD);
    loraReset();

    const bool loraOk = loraCommand("AT", "+AT: OK", 1500) ||
                        loraCommand("AT", "OK", 1500);
    digitalWrite(PIN_LED, loraOk ? HIGH : LOW);
    Serial.printf("LoRa AT test: %s\n", loraOk ? "PASS" : "FAIL");

    Serial.println("TODO: initialize compile-tested PIO/DMA I2S capture");
    Serial.println("TODO: initialize compile-tested 4-bit SDIO driver and filesystem");
}

void loop() {
    if (millis() - lastSensorMs >= SENSOR_PERIOD_MS) {
        lastSensorMs = millis();
        const float humidity = dht.readHumidity();
        const float temperatureC = dht.readTemperature();
        if (isnan(humidity) || isnan(temperatureC)) {
            Serial.println("DHT read failed or sensor absent");
        } else {
            Serial.printf("T=%.2f C RH=%.2f %%\n", temperatureC, humidity);
        }
    }

    while (Serial1.available()) {
        Serial.write(Serial1.read());
    }

    delay(2);
}
Audio Implementation Requirements
  • Use RP2040 PIO or an Arduino-Pico I2S API that supports the confirmed pins: SCK 11, WS 9, data input 10.
  • Choose and document sample rate and word width before allocating buffers.
  • Use at least two DMA buffers so SD latency cannot directly stall capture.
  • Track buffer overruns and write an error counter to the log.
  • The ICS-43434 produces one channel selected by LR; verify channel alignment during bring-up.
  • Apply a high-pass/DC-removal stage before feature extraction if required by the model.
SD Implementation Requirements
  • Hardware is wired for 4-bit SD, not SPI.
  • Confirm the selected RP2040 core/library can map GPIO17-22 to a 4-bit SD host. If not, either add a PIO SDIO driver or revise the PCB to expose an SPI-compatible connection.
  • Use preallocated files or large contiguous writes to reduce latency.
  • Call flush() at controlled checkpoints, not for every audio block.
  • Detect write failures, close files on low battery, and avoid filesystem corruption during brownout.
LoRaWAN Implementation Requirements
  • Start with AT and query module firmware/version.
  • Configure the regional band before setting keys.
  • Store DevEUI, JoinEUI, and AppKey securely outside source control.
  • Join using OTAA unless deployment requirements specify ABP.
  • Send compact features, event counts, battery state, and file metadata. Do not attempt raw audio streaming.
  • Rate-limit retries and comply with regional duty-cycle and dwell-time rules.
Startup Order
  1. Configure safe GPIO levels.
  2. Start USB diagnostics.
  3. Check reset cause and retained fault information.
  4. Initialize flash-backed configuration.
  5. Test/mount microSD.
  6. Initialize audio DMA without starting capture.
  7. Reset and test LoRa-E5.
  8. Initialize optional DHT sensor.
  9. Start scheduler/watchdog.
  10. Enter logging or low-power mode.
Build and Flash

Bash


pio run
pio run -t upload
pio device monitor -b 115200
If USB upload fails, program/debug through J8 using an SWD probe and a tool supported by the selected PlatformIO configuration.
Firmware Acceptance Tests
  • USB serial appears within 3 seconds after reset.
  • User LED can be toggled.
  • LoRa-E5 returns an AT response after hardware reset.
  • SD card mounts and sustains the selected audio data rate for at least 30 minutes.
  • Audio clock, word select, and data are visible at the microphone pins.
  • No audio buffer overruns occur during LoRa transmissions.
  • DHT absence does not block the main application.
  • Watchdog recovers a deliberately stalled task.
  • Brownout or battery shutdown leaves the filesystem recoverable.
  • Platform and Toolchain

  • Pin Mapping

  • Recommended Firmware State Machine

  • PlatformIO Configuration

  • Initial Bring-Up Source

  • Audio Implementation Requirements

  • SD Implementation Requirements

  • LoRaWAN Implementation Requirements

  • Startup Order

  • Build and Flash

  • Firmware Acceptance Tests