<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[M5Stack MiniScale - can it work with Python using I2C?]]></title><description><![CDATA[<p dir="auto">I have been trying for some time to get the M5 MiniScale unit working with MicroPython using the  I2C protocol as published with the product listing. I am using Raspberry Pico microcontrollers.</p>
<p dir="auto">The process seems quite straightforward. I am resetting the offset and calculating the GAP as described. I have an accurate 100g calibration weight and have experimented with all the filter settings.</p>
<p dir="auto">I have three identical M5Stack MiniScale units, all bought new, but I have never been able to get any of them to zero correctly which as it stands makes them all pretty much useless for my intended purpose.</p>
<p dir="auto">The Unit-Mini Scales product page (SKU:U177) says that the unit is suitable for scientific experimentation (as such 0.01g resolution would not be unreasonable)  and it also states Python as a programming platform.</p>
<p dir="auto">I can't however find any information or Pyhton examples regarding this unit having searched high and low and before I conclude I may be wasting my time thought I'd post here to see if anyone has ever managed to get this unit working accurately, has experienced similar frustrations or may be able to point me in the right direction?</p>
]]></description><link>https://community.m5stack.com/topic/6827/m5stack-miniscale-can-it-work-with-python-using-i2c</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 13:21:46 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6827.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 24 Sep 2024 12:12:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5Stack MiniScale - can it work with Python using I2C? on Sun, 03 Nov 2024 08:15:49 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/162694">@xpackers</a>,<br />
i can help you with the micropython code for the miniScale unit.<br />
regarding the accuracy of the unit i have the same problem, its drifts a lot over time with or without calibration, i try to use the set_offset() function before each use but its useless over time.<br />
tried to take it a part and tighten the screws a little but also the same problem</p>
<p dir="auto">this is the <a href="http://miniUnit.py" target="_blank" rel="noopener noreferrer nofollow ugc">miniUnit.py</a></p>
<p dir="auto">from machine import I2C, Pin<br />
import time<br />
import struct</p>
<h1>Constants</h1>
<p dir="auto">DEVICE_DEFAULT_ADDR = 0x26</p>
<h1>Scale Registers</h1>
<p dir="auto">UNIT_SCALES_RAW_ADC_REG = 0x00<br />
UNIT_SCALES_CAL_DATA_REG = 0x10<br />
UNIT_SCALES_BUTTON_REG = 0x20<br />
UNIT_SCALES_RGB_LED_REG = 0x30<br />
UNIT_SCALES_SET_GAP_REG = 0x40<br />
UNIT_SCALES_SET_OFFSET_REG = 0x50<br />
UNIT_SCALES_CAL_DATA_INT_REG = 0x60<br />
UNIT_SCALES_CAL_DATA_STRING_REG = 0x70<br />
UNIT_SCALES_FILTER_REG = 0x80<br />
JUMP_TO_BOOTLOADER_REG = 0xFD<br />
FIRMWARE_VERSION_REG = 0xFE<br />
I2C_ADDRESS_REG = 0xFF</p>
<p dir="auto">class UnitScales:<br />
def <strong>init</strong>(self, sda=21, scl=22, addr=DEVICE_DEFAULT_ADDR):<br />
self._i2c = I2C(0, scl=Pin(scl), sda=Pin(sda), freq=400000)<br />
self._addr = addr</p>
<pre><code>def write_bytes(self, reg, data):
    self._i2c.writeto(self._addr, bytes([reg]) + data)

def read_bytes(self, reg, length):
    self._i2c.writeto(self._addr, bytes([reg]))
    return self._i2c.readfrom(self._addr, length)

def begin(self):
    try:
        self._i2c.readfrom(self._addr, 1)
        return True
    except OSError:
        return False

def get_btn_status(self):
    data = self.read_bytes(UNIT_SCALES_BUTTON_REG, 1)
    return data[0]

def set_led_color(self, color_hex):
    color = bytearray(3)
    color[0] = (color_hex &gt;&gt; 16) &amp; 0xff  # RED
    color[1] = (color_hex &gt;&gt; 8) &amp; 0xff   # GREEN
    color[2] = color_hex &amp; 0xff           # BLUE
    self.write_bytes(UNIT_SCALES_RGB_LED_REG, color)

def get_led_color(self):
    color = self.read_bytes(UNIT_SCALES_RGB_LED_REG, 3)
    return (color[0] &lt;&lt; 16) | (color[1] &lt;&lt; 8) | color[2]

def get_weight(self):
    data = self.read_bytes(UNIT_SCALES_CAL_DATA_REG, 4)
    return struct.unpack('&lt;f', data)[0]

def get_weight_int(self):
    data = self.read_bytes(UNIT_SCALES_CAL_DATA_INT_REG, 4)
    return int.from_bytes(data, 'little')

def get_weight_string(self):
    data = self.read_bytes(UNIT_SCALES_CAL_DATA_STRING_REG, 16)
    return ''.join([chr(b) for b in data if b != 0])

def get_gap_value(self):
    data = self.read_bytes(UNIT_SCALES_SET_GAP_REG, 4)
    return struct.unpack('&lt;f', data)[0]

def set_gap_value(self, offset):
    data = struct.pack('&lt;f', offset)
    self.write_bytes(UNIT_SCALES_SET_GAP_REG, data)

def set_offset(self):
    self.write_bytes(UNIT_SCALES_SET_OFFSET_REG, bytearray([1]))

def get_raw_adc(self):
    data = self.read_bytes(UNIT_SCALES_RAW_ADC_REG, 4)
    return int.from_bytes(data, 'little')

def set_i2c_address(self, addr):
    self.write_bytes(I2C_ADDRESS_REG, bytearray([addr]))
    self._addr = addr
    return self._addr

def get_i2c_address(self):
    data = self.read_bytes(I2C_ADDRESS_REG, 1)
    return data[0]

def get_firmware_version(self):
    data = self.read_bytes(FIRMWARE_VERSION_REG, 1)
    return data[0]

def jump_bootloader(self):
    self.write_bytes(JUMP_TO_BOOTLOADER_REG, bytearray([1]))
</code></pre>
]]></description><link>https://community.m5stack.com/post/26936</link><guid isPermaLink="true">https://community.m5stack.com/post/26936</guid><dc:creator><![CDATA[alien]]></dc:creator><pubDate>Sun, 03 Nov 2024 08:15:49 GMT</pubDate></item></channel></rss>