ACMeasure Unit
C Measure Unit is a single-phase AC measurement module with isolation capabilities. It utilizes the STM32+HLW8032 scheme to monitor high-precision current, voltage, power, and other data in real time. The module features a built-in AC isolation chip, B0505ST16-W5, and communicates with the STM32 through the EL357 optocoupler isolation chip.
Support the following products:
Micropython Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import * 9from unit import ACMeasureUnit 10 11 12label0 = None 13title0 = None 14label1 = None 15i2c0 = None 16ac_measure_0 = None 17 18 19def setup(): 20 global label0, title0, label1, i2c0, ac_measure_0 21 22 M5.begin() 23 Widgets.fillScreen(0x222222) 24 label0 = Widgets.Label("label0", 1, 81, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 25 title0 = Widgets.Title( 26 "ACMeasureUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 27 ) 28 label1 = Widgets.Label("label1", 1, 125, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 29 30 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) 31 ac_measure_0 = ACMeasureUnit(i2c0, 0x42) 32 33 34def loop(): 35 global label0, title0, label1, i2c0, ac_measure_0 36 M5.update() 37 label0.setText(str((str("Voltage:") + str((ac_measure_0.get_voltage_str()))))) 38 label1.setText(str((str("Current:") + str((ac_measure_0.get_current_str()))))) 39 M5.update() 40 41 42if __name__ == "__main__": 43 try: 44 setup() 45 while True: 46 loop() 47 except (Exception, KeyboardInterrupt) as e: 48 try: 49 from utility import print_error_msg 50 51 print_error_msg(e) 52 except ImportError: 53 print("please update to latest firmware")
UIFLOW2 Example:
class ACMeasureUnit
Constructors
- class ACMeasureUnit(i2c, address)
Initialize the AC Measure unit by setting the I2C port and the AC Measure slave address.
- Parameters:
i2c – The I2C interface object or PAHUBUnit used for communication.
address – The I2C address of the AC Measure unit, default is 0x42.
UIFLOW2:
Methods
- ACMeasureUnit.init_i2c_address(slave_addr)
Initialize the I2C address for the AC Measure unit.
- Parameters:
slave_addr (int) – The I2C address of the AC Measure unit, should be between 1 and 127.
- ACMeasureUnit.get_voltage_str()
Get the voltage string value from the AC Measure unit.
- Returns:
The voltage value as a string.
UIFLOW2:
- ACMeasureUnit.get_current_str()
Get the current string value from the AC Measure unit.
- Returns:
The current value as a string.
UIFLOW2:
- ACMeasureUnit.get_active_power_str()
Get the active power string value from the AC Measure unit.
- Returns:
The active power value as a string.
UIFLOW2:
- ACMeasureUnit.get_apparent_power_str()
Get the apparent power string value from the AC Measure unit.
- Returns:
The apparent power value as a string.
UIFLOW2:
- ACMeasureUnit.get_power_factor_str()
Get the power factor string value from the AC Measure unit.
- Returns:
The power factor value as a string.
UIFLOW2:
- ACMeasureUnit.get_kwh_str()
Get the kWh string value from the AC Measure unit.
- Returns:
The kWh value as a string.
UIFLOW2:
- ACMeasureUnit.get_voltage_byte()
Get the raw voltage value from the AC Measure unit.
- Returns:
The raw voltage value as an integer.
UIFLOW2:
- ACMeasureUnit.get_current_byte()
Get the raw current value from the AC Measure unit.
- Returns:
The raw current value as an integer.
UIFLOW2:
- ACMeasureUnit.get_active_power_byte()
Get the raw active power value from the AC Measure unit.
- Returns:
The raw active power value as an integer.
UIFLOW2:
- ACMeasureUnit.get_apparent_power_byte()
Get the raw apparent power value from the AC Measure unit.
- Returns:
The raw apparent power value as an integer.
UIFLOW2:
- ACMeasureUnit.get_power_factor_byte()
Get the raw power factor value from the AC Measure unit.
- Returns:
The raw power factor value as an integer.
UIFLOW2:
- ACMeasureUnit.get_kwh_byte()
Get the raw kWh value from the AC Measure unit.
- Returns:
The raw kWh value as an integer.
UIFLOW2:
- ACMeasureUnit.get_voltage_coeff()
Get the voltage coefficient value from the AC Measure unit.
- Returns:
The voltage coefficient value as an integer.
UIFLOW2:
- ACMeasureUnit.set_voltage_coeff(value)
Set the voltage coefficient value for the AC Measure unit.
- Parameters:
value (int) – The voltage coefficient value to set, between 0 and 255.
UIFLOW2:
- ACMeasureUnit.get_current_coeff()
Get the current coefficient value from the AC Measure unit.
- Returns:
The current coefficient value as an integer.
UIFLOW2:
- ACMeasureUnit.set_current_coeff(value)
Set the current coefficient value for the AC Measure unit.
- Parameters:
value (int) – The current coefficient value to set, between 0 and 255.
UIFLOW2:
- ACMeasureUnit.set_save_coeff()
Save the voltage and current coefficient values to flash memory.
UIFLOW2:
- ACMeasureUnit.get_data_ready()
Check if the AC Measure unit data is ready.
- Returns:
True if data is ready, False otherwise.
UIFLOW2:
- ACMeasureUnit.set_jump_bootloader()
Set the AC Measure unit to jump to the bootloader.