m5stack tough for power monitoring suggestion
-
Hi
I'm looking to monitor amp and voltage usage on a wire with a clamp type transformer sensor and M5stack tough device. I
I have been trying to use SCT-013 20AMP/1V clamp sensor without any success. The configuration of the sensor is as per the attached figure
connecting it to the adc 36 pin and 3.3v supply and ground pins.
But not having much of a luck.
Is there any suggestion on the most cost effective and reliable method of monitoring 20 amps of power on a wire with minimal infrastructure, non invasive connection, using M5 stack tough device. I need specific suggestion on the use of clamp type sensor, code and wiring arrangements.
Thanks
-
what type of load are you monitoring?
-
@robski hi I have 20amp, 110v, 60hz load
-
@aiconnection what is your code that doesn't work?
-
@aiconnection
import M5
from M5 import *
from machine import ADC, Pin
import timeADC_PIN = 35
label_raw = None
def setup():
"""Initialize the system."""
global label_raw
try:
log("INFO", "Initializing system")
M5.begin()
Widgets.fillScreen(0xffffff) # White backgroundlabel_raw = Widgets.Label("Raw ADC:", 5, 40, 1.0, 0x000000, 0xffffff, Widgets.FONTS.DejaVu18) adc = ADC(Pin(ADC_PIN)) adc.atten(ADC.ATTN_11DB) # Set ADC range to 0-3.3V adc.width(ADC.WIDTH_12BIT) # Set 12-bit resolution log("INFO", "System initialized successfully") return adc except Exception as e: log("ERROR", f"Setup failed: {str(e)}") time.sleep(5) reset()
def log(level, message):
"""Log messages with a timestamp."""
ts = time.localtime()
print(f"[{level}][{ts[3]:02d}:{ts[4]:02d}:{ts[5]:02d}] {message}")def loop(adc):
"""Main loop to read and display raw ADC values."""
try:
while True:
# Read raw ADC value
raw_value = adc.read()# Update display label_raw.setText(f"Raw ADC: {raw_value}") # Log raw value log("DEBUG", f"Raw ADC: {raw_value}") # Wait before next reading time.sleep(5) except Exception as e: log("ERROR", f"Loop error: {str(e)}") time.sleep(5) reset()
if name == 'main':
try:
# Initialize system and ADC
adc = setup()# Start the main loop loop(adc) except Exception as e: log("ERROR", f"Fatal error: {str(e)}") time.sleep(5) reset()