RP2: How to use ADC channel 3/GPIO pin 29 to measure VSYS on Pico W board #10421
-
firmware: rp2-pico-w-20221220-unstable-v1.19.1-782-g699477d12.uf2 MicroPython program import machine
import sys
print("sys.implementation:{}".format(sys.implementation))
print("sys.version:{}".format(sys.version))
pin = machine.ADC(29)
adc_reading = pin.read_u16()
adc_voltage = (adc_reading * 3.3) / 65535
vsys_voltage = adc_voltage * 3
print("""ADC reading:{}
ADC voltage:{}
VSYS voltage:{}""".format(adc_reading, adc_voltage, vsys_voltage)) on Raspberry Pi Pico W outputs
on Raspberry Pi Pico it outputs
equivalent CircuitPython program import analogio
import sys
from board import VOLTAGE_MONITOR
print("sys.implementation:{}".format(sys.implementation))
print("sys.version:{}".format(sys.version))
pin = analogio.AnalogIn(VOLTAGE_MONITOR)
adc_reading = pin.value
adc_voltage = (adc_reading * pin.reference_voltage) / 65535
vsys_voltage = adc_voltage * 3
print("""ADC reading:{}
ADC voltage:{}
VSYS voltage:{}""".format(adc_reading, adc_voltage, vsys_voltage))
pin.deinit() on Raspberry Pi Pico W (same board) it produces output
I know that on Pico-W this pin is shared with WiFi module. But I can not get correct output from Pico-W event after fresh .uf2 firmware upload with 0 WiFi module usage. Some related discussions: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Have you tried the provided solution here? Looking through this thread there seems to be problems restarting the wifi modul again, after changing GPIO29 and 25 to be able to read VSYS with ADC 3 https://forums.raspberrypi.com/viewtopic.php?p=2062543&hilit=ADC+29#p2062568 |
Beta Was this translation helpful? Give feedback.
-
Thank you, that recommendation worked. Test code: import machine
import sys
print("sys.implementation:{}".format(sys.implementation))
print("sys.version:{}".format(sys.version))
wl_cs = machine.Pin(25) # WiFi chip SDIO_DATA3 / gate on FET between VSYS divider (FET drain) and GPIO29 (FET source)
print("Initial WL_CS (GPIO25) state:{}".format(wl_cs))
wl_cs.init(mode=machine.Pin.OUT, value=1)
pin = machine.ADC(29)
adc_reading = pin.read_u16()
adc_voltage = (adc_reading * 3.3) / 65535
vsys_voltage = adc_voltage * 3
print("""ADC reading:{}
ADC voltage:{}
VSYS voltage:{}""".format(adc_reading, adc_voltage, vsys_voltage))
wl_cs.init(mode=machine.Pin.ALT, pull=machine.Pin.PULL_DOWN, alt=31)#try to restore initial WL_CS state and output
It means that MicroPython initializes GPIO used for WiFi module even if module is never used.
|
Beta Was this translation helpful? Give feedback.
-
There is a call to initialize the cyw43 driver directly in /ports/rp2/main.c when the rp2 firmware is build with the MICROPY_PY_NETWORK_CYW43 flag.
This means, to use a WL_GPIO pin in a alternative mode, it must always be reconfigured manually |
Beta Was this translation helpful? Give feedback.
-
It seems that I have not read Pico W datasheet carefully enough. There is a section about pins used for WiFi module and explanations about need to put GPIO25 high when using GPIO29 to read VSYS voltage:
RP2 port now has 15 different boards. I think there is no need to add something to MicroPhyton documentation about Pico W pin usage. Documentation chapter General information about the RP2xxx port needs section "Multitude of boards" as other ports has it:
This issue can be closed after someone will add |
Beta Was this translation helpful? Give feedback.
Have you tried the provided solution here? Looking through this thread there seems to be problems restarting the wifi modul again, after changing GPIO29 and 25 to be able to read VSYS with ADC 3
Can't test it myself at the moment.
https://forums.raspberrypi.com/viewtopic.php?p=2062543&hilit=ADC+29#p2062568