Raspberry pi PICO ADC reading
Asked 3 days ago
Modified today
Viewed 51 times
1
Why not get zero when taking ADC readings on Raspberry Pi Pico? Even though I ground the ADC pin, the analog reading always fluctuates between 10 to 20. How can analog reading be reduced to zero?
EditFollowFlag
asked Apr 21 at 6:32
1133 bronze badges
- 1Please share your code showing how you read the ADC. Note that it is a 12-bit ADC with 4096 quantisation levels, so a reading of 20 corresponds to just 0.5% noise. – Mark Setchell Apr 21 at 9:24
- Perhaps you can try the demo code in the following tutorial, and I can repeat your experiment and see if I get the same results as yours: how2electronics.com/…. – tlfong01 yesterday
- And a couple of troubleshooting suggestions: (1) Swapping technique: Pico has 4 ADC pins. You can swap the pin a see if all pins have the same error/tolerance levels. If all pins have move or less random error margins, say 1% of max analog signal value, then the might be the spec and you cannot change tha.t. (2) Pico has the Analog reference pin. If you use a low max/ reference signal level, say 1.8/2.0V, then if error rate is still 1% of max, you can have relevative lower error spec.round, then you would have less noise noice releated to power/mains ground noise, / to continue, … – tlfong01 yesterday
- / continued, … (3) Pico has a specific “Analog ground pin”, which you should use specifically for analog signal ground (also avoid, messing with power ground). (4) If your anslogue signal to measure is stable, low frequency, then you can use a low frequency filter to filter high frequency noise. (4) Avoid using long wiring/cables to reduce picking up surrounding noise. (5) use double shielded, pseudo differential pair wiring/cables twisted pair cables, … – tlfong01 yesterday
- Now let us use the following picture as a reference, focusing on the ADC pins in pink, and write a program to calibrate the Pico ADC performance: imgur.com/a/0oU6DOb – tlfong01 yesterday
- The How2Tlectronics tutorialha a good newbie explanation on how to do the programming: Raspberry Pi Pico Complete Guide| Pinout + Features + ADC Tutorial (08:56) + I2C + OLED + Internal Temperature Sensor + DHT11: youtube.com/watch?v=oaM80GyVIwA&t=2s. – tlfong01 yesterday
- The video tutorial part, starting from 08:56, actually points out why the ADC conversion results for 0V is not 0, but 200+. Perhaps we should do some modification to the program, as requested by the OP, to make the output range from 0 to 4096, instead of 200+ to 65536. – tlfong01 yesterday
- Now the time has come for us to try to write a program to give an ADC output range of 0 to 4096. Stay tuned, … – tlfong01 23 hours ago
1 Answer
Sorted by: Highest score (default) Date modified (newest first) Date created (oldest first)
0
Question
How to make Rpi Pico do ADC with an output range starting from zero, and hopefully no fluctuation of 10 to 20?
Answer
- I googled and found How2Electronics has a newbie friendly tutorial on Pico ADC, with a short demo code (References 1, 2. Appendices B, C).
- The demo code does not seem to have any problem as reported by the OP. So I decided to try the demo code in my Pico setup, to see if I can repeat the OP’s situation.
- I read the Pico datasheet which says that Pico ADC has an internal offset of about 30mV, and that its offset can be reduced by using an external voltage of 3.0V (Appendix D).
- Now the OP says his ADC results of 0V (signal grounded) always fluctuates between 10 and 20. So let me calculate if this 10~20 offset is within the Pico datasheet’s 20~30mV internal/intrinsic zero offset. Since Pico ADC resolution is 12 bit, and if 3V3 power rail is used as analog reference, then the intrinsic is 30mV / 3V * 4096 ~= 30/3000 * 4096 ~= 5 < 10. In other words, the OP’s zero offset seems twice the spec.
- I have not verified my always dodgy calculation. Perhaps I can verify it by working backwards: What is the offset in mV, if offset value is 20/4096. Suppose analog reference is 3V3, then offset in mV = 3V3 * (20/4096) = 3300mV * 20 / 4096 = 16mV, looks OK.
- Anyway, perhaps I can repeat the OP’s test and compare with his zero offsets.
- I modified/expanded How2Electronics’s demo program, to do the following: (a) Do ADC with the three ADC pins, ADC0, ADC1, ADC2, (b) Find max, min, avg values and print out results (Appdenix F).
/ to continue, …
References
(1) How to use ADC in Raspberry Pi Pico – How2Electronics, 2021apr21
(3) Rpi Pico Datasheet (4.3. Using the ADC) – Rpi
(4) Raspberry Pi Pico 3.3V_EN pin control voltage inquiry – EE.SE, Asked 2021jun22, Viewed 1k times
/ to continue, …
Appendices
Appendix A – Rpi Pico ADC Pinout

Appendix B – Rpi Pico wiring for testing ADC program v0.1
------------------------------------------------------------------------------------
Pin name Pin # Connected to
-------------------------------------------------------------------------------------
Rpi 3V3 Output 36 -
Rpi 3V3 Enable 37 -
Analog Gnd 33 Rpi Pico Ground
Analog Ref 35 Rpi 3V3
ADC0 26 Rpi Ground
ADC1 27 Rpi 3V3
ADC2 28 2V5
ADC3 - Not available, connected to Pico internal temperature sensor
-------------------------------------------------------------------------------------
Appendix C – How2Eloectronics’s ADC Demo Code

Appendix D – How to improve ADC Performance
Rpi Pico Datasheet (4.3. Using the ADC) – Rpi
4.3. Using the ADC
The RP2040 ADC does not have an on-board reference and therefore uses its own power supply as a reference.
On Pico the ADC_AVDD pin (the ADC supply) is generated from the SMPS 3.3V by using an R-C filter (201 ohms into 2.2μF). This is a simple solution but does have the following drawbacks:
- We are relying on the 3.3V SMPS output accuracy which isn’t great
- We can only do so much filtering and therefore ADC_AVDD will be somewhat noisy
- The ADC draws current (about 150μA if the temperature sense diode is disabled, but it varies from chip to chip) and therefore there will be an inherent offset of about 150μA200 = ~30mV*. There is a small difference in current draw when the ADC is sampling (about +20μA) so that offset will also vary with sampling as well as operating temperature.
Changing the resistance between the ADC_VREF and 3V3 pin can reduce the offset at the expense of more noise – which may be OK especially if the use case can support averaging over multiple samples.
Driving high the SMPS mode pin (GPIO23), to force the power supply into PWM mode, can greatly reduce the inherent ripple of the SMPS at light load, and therefore the ripple on the ADC supply. This does reduce the power efficiency of the board at light load, so the low-power PFM mode can be re-enabled between infrequent ADC measurements by driving GPIO23 low once more. See Section 4.4.
The ADC offset can be reduced by tying a second channel of the ADC to ground, and using this zero-measurement as an approximation to the offset.
For much improved ADC performance, an external 3.0V shunt reference, such as LM4040, can be connected from the ADC_VREF pin to ground.
Note that if doing this the ADC range is limited to 0-3.0V signals (rather than 0-3.3V), and the shunt reference will draw continuous current through the 200R filter resistor (3.3V-3.0V)/200 = ~1.5mA.
Note that the 1R resistor on Pico (R9) is designed to (maybe) help with shunt references that would otherwise become unstable when directly connected to 2.2μF. It also makes sure there is a little filtering even in the case that 3.3V and ADC_VREF are shorted together (which is a valid thing to do if you don’t care about noise and want to reduce the inherent offset).
Finally, R7 is a physically large 1608 metric (0603) package resistor, so can be relatively easily removed if a user wants to isolate ADC_VREF and do their own thing with the ADC voltage, for example powering it from an entirely separate voltage (e.g. 2.5V). Note that the ADC on RP2040 has only been qualified at 3.0/3.3V but should work down to about 2V.
Appendix E – Pico 3V3 Enable pin to enable 3V3 Power
Raspberry Pi Pico 3.3V_EN pin control voltage inquiry – Asked 2021jun22, Viewed 1k times

Appendix F – Testing Pico’s 3 ADC Pins V0.1
programName = 'testPicoAdcV01()'
programFunction = 'test Pico ADC pins GP26, 27, 28'
programDate = '2022apr25hkt1111'
programAuthor = 'tlfong01'
systemInfo = 'Chinese Windows 10, Thonny IDE 3.3.13, Python 3.7.9, Rpi Pico'
import machine
import utime
# *** Configuration ***
adcPinNum0 = 26
adcPinNum1 = 27
adcPinNum2 = 28
adcPin0 = machine.ADC(adcPinNum0)
adcPin1 = machine.ADC(adcPinNum1)
adcPin2 = machine.ADC(adcPinNum2)
adcPinDict = \
{
'0' : {
'AdcPinNum': 0,
'AdcPin' : adcPin0,
},
'1' : {
'AdcPinNum': 1,
'AdcPin' : adcPin1,
},
'2' : {
'AdcPinNum': 2,
'AdcPin' : adcPin2,
},
}
# *** Adc Functions ***
def getAdcResults(adcPinNum):
adcPin = adcPinDict[str(adcPinNum)]['AdcPin']
adcResults = adcPin.read_u16()
return adcResults
# *** Sample Test ***
#adcResults = getAdcResults(adcPinNum = 0)
#print(adcResults)
def getAdcResultsList(adcPinNumList):
adcResultsList = [0] * len(adcPinNumList)
for adcPinNum in adcPinNumList:
adcResults = getAdcResults(adcPinNum)
adcResultsList[adcPinNum] = adcResults
return adcResultsList
# *** Sample Tests ***
#adcResultsList = getAdcResultsList([0, 1, 2])
#print(adcResultsList)
def printAdcResultsList(adcResultsList):
print('ADC Results =', adcResultsList)
print('Max =', max(adcResultsList))
print('Min =', min(adcResultsList))
print('Avg =', (sum(adcResultsList)) / len(adcResultsList))
return
# *** Sample Tests ***
#adcResultsList = getAdcResultsList([0, 1, 2])
#printAdcResultsList(adcResultsList)
def testPicoAdcV01():
print('Name =', programName)
print('Function =', programFunction)
print('Date =', programDate)
adcResultsList = getAdcResultsList([0, 1, 2])
printAdcResultsList(adcResultsList)
return
# *** Main ***
testPicoAdcV01()
# *** End of Program ***
# *** Sample Output ***
'''
>>> %Run -c $EDITOR_CONTENT
Name = testPicoAdcV01()
Function = test Pico ADC pins GP26, 27, 28
Date = 2022apr25hkt1102
ADC Results = [208, 20645, 17828]
Max = 20645
Min = 208
Avg = 12893.67
>>>
'''
# *** End of sample output ***
/ to continue, …
Categories: Uncategorized