Hi,
I have now bought this M5Stack Core2. It's a nifty little thing with great application possibilities. So now my first project with it...
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...
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.
Code:
import os, sys, io
import M5
from M5 import *
from hardware import *
from unit import WEIGHTUnit
label0 = None
title0 = None
label1 = None
label2 = None
weight_0 = None
import math
gewicht = None
gewicht1 = None
def btnA_wasClicked_event(state):
global label0, title0, label1, label2, weight_0, gewicht, gewicht1
weight_0.set_tare()
def setup():
global label0, title0, label1, label2, weight_0, gewicht, gewicht1
weight_0 = WEIGHTUnit((33,32))
M5.begin()
Widgets.fillScreen(0x222222)
label0 = Widgets.Label("label0", 45, 87, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu72)
title0 = Widgets.Title("Futter/Feed", 3, 0xffffff, 0x0000FF, Widgets.FONTS.DejaVu40)
label1 = Widgets.Label("Kg", 47, 163, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu24)
label2 = Widgets.Label(">0<", 49, 224, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)
def loop():
global label0, title0, label1, label2, weight_0, gewicht, gewicht1
M5.update()
gewicht = (weight_0.get_scale_weight) / 52000
gewicht1 = round(gewicht, 1)
if gewicht1 <= 0.00:
gewicht1 = 0.00
label0.setText(str(gewicht1))
sleep(1)
if name == 'main':
try:
setup()
while True:
loop()
except (Exception, KeyboardInterrupt) as e:
try:
from utility import print_error_msg
print_error_msg(e)
except ImportError:
print("please update to latest firmware")
Please help :-)
Thank you