I'm trying to do some analogRead() of a voltage with MKR1010 but the value is off by quite a bit from what's expected.
I've pretty much setup the simple voltage divider like one shown here https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput with same resistance values on the resistors so that voltage divided by half. When I measure on the A1 pin, I get 770, or 770 * (5 / 1023) = 3.76 V, 1.2 V greater than the expected 2.5 V.
As a sanity check, I went and measured everything with a multi-meter (albeit a cheap one that may not be too reliable). The resistance values were both pretty much the same at 22 k Ohm so no offset due to mismatch. I went and measure from the head of the top resistor and tail of bottom resistor and measured 4.8 V across both resistors. A little off from 5V claimed on source, but not too bad. Measured at the halfway point and got 2.35V, right around what's expected.
Thinking it maybe Arduino power source interfering somehow, I instead got a power supply independent of Arduino's 5V source pin and provided the voltage across divider and same result, multimeter showed 2.5V but Arduino analogRead() showed around 3.6V. I changed port from A1 to A2, same result. Tried grounding the pin and actually got 0 reading or 0V on analogRead() ; shorting it with resistor below got me 1023 or 5V so it seems to be working on the fringes. I'm stuck and cannot figure out where this 1.2V offset is coming from. Is this expected on analogRead() where it's expected to be a bit off and I need to calibrate it? Are there other steps I need to take to make it work? Am I missing something?
The microcontroller on the this board runs at 3.3V, which means that you must never apply more than 3.3V to its Digital and Analog pins. Care must be taken when connecting sensors and actuators to assure that this limit of 3.3V is never exceeded. Connecting higher voltage signals, like the 5V commonly used with the other Arduino boards, will damage the board.
What is the reference voltage for the ADC? Surely not 5V.
your 5/1023 (wrong anyway should be 1024) is for an arduino using a "default" reference of Vcc (ie 5V approx)
IF the ADC reference is 3.3V
AND the ADC is working at 10 bit resolution
then 770 * 3.3 / 1024 = 2.5V