import time
from machine import SoftI2C, Pin, ADC
from machine_i2c_lcd import I2cLcd
time.sleep(0.1) # Wait for USB to become ready
# LCD Setup
LCDAddress = 0x27
i2c = SoftI2C(scl=Pin(21), sda=Pin(20), freq=400000) # connect scl to GPIO 21, sda to GPIO 20
lcd = I2cLcd(i2c, LCDAddress, 2, 16)
Ammeter = ADC(28)
def Get_Current():
VoltageReference = 3.3
ADCResolution = 65536
ShuntResistor = 0.5
RawCurrent = Ammeter.read_u16()
voltageAcrossShunt = (RawCurrent * VoltageReference) / ADCResolution;
Current = voltageAcrossShunt / ShuntResistor
return Current
def Display_Current():
Current = Get_Current()
StrCurrent = "{:.2f}A".format(Current)
lcd.move_to(0,0)
lcd.putstr("Current:")
lcd.move_to(0,1)
lcd.putstr(StrCurrent)
while True:
Display_Current()
time.sleep(1)Loading
pi-pico-w
pi-pico-w