Hi Leute,
ich habe mir jetzt mal diesen M5Stack Core2 zugelegt. Ist ein schickes kleines Teil mit tollen Einsatzmöglichkeiten. Jetzt also mein erstes Projekt damit...
Ich möchte das Gewicht von Futter in einer Futterschale ermitteln. Für den M5Stack Core2 habe ich ein "Scales-Kit" mit 4 Gewichtssensoren (HX711). Programmieren wollte ich eigentlich über UIFlow 2, wirkt optisch sehr ansprechend und einfach. Als Neuling ist das aber doch etwas überfordernd. Also bin ich doch zu Python gewechselt...
Also, alles angesteckt (absolut simple) ich habe auch schon mal Messwerte im Display. Die schwanken aber noch zu sehr. Pro Sekunde kommen unzählige Messwerte rein. Die Idee ist also die Messwerte eine für eine halbe Sekunde zu sammeln und dann nur den Mittelwert im Display anzuzeigen. Leider bin ich schon wieder so lange aus der Python-Programmierung raus, dass ich es nicht hinbekomme ohne eure Hilfe.
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, 2)
if gewicht1 <= 0.00:
gewicht1 = 0.00
label0.setText(str(gewicht1))
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")
Ich bin für jede Hilfe sehr dankbar ![]()