Is battery voltage via ADC possible on SODAQ One?

According to it is possible to read the battery voltage with a call to analogRead() on the SODAQ One (the original, not the v2).

Certainly doing so returns a somewhat realistic number, but I can’t for the life of me figure out why this would work!

  • The schematic shows no connection from the battery voltage to an analog pin (unlike the v2 schematic, which clearly shows a batt voltage measurement).
  • Calling print() on BATVOLT_PIN returns 36, but pin 36 is VDDIO2 and certainly not an AIN pin.

Is there a part of the schematic missing? Is there a way to inspect the definition of BAT_VOLT? Where are BATVOLT_R1 and BATVOLT_R2? Is this all done on the One board or does it need the Base board?

You need to read about voltage dividers, R1 and R2 are resistors of known value

Sorry I clearly haven’t explained myself properly. There is absolutely no question about what a voltage divider is. I got that 20 years ago.

The question is… where is the voltage divider? R1 and R2 on the schematic have different values to the constants in the sample code and are not connected to an analog pin.

What does BAT_VOLT refer to? Which pin is used? How is that pin connected to the battery voltage? Is there a way to inspect the BAT_VOLT source in case there’s any clues there?

BAT_VOLT is connected to pin 36 of the microcontroller.

Instead of calling the I/O pin D1/A1 we called it BAT_VOLT because it is not connected to an external I/O pin.

The downloaded board files can be found in: %localappdata%\Arduino15\packages\SODAQ\hardware\samd\1.6.14\variants

For rev.4 both R1 and R2 are both 2

I made a note of this. We will update the support pages soon.



I see the Rev4 schematics have already been posted on the support page and now that I’ve found those board files(1), it all makes sense!

I see now that Arduino “pin numbers” have no relationship to IC pin numbers, so BAT_VOLT being 36 doesn’t tell you much without reading variant.cpp. As westfw describes here, Arduino pin numbers tend to follow a pattern to some extent, but can be entirely arbitrary.

By reading variant.cpp I see that BAT_VOLT corresponds to PORTA, pin 5, which is IC pin 10, which is assigned to AIN5. And as the new schematic clearly shows, that’s connected to a 2M/2M voltage divider of the battery voltage!

Thanks for your help. Amazed I’m the first to ask.

  1. On macOS, they’re here: /Users/<user>/Library/Arduino15/packages/SODAQ/hardware/samd/1.6.11/variants/sodaq_one/
1 Like