<?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[Core2 as a scale - measured value jumps - measurement accurate to the gram?]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I have now bought this M5Stack Core2. It's a nifty little thing with great application possibilities. So now my first project with it...</p>
<p dir="auto">I want to determine the weight of food in a food bowl. I have a "scale kit" with 4 weight sensors (HX711) for the M5Stack Core2. I actually wanted to program via UIFlow 2, which looks very appealing and simple. But as a newbie, it's a bit overwhelming. So I switched to Python after all...</p>
<p dir="auto">So, everything is plugged in (absolutely simple) and I already have measured values on the display. But they still fluctuate too much. Countless measured values come in every second. So the idea is to collect the measured values for half a second and then only show the average value on the display. Unfortunately, I've been out of Python programming for so long that I can't do it without your help.</p>
<p dir="auto">Code:<br />
import os, sys, io<br />
import M5<br />
from M5 import *<br />
from hardware import *<br />
from unit import WEIGHTUnit</p>
<p dir="auto">label0 = None<br />
title0 = None<br />
label1 = None<br />
label2 = None<br />
weight_0 = None</p>
<p dir="auto">import math</p>
<p dir="auto">gewicht = None<br />
gewicht1 = None</p>
<p dir="auto">def btnA_wasClicked_event(state):<br />
global label0, title0, label1, label2, weight_0, gewicht, gewicht1<br />
weight_0.set_tare()</p>
<p dir="auto">def setup():<br />
global label0, title0, label1, label2, weight_0, gewicht, gewicht1</p>
<p dir="auto">weight_0 = WEIGHTUnit((33,32))<br />
M5.begin()<br />
Widgets.fillScreen(0x222222)<br />
label0 = Widgets.Label("label0", 45, 87, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu72)<br />
title0 = Widgets.Title("Futter/Feed", 3, 0xffffff, 0x0000FF, Widgets.FONTS.DejaVu40)<br />
label1 = Widgets.Label("Kg", 47, 163, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu24)<br />
label2 = Widgets.Label("&gt;0&lt;", 49, 224, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)</p>
<p dir="auto">BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)</p>
<p dir="auto">def loop():<br />
global label0, title0, label1, label2, weight_0, gewicht, gewicht1<br />
M5.update()<br />
gewicht = (weight_0.get_scale_weight) / 52000<br />
gewicht1 = round(gewicht, 1)<br />
if gewicht1 &lt;= 0.00:<br />
gewicht1 = 0.00<br />
label0.setText(str(gewicht1))<br />
sleep(1)</p>
<p dir="auto">if <strong>name</strong> == '<strong>main</strong>':<br />
try:<br />
setup()<br />
while True:<br />
loop()<br />
except (Exception, KeyboardInterrupt) as e:<br />
try:<br />
from utility import print_error_msg<br />
print_error_msg(e)<br />
except ImportError:<br />
print("please update to latest firmware")</p>
<hr />
<p dir="auto">Please help :-)<br />
Thank you</p>
]]></description><link>https://community.m5stack.com/topic/6190/core2-as-a-scale-measured-value-jumps-measurement-accurate-to-the-gram</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Mar 2026 01:38:24 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6190.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Mar 2024 16:40:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Core2 as a scale - measured value jumps - measurement accurate to the gram? on Fri, 08 Mar 2024 19:36:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/92138">@dreamer</a> This is 'roughly' how I average temperatures from sensor</p>
<pre><code>float room_temp_read[5] = { 25, 25, 25, 25, 25 };   //array of five reads
int x = 1;  //(declared in Setup)
//Read and Average subroutine
if (x &gt; 4) {
    x = 0;
  }

room_temp_read[x] = tempC;
room_tempAVG = (room_temp_read[0]
              + room_temp_read[1]
              + room_temp_read[2]
              + room_temp_read[3]
              + room_temp_read[4]
              + room_tempAVG * 8)
                 / 13;   //five reads + weighted average equals 13
   x++;  //increment to next array pointer
</code></pre>
<p dir="auto">There are five reads 0-4 and a heavy weighted average (times 8) of the last average results<br />
This is Arduino C, but just change the grammar for Python.<br />
-Terry</p>
]]></description><link>https://community.m5stack.com/post/24301</link><guid isPermaLink="true">https://community.m5stack.com/post/24301</guid><dc:creator><![CDATA[teastain]]></dc:creator><pubDate>Fri, 08 Mar 2024 19:36:30 GMT</pubDate></item></channel></rss>