import machine import time # [Ed note: Feb 10, 2021 from hippy in raspberrypi.org/forums t=301152] # [Ed note: ADC VREF can be read using ADC as either ADC(3) or ADC(29) but...] VSYS_ADC_INPUT = 3 # 3 or 29 # Using ADC(3) - Pin 29 needs to be set as input with no pulls. # Using ADC(29) - Pin 29 is automatically set as required. if VSYS_ADC_INPUT == 3: Pin = machine.Pin Pin(29, Pin.IN) vsysChannel = machine.ADC(3) else: vsysChannel = machine.ADC(29) # [Ed note: safest] while True: adcReading = vsysChannel.read_u16() adcVoltage = (adcReading * 3.3) / 65535 vsysVoltage = adcVoltage * 3 vbusVoltage = vsysVoltage + 0.275 # At 100mA print(adcReading >> 4, adcReading, adcVoltage, "|", vbusVoltage, "|", vsysVoltage) time.sleep(1) Example output VBUS VSYS 2016 32263 1.624596 | 5.148788 | 4.873788 2019 32311 1.627013 | 5.156039 | 4.881039 2009 32151 1.618956 | 5.131869 | 4.856869 2013 32215 1.622179 | 5.141537 | 4.866537 # [Ed note: if you change first line from 3 to 29 then rerun, results should not vary much 2021EMay20] /Source04_Read_VSYS.txt stored at http://ephotocaption.com/a/164/Source04_Read_VSYS.txt