From 1d2f0ddd050c3647ea4c435587d210199ee02749 Mon Sep 17 00:00:00 2001 From: Henry Schokkenbroek Date: Wed, 14 Oct 2026 22:36:39 +0200 Subject: [PATCH] RAK3112: enable octal PSRAM, fix battery reading, drop Heltec leftovers - Set board_build.arduino.memory_type = qio_opi. The RAK3112 (ESP32-S3R8) has 8MB octal PSRAM; the esp32-s3-devkitc-1 default (qio_qspi) failed with "PSRAM ID read error ... wrong PSRAM line mode", so BOARD_HAS_PSRAM builds ran without PSRAM (MQTT limited to 2 slots, TLS on internal heap). - Remove PIN_ADC_CTRL (GPIO36) handling copied from Heltec V3. The RAK3112 has no ADC enable pin and GPIO33-37 are used by the octal PSRAM. - Read VBAT with calibrated analogReadMilliVolts() and the WisBlock base board divider (1M/1.5M, empirical x1.73 as in Meshtastic's RAK4631). - Sensor env: drop ENV_PIN_SDA/SCL=33/34 (Heltec V3 values, PSRAM pins). - Exclude MQTTMessageBuilder/JWTHelper from non-MQTT envs so they build without the MQTT-only libraries (Timezone.h not found). Tested on RAK3112 + RAK19007: PSRAM found (8MB), 5 MQTT slots, both dutchmeshcore collectors connected, battery reads 4139 mV on a full LiPo. Co-Authored-By: Claude Opus 5.5 (1M context) --- variants/rak3112/RAK3112Board.h | 31 ++++++++++--------------------- variants/rak3112/platformio.ini | 9 ++++++--- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/variants/rak3112/RAK3112Board.h b/variants/rak3112/RAK3112Board.h index 8ba3197cf6..8045ee0650 100644 --- a/variants/rak3112/RAK3112Board.h +++ b/variants/rak3112/RAK3112Board.h @@ -6,22 +6,17 @@ // built-ins #ifndef PIN_VBAT_READ - #define PIN_VBAT_READ 1 + #define PIN_VBAT_READ 1 // WB_A0, VBAT via the WisBlock base board divider #endif -#ifndef PIN_ADC_CTRL - #define PIN_ADC_CTRL 36 -#endif -#define PIN_ADC_CTRL_ACTIVE LOW -#define PIN_ADC_CTRL_INACTIVE HIGH -#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000) +// WisBlock base boards (RAK19007 etc.) divide VBAT with 1M / 1.5M (nominal x1.667); 1.73 compensates +// for ADC loading of the high-impedance divider (same empirical value as Meshtastic's RAK4631) +#define ADC_MULTIPLIER 1.73f #define BATTERY_SAMPLES 8 +// NOTE: no ADC enable pin on the RAK3112. GPIO33-37 belong to the octal PSRAM and must not be touched. #include class RAK3112Board : public ESP32Board { -private: - bool adc_active_state; - public: RefCountedDigitalPin periph_power; @@ -30,13 +25,6 @@ class RAK3112Board : public ESP32Board { void begin() { ESP32Board::begin(); - // Auto-detect correct ADC_CTRL pin polarity (different for boards >3.2) - pinMode(PIN_ADC_CTRL, INPUT); - adc_active_state = !digitalRead(PIN_ADC_CTRL); - - pinMode(PIN_ADC_CTRL, OUTPUT); - digitalWrite(PIN_ADC_CTRL, !adc_active_state); // Initially inactive - periph_power.begin(); esp_reset_reason_t reason = esp_reset_reason(); @@ -81,13 +69,14 @@ class RAK3112Board : public ESP32Board { uint16_t getBattMilliVolts() override { analogReadResolution(12); - uint32_t raw = 0; + // analogReadMilliVolts() applies the eFuse ADC calibration + uint32_t mv = 0; for (int i = 0; i < BATTERY_SAMPLES; i++) { - raw += analogRead(PIN_VBAT_READ); + mv += analogReadMilliVolts(PIN_VBAT_READ); } - raw = raw / BATTERY_SAMPLES; + mv = mv / BATTERY_SAMPLES; - return (ADC_MULTIPLIER * raw) / 4096; + return (uint16_t)(ADC_MULTIPLIER * mv); } const char* getManufacturerName() const override { diff --git a/variants/rak3112/platformio.ini b/variants/rak3112/platformio.ini index a7d27a65b7..15ea863716 100644 --- a/variants/rak3112/platformio.ini +++ b/variants/rak3112/platformio.ini @@ -1,6 +1,8 @@ [rak3112] extends = esp32_base board = esp32-s3-devkitc-1 +; RAK3112 (ESP32-S3R8) has 8MB octal PSRAM; the devkitc-1 default (qio_qspi) fails to detect it +board_build.arduino.memory_type = qio_opi build_flags = ${esp32_base.build_flags} ${sensor_base.build_flags} @@ -35,6 +37,9 @@ build_flags = build_src_filter = ${esp32_base.build_src_filter} +<../variants/rak3112> + +; MQTT helpers need the MQTT-only libs (Timezone, ArduinoJson); the *_observer_mqtt envs add them back + - + - lib_deps = ${esp32_base.lib_deps} ${sensor_base.lib_deps} @@ -273,12 +278,10 @@ lib_deps = extends = rak3112 build_flags = ${rak3112.build_flags} - -D ADVERT_NAME='"RAK3112 v3 Sensor"' + -D ADVERT_NAME='"RAK3112 Sensor"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' - -D ENV_PIN_SDA=33 - -D ENV_PIN_SCL=34 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${rak3112.build_src_filter}