from machine import ADC, Pin
import utime
# Initialize ADC
adc = ADC(2) # Assuming you are using GPIO 26 for ADC input
burden_resistor = 2.2 # Total burden resistor value in ohms (10 ohm + 3.9 ohm)
adc_resolution = 65535 # 16-bit resolution
max_expected_voltage = 3 # Maximum expected voltage across the burden resistor
ct_ratio = 400 # CT ratio
def read_voltage_and_current():
# Read ADC value
adc_value = adc.read_u16()
# Convert ADC value to voltage
voltage = (adc_value / adc_resolution) * max_expected_voltage
# Calculate measured current (I = V/R)
measured_current = voltage / burden_resistor
# Scale up to real-world current
real_world_current = measured_current * ct_ratio
return voltage, measured_current, real_world_current
# Main loop
while True:
voltage, measured_current, real_world_current = read_voltage_and_current()
print(f"Measured Voltage: {voltage:.3f} V, Measured Current: {measured_current:.3f} A, Real-World Current: {real_world_current:.2f} A")
utime.sleep(1) # Read every 1 second
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
vcc1:VCC
r1:1
r1:2
gnd1:GND
pot1:GND
pot1:SIG
pot1:VCC