Scales Unit
UNIT Scales is a high precision low-cost I2C port weighing sensor, with a total weighing range of 20kgs. Adopt STM32F030 as the controller, HX711 as sampling chip and 20 kgs weighing sensor. With tare button and programable RGB LED. This Unit offers the customer with a highly integrated weighing solution, suitable for the applications of weighing, item counting, item movement Checking and so on.
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 ScalesUnit 10 11 12title1 = None 13label0 = None 14label1 = None 15i2c0 = None 16scales_0 = None 17 18 19def setup(): 20 global title1, label0, label1, i2c0, scales_0 21 22 M5.begin() 23 Widgets.fillScreen(0x222222) 24 title1 = Widgets.Title( 25 "ScaleUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 26 ) 27 label0 = Widgets.Label("label0", 3, 89, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 28 label1 = Widgets.Label("label1", 3, 132, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 29 30 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) 31 scales_0 = ScalesUnit(i2c0, 0x26) 32 scales_0.set_rgb_led(0x6600CC) 33 34 35def loop(): 36 global title1, label0, label1, i2c0, scales_0 37 M5.update() 38 if not (scales_0.get_button_status(2)): 39 scales_0.set_current_raw_offset() 40 label0.setText(str("Reset to zero")) 41 else: 42 label0.setText(str("Press Btn to reset")) 43 label1.setText( 44 str((str("Current weight:") + str((str((scales_0.get_scale_value(1))) + str("g"))))) 45 ) 46 47 48if __name__ == "__main__": 49 try: 50 setup() 51 while True: 52 loop() 53 except (Exception, KeyboardInterrupt) as e: 54 try: 55 from utility import print_error_msg 56 57 print_error_msg(e) 58 except ImportError: 59 print("please update to latest firmware")
UIFLOW2 Example:
class ScalesUnit
Constructors
- class ScalesUnit(i2c, address)
Initialize the ScalesUnit with I2C communication and an optional I2C address.
- Parameters:
i2c – The I2C or PAHUBUnit instance for communication.
address – The I2C address or a list/tuple of addresses for the scales unit.
UIFLOW2:
Methods
- ScalesUnit.get_button_status(status)
Retrieve the status of a button on the scales unit.
- Parameters:
status – The button status identifier.
- Returns:
The current status of the specified button.
UIFLOW2:
- ScalesUnit.set_button_offset(enable)
Enable or disable the button offset for the scales unit.
- Parameters:
enable – The offset enable value (1 to enable, 0 to disable).
UIFLOW2:
- ScalesUnit.set_rgbled_sync(control)
Set synchronization mode for the RGB LED.
- Parameters:
control – The control value for synchronization.
UIFLOW2:
- ScalesUnit.get_rgbled_sync()
Retrieve the synchronization mode of the RGB LED.
- Returns:
The synchronization mode value.
- ScalesUnit.set_rgb_led(rgb)
Set the RGB values for the LED.
- Parameters:
rgb – The RGB value as a 24-bit integer.
UIFLOW2:
- ScalesUnit.get_rgb_led()
Retrieve the current RGB values of the LED.
- Returns:
A list containing the RGB values.
UIFLOW2:
- ScalesUnit.get_scale_value(scale)
Get the scale value for the specified scale type.
- Parameters:
scale – The scale type identifier.
- Returns:
The scale value as an integer.
UIFLOW2:
- ScalesUnit.set_raw_offset(value)
Set the raw offset for the scales unit.
- Parameters:
value – The raw offset value as an integer.
UIFLOW2:
- ScalesUnit.set_current_raw_offset()
Set the current raw offset value for the scales unit.
UIFLOW2:
- ScalesUnit.set_calibration_zero()
Calibrate the scales unit for zero weight.
UIFLOW2:
- ScalesUnit.set_calibration_load(gram)
Calibrate the scales unit with a specified weight.
- Parameters:
gram – The weight value in grams for calibration.
UIFLOW2:
- ScalesUnit.get_device_inform(mode)
Get the device information for a specified mode.
- Parameters:
mode – The mode identifier for the requested information.
- Returns:
The device information value.
UIFLOW2:
- ScalesUnit.set_i2c_address(addr)
Change the I2C address of the scales unit.
- Parameters:
addr – The new I2C address value.
UIFLOW2: