Skip to content

allow using AIN1 for VBAT on RAK19007 boards - #3328

Open
andyshinn wants to merge 1 commit into
meshcore-dev:devfrom
andyshinn:ashinn/allow-override-rak4631-vbat-pin
Open

allow using AIN1 for VBAT on RAK19007 boards#3328
andyshinn wants to merge 1 commit into
meshcore-dev:devfrom
andyshinn:ashinn/allow-override-rak4631-vbat-pin

Conversation

@andyshinn

Copy link
Copy Markdown
Contributor

This allows someone using the RAK19007 board to use AIN1 on the J11 header to get VBAT. Handy if using an external supply like a Voltaic pack.

Copilot AI lite review requested due to automatic review settings August 31, 2026 00:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the RAK4631 variant’s VBAT sensing and NRF52 power-management LPCOMP configuration compile-time overrideable, enabling RAK19007 users to read VBAT via an alternate analog input (e.g., AIN1 on J11) without patching the core.

Changes:

  • Wrapped PIN_VBAT_READ and ADC_MULTIPLIER in #ifndef guards to allow -D/pre-include overrides.
  • Wrapped PWRMGT_LPCOMP_AIN and PWRMGT_LPCOMP_REFSEL in #ifndef guards to allow alternative LPCOMP wake configuration.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
variants/rak4631/variant.h Allows overriding LPCOMP AIN/refsel defaults via preprocessor defines.
variants/rak4631/RAK4631Board.h Allows overriding VBAT ADC pin and multiplier defaults via preprocessor defines.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 111 to +114
// AIN3 = P0.05 = PIN_A0 / PIN_VBAT_READ
#define PWRMGT_LPCOMP_AIN 3
#define PWRMGT_LPCOMP_REFSEL 4 // 5/8 VDD (~3.13-3.44V)
#ifndef PWRMGT_LPCOMP_AIN
#define PWRMGT_LPCOMP_AIN 3
#endif
@MFornander

Copy link
Copy Markdown

HI Andy. Great minds think alike. I started working on this today after I got my V25 soldered up and connected directly to the 1W booster. I then found your PR and extended it to handle both the 4631 and the 3401.

MFornander added a commit to MFornander/MeshCore that referenced this pull request Sep 1, 2026
Wrap PIN_VBAT_READ / ADC_MULTIPLIER and the PWRMGT_* defines in #ifndef
guards so build flags can redirect battery telemetry to another analog
pin, e.g. a Voltaic V25/V50/V75 pack's USB-C SBU output (1/2 cell
voltage) wired to the base board J11 AIN1 pin.

Remove the unused Meshtastic-leftover battery defines from the rak3401
variant.h: nothing in the MeshCore, framework, or library compile
closure references them, and the unconditional ADC_MULTIPLIER there
would defeat both the new #ifndef default and any -D build flag
(variant.h is included via Arduino.h before the board headers).

Add a documented RAK_3401_repeater_voltaic example env that reports the
pack's true cell voltage and keeps nRF52 power management active with
LPCOMP wake rerouted to the SBU pin: sleep below 3.4V cell, wake once
the pack recharges past ~3.7V.

The rak4631 hunks are byte-identical to PR meshcore-dev#3328 by @andyshinn, which
this change incorporates and extends.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@andyshinn

Copy link
Copy Markdown
Contributor Author

Sounds good. If you open that one I can close this.

@MFornander

Copy link
Copy Markdown

Sounds good. If you open that one I can close this.

Cool. Going to test on both boards so will probaly take a few days. I'll ping when they look good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants