Project Idea Start
Image
Image
arduino and board esp32dev. Add adafruit/DHT sensor library and plerup/EspSoftwareSerial dependencies.Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 lib_deps = adafruit/DHT sensor library plerup/EspSoftwareSerial
Cpp
constexpr int BHA_RX=16, BHA_TX=17; constexpr int FDA_RX=22, FDA_TX=23; constexpr int I2S_BCLK=14, I2S_WS=25, I2S_SD=32; constexpr int MQ2_ADC=34, DHT_PIN=27; constexpr int XIAO_RX=33, XIAO_TX=13;
Cpp
#include <Arduino.h> #include <driver/i2s.h> #include <DHT.h> #include <SoftwareSerial.h> constexpr int BHA_RX=16, BHA_TX=17; constexpr int FDA_RX=22, FDA_TX=23; constexpr int I2S_BCLK=14, I2S_WS=25, I2S_SD=32; constexpr int MQ2_ADC=34, DHT_PIN=27; constexpr int XIAO_RX=33, XIAO_TX=13; HardwareSerial RadarBHA(1); HardwareSerial RadarFDA(2); SoftwareSerial XiaoUart; DHT dht(DHT_PIN, DHT11); void setupI2S() { i2s_config_t cfg{}; cfg.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX); cfg.sample_rate = 16000; cfg.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT; cfg.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT; cfg.communication_format = I2S_COMM_FORMAT_STAND_I2S; cfg.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1; cfg.dma_buf_count = 4; cfg.dma_buf_len = 128; cfg.use_apll = false; cfg.tx_desc_auto_clear = false; cfg.fixed_mclk = 0; i2s_pin_config_t pins{I2S_BCLK, I2S_WS, I2S_PIN_NO_CHANGE, I2S_SD}; i2s_driver_install(I2S_NUM_0, &cfg, 0, nullptr); i2s_set_pin(I2S_NUM_0, &pins); } void setup() { Serial.begin(115200); // UART0: laptop debug only RadarBHA.begin(1382400, SERIAL_8N1, BHA_RX, BHA_TX); RadarFDA.begin(115200, SERIAL_8N1, FDA_RX, FDA_TX); XiaoUart.begin(115200, SWSERIAL_8N1, XIAO_RX, XIAO_TX, false); analogSetPinAttenuation(MQ2_ADC, ADC_11db); dht.begin(); setupI2S(); } void loop() { // Raw radar pass-through: no undocumented packet interpretation. while (RadarBHA.available()) Serial.write(RadarBHA.read()); while (RadarFDA.available()) Serial.write(RadarFDA.read()); while (XiaoUart.available()) Serial.write(XiaoUart.read()); static uint32_t last=0; if (millis()-last >= 2000) { last=millis(); int raw=analogRead(MQ2_ADC); float t=dht.readTemperature(), h=dht.readHumidity(); Serial.printf("MQ2 raw=%d DHT11 T=%.1fC RH=%.1f%%\n", raw, t, h); int32_t samples[128]; size_t bytes=0; if (i2s_read(I2S_NUM_0, samples, sizeof(samples), &bytes, pdMS_TO_TICKS(20))==ESP_OK) Serial.printf("I2S bytes=%u first=%ld\n", (unsigned)bytes, (long)samples[0]); } }
Toolchain
Pin map
Compilable Arduino starter
Startup sequence