Reading analog values on PicoW

I have a 2-wire anemometer (RED = Signal, Yellow = Ground) that provides a voltage proportional to wind speed that ranges between 0 and 2.5v. It is connected to ADC0 (Pin 26).

I have a function that reads the value on the pin, divides by 65535 (as its a 16-bit int) to get a voltage to which I then apply a formula to convert the voltage to wind speed in m/s.


from machine import Pin, ADC

anemometer = ADC(26) # ADC(0)

def get_w_Speed():
    adc_Val = anemometer.read_u16()
    volt_Val = ((adc_Val / 65535) * 3.3)
    w_speed = ((volt_Val *2) /5)*32.4
    return w_speed

wind_Sp = get_w_Speed()  

With the pin not connected to the anemometer, I get a value that apoproximates to 7m/s.

I assume this is “noise” as the pin is in an undefined state.

I’ve been told that I:

(a) need a “pull down” resistor circa 10k
(b) need a 10nf capacitor between the pin and ground
(c) need both (a) and (b)

Can someone please advise which, if any is correct and if not, what the solution is?

Learning to deal with new hardware and a new programming language (python) is hard for my 67 year old brain (despite over 50 years of FORTAN IV, COBOL, Pascal and Basic on mainframes)!


1 Like

Hi Alan,

Good to see you’ve got the built-in ADC working. Because of how the Pi Foundation implemented the design of the ADC in the Pico boards there is a certain amount of noise (fluctuating variation in readings) or offset (inaccuracy of the reading by a consistent margin). Most of these are due to the way the ADC uses it’s own power supply as a reference voltage. Any variation in the power supply will then result in an error in the reading on your ADC.

This is explained in more detail in the official documentation for the Pico on page 13.

I can see in that there are a few options provided in the official documentation but most require hardware modification or external circuitry, and most have a tradeoff where you reduce offset but may increase noise.

One hardware-free option to work around noise would be to add some software averaging to your ADC measurements. This will make your data less responsive but based on how frequently you need windspeed updates it may be a minor compromise.

Thank you for that.

Given that this is not a mission critical application, I think I’ll just log the readings at 10 second intervals for 24 hours or so and then subtract the average in my code to give a “near enough” reading.

Bit sad though. I understand the ADC on the ESP32 family absolutely sucks, hence my use of the Pico.

I suppose another alternative is to do the readings with an Arduino (or an ATTiny88 or similar) and then communicate that to the Pico, or directly to the Raspberry Pi, which will be the eventual destination anyway.


Hi Alan,

That would be one workaround, alternatively there are external ADCs with greater precision that you could use with the Pico, which would also allow you to chose an external power supply.

1 Like

Thanks for that.

I ordered one of the Adafruit devices today and shall see how I go.