Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4999

General • Re: Help with Pico ADC project

$
0
0
Are you sure this bit is right?

Code:

# Create an ADC object linked to pin 26adc = ADC(Pin(26, mode=Pin.IN))
I've done very little in microPython on the Pico so far, and could be wrong, but that looks like it's setting the pin up as a GPIO for input, not an ADC channel.
It does, but that should work. The 'Pin()' will set the pin as a digital input but it will be a digital input by default at power-on and after reset, so no change in configuration except any enabled pull-down is disabled. The 'ADC()' should then enable analogue input on that pin.
I would use

Code:

# Create an ADC object linked to pin 26adc = ADC(26)
(untested)
That should also work the same as above. But there have been bugs with 'ADC()' incorrectly initialising pins, particularly in not disabling the pull-down, and those bugs come and go with different firmware versions; 'ADC(0)' and 'ADC(26)' not always behaving identically when they should.

In theory all these should deliver the same outcome but I am not sure what the state of play is with latest firmware, or any particular version of firmware -

Code:

adc = ADC(Pin(26, Pin.IN))adc = ADC(Pin(26))adc = ADC(26)adc = ADC(0)
Arguably the first is better to use where buggy behaviour may exist because it should select the ADC0 channel and disable the pull-down even if 'ADC()' doesn't.
I just wish I actually knew how to code this stuff because every time I need to test something I am stuck :(
Which is why I suggested embarking on a proof of concept adventure with just reading a pot.

If that doesn't work there is no way that reading the switches using ADC ever will; you are just wasting your time trying to make it work.

You currently have no idea if things aren't working because ADC isn't working or there is some issue with what you have or how you are trying to use it. If you know ADC works with a pot then you know it should work with the switch.
The board shown in your most recent image is NOT a Raspberry Pi Pico board.
It looks like a Pico clone with some added features. The pinout looks to be the same so ADC pins should be in the same place and work the same.
But what about VREF ?

On the Pico and Pico W the VREF is hard-wired to be almost 3V3. On a third-party board that may not be so. It may not be connected, VREF may need to be supplied to it.

It's not clear from the datasheet how the ADC convertor behaves if VREF is floating, not connected - I don't recall that VREF voltage ranges are even stated in the datasheet. It's entirely possible that ADC could always read near zero or maximum when not connected. Near zero is what I recall was reported by someone who had a board where VREF was not connected.

Undertaking the proof of concept adventure with a pot as above should identify such issues and solutions.

In this case we are dealing with quite high resistances, a 100K pull-up which could have an impact on ADC behaviour, particularly Sample & Hold capacitor charge times. That may also need dealing with. I would suggest putting resistors in parallel with the switch's internal 100K 'no push' resistors to allow lower value pull-ups to be used. But that's for later, after we know ADC reading is working.

Statistics: Posted by hippy — Wed Jun 19, 2024 12:24 pm



Viewing all articles
Browse latest Browse all 4999

Trending Articles