While working on the wind direction vane for my weather station, I gathered some data on the accuracy of the ADC.
The wind vane contains 8 reed-switches arranged in an 8-pointed star shape on a small circular PCB. A small magnet in the rotating part of the vane actuates one of these reed switches, or, if it is roughly half way between two of them, it will actuate 2 adjacent reed switches together. Each reed switch has a different value resistor in series with it. If 2 adjacent reed switches are both active, their 2 resistors combine in parallel. So, the vane can have one of 16 different resistance values, depending on the wind direction.
I connected a fixed 10K resistor "R1" between the the XIAO ESP32C3's 3.3V pin and the A0 pin, and the vane "R2" was connected between A0 and ground, to make a voltage divider.
I wrote a short code to take the average of 1,000 values from digitalRead(A0) with 1ms delay between each reading and write the averages to serial monitor.
This is what I found:
| Direction | Vcc | R1 | R2 | Expected V | Actual V | Diff V | Expected ADC | Actual ADC | Diff ADC |
|---|---|---|---|---|---|---|---|---|---|
| 112.5 | 3.28 | 10000 | 688 | 0.21 | 0.21 | -0.5% | 263 | 282 | 7.1% |
| 67.5 | 3.28 | 10000 | 891 | 0.27 | 0.27 | 0.6% | 335 | 361 | 7.7% |
| 90 | 3.28 | 10000 | 1000 | 0.30 | 0.30 | 0.6% | 372 | 400 | 7.4% |
| 157.5 | 3.28 | 10000 | 1405 | 0.40 | 0.41 | 1.5% | 505 | 543 | 7.6% |
| 135 | 3.28 | 10000 | 2200 | 0.59 | 0.59 | -0.2% | 738 | 796 | 7.8% |
| 202.5 | 3.28 | 10000 | 3129 | 0.78 | 0.79 | 1.1% | 976 | 1058 | 8.4% |
| 180 | 3.28 | 10000 | 3890 | 0.92 | 0.92 | 0.2% | 1147 | 1244 | 8.5% |
| 22.5 | 3.28 | 10000 | 6568 | 1.30 | 1.30 | 0.0% | 1623 | 1774 | 9.3% |
| 45 | 3.28 | 10000 | 8200 | 1.48 | 1.48 | 0.1% | 1845 | 2024 | 9.7% |
| 247.5 | 3.28 | 10000 | 14115 | 1.92 | 1.92 | 0.0% | 2397 | 2643 | 10.3% |
| 225 | 3.28 | 10000 | 16000 | 2.02 | 2.02 | 0.1% | 2520 | 2779 | 10.3% |
| 337.5 | 3.28 | 10000 | 22239 | 2.26 | 2.26 | -0.1% | 2825 | 3116 | 10.3% |
| 0 | 3.28 | 10000 | 33000 | 2.52 | 2.52 | 0.1% | 3143 | 3486 | 10.9% |
| 292.5 | 3.28 | 10000 | 43459 | 2.67 | 2.66 | -0.2% | 3329 | 3719 | 11.7% |
| 315 | 3.28 | 10000 | 68200 | 2.86 | 2.86 | 0.0% | 3571 | 4050 | 13.4% |
| 270 | 3.28 | 10000 | 119800 | 3.03 | 3.02 | -0.2% | 3780 | 4095 | 8.3% |
At best, the ADC readings were 7% higher than I expected, and as the input voltage increased, the error got increasingly worse until, at an input voltage of just over 3V, the ADC hit its maximum 4095 reading.
I expected 4095 to correspond to around 3.3V.
I have read that the ESP32C3's ADC is not ratiometric, but may be based on it's internal voltage reference (1.1V).
As far as I can see, there are no voltage dividers on the XIAO's internal schematic, so I assume there is some configuration done to allow anaglodRead() to read up to around 3.3V for the analog input pins.
Could these inaccuracies be due to the inaccuracy of the chip's internal voltage reference, and is there some way to calibrate and correct for it?


