pimoroni / pimoroni-pico

Libraries and examples to support Pimoroni Pico add-ons in C++ and MicroPython.
https://shop.pimoroni.com/collections/pico
MIT License
1.29k stars 492 forks source link

Lipo shim example is not compatible with the pico w #706

Open migs35323 opened 1 year ago

migs35323 commented 1 year ago

well, i spent a day troubleshooting my lipo shim or pico w thinking they were broken or my solder job was bad lol, it turns out the provided example is only for the normal pico, the pico w changes the internal pins to deal with the wifi stuff

so now i am not really sure how to get the VSYS and VBUS values for my lipo shim can someone help? the datasheet might provide a hint..datasheet for the led we can use Pin("LED") not sure if can use something like Pin("ADC3")

alphanumeric007 commented 1 year ago

It goes something like this.

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
    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)