UNO WiFi Rev2 Analog Read Problem

I am attaching a Sparkfun ACS72 current sensor to analog pin A2 on an UNO WiFi Rev2. I usually work with MEGA2560 boards but this project requires WiFi.

I've updated the IDE and firmware on the UNO to all the latest.

The current sensor VOUT range is 0-5VDC.

I initialize the analogReference to VDD as per:

...which says it's a 5VDC reference.

When I analogRead(A2) with the current sensor attached, the integer is always 1023 (max).

When I use a voltmeter to manually read VOUT from the current sensor, I correctly get slightly above 2.5VDC.

If I ground pin A2, analogRead(A2) correctly returns an integer zero.

If I change analogReference to EXTERNAL and connect the AREF pin to Arduino 5VDC, I get the same results.

It appears the analogReference method is not working correctly, but it could be lots of things.

I've searched this forum and the outer world in general for similar issues and have found none that apply.

Anyone else out there having an analogRead problem on this type of board?

DOH! (he said in a Homer Simpson voice)

Cut'n'paste error, analogReference was called in two places. The first occurrence used VDD as the argument, the later occurrence used DEFAULT.

Back to work, thanks.
G.

What made you think that your problem has anything to do with the workings of this Website and Forum?

I have suggested to the Moderator to move it to the Networking section.

...R

@gcw1957

Moved your topic to it's current location / section as it is more suitable.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.