0

I hope I am just missing something simple here, but I have been banging my head on the desk for awhile trying to solve this very simple problem that I can't seem to find a solution for online.

I have a seeed XIAO nrf52840 and I want to simply do an analogRead(A3).

The issue is that when I apply 3 volts, the output is 2.7 volts from this code below:

#include <Arduino.h>
#include <Adafruit_SPIFlash.h>

float mv_per_lsb = 3300.0F / 1024.0F; // 10-bit ADC with 3.3V input range

void setup() {
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 3:
  int sensorValue = analogRead(A3);
  // print out the value as mV:
  Serial.println((float)sensorValue * mv_per_lsb);
  delay(50);        // delay in between reads for stability
}

I have tried other voltages and this is what I see:

INPUT: 0.5V OUTPUT: 0.47V

INPUT: 1.5V OUTPUT: 1.41V

INPUT: 3.3V OUTPUT: 3.05V

So it seems to be slightly more accurate on the lower range.

My setup is a power supply with ground connected to the GND pin on the nRF and the power connected directly to the A3 pin on the nRF. The nRF is being powered over USB.

What am I missing here?

I also confirmed with a volt meter that the voltage output from my bench power supply is outputting correct values. Lastly I tried a brand new nRF board, and got same result.

4
  • 1
    This particular chip's analog inputs aren't measuring with respect to your 3.3V power supply; they are using an internal reference (that's likely a LOT more accurate than your power supply voltage), with default settings that make it equivalent to a 3.6V full-scale reading. You can use analogReference() to select between several options here. Commented Sep 15, 2023 at 18:39
  • Ok, so do I need to scale it somehow with respect to the 3.6V reference? Commented Sep 15, 2023 at 18:41
  • 1
    Just changing 3300 to 3600 in your mv_per_lsb calculation should fix it. Commented Sep 15, 2023 at 18:41
  • That did it! I can mark it as an answer if you add it. Thank you! Commented Sep 15, 2023 at 18:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.