Last active
January 31, 2024 17:13
-
-
Save helgibbons/762fffc0dafd7eff11f429a1d2ed171a to your computer and use it in GitHub Desktop.
get_vsys.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_vsys(): | |
# Pico W voltage read function by darconeous on reddit: | |
# https://www.reddit.com/r/raspberrypipico/comments/xalach/comment/ipigfzu/ | |
conversion_factor = 3 * 3.3 / 65535 | |
import network | |
from machine import Pin, ADC | |
wlan = network.WLAN(network.STA_IF) | |
wlan_active = wlan.active() | |
try: | |
# Don't use the WLAN chip for a moment. | |
wlan.active(False) | |
# Make sure pin 25 is high. | |
Pin(25, mode=Pin.OUT, pull=Pin.PULL_DOWN).high() | |
# Reconfigure pin 29 as an input. | |
Pin(29, Pin.IN) | |
vsys = ADC(29) | |
return vsys.read_u16() * conversion_factor | |
finally: | |
# Restore the pin state and possibly reactivate WLAN | |
Pin(29, Pin.ALT, pull=Pin.PULL_DOWN, alt=7) | |
wlan.active(wlan_active) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment