Project Documentation
Project Specification
Power Budget
+3V3.+1V1, generated by the RP2040 internal regulator.VBAT, a single Li-ion/Li-polymer cell charged to 4.2 V by U5.Firmware Getting Started
Board Bring-Up Plan
Table
| Function | RP2040 pin | Connected hardware | Direction |
|---|---|---|---|
| LoRa UART RX | GPIO0 | U6 PB6, net LoRA_RX | Input |
| LoRa UART TX | GPIO1 | U6 PB7, net LoRa_TX | Output |
| Microphone WS | GPIO9 | MK3 WS through R17 | Output |
| Microphone SD | GPIO10 | MK3 SD through R12 | Input |
| Microphone SCK | GPIO11 | MK3 SCK through R16 | Output |
| LoRa reset | GPIO12 | U6 RST, net LORA_NRST | Output, active low |
| DHT data | GPIO16 | J6 pin 2, 5 kOhm pull-up | Bidirectional |
| SD clock | GPIO17 | J1 pin 5 | Output |
| SD command | GPIO18 | J1 pin 3 | Bidirectional |
| SD data 0 | GPIO19 | J1 pin 7 | Bidirectional |
| SD data 1 | GPIO20 | J1 pin 8 | Bidirectional |
| SD data 2 | GPIO21 | J1 pin 1 | Bidirectional |
| SD data 3 | GPIO22 | J1 pin 2 | Bidirectional |
| User LED | GPIO25 | D2 | Output |
| Reset | RUN | SW2 | Active low |
| SWD data | SWD | J8 pin 1 | Debug |
| SWD clock | SWCLK | J8 pin 3 | Debug |
Diagram
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
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); }
flush() at controlled checkpoints, not for every audio block.AT and query module firmware/version.Bash
pio run pio run -t upload pio device monitor -b 115200
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