@ajb2k3 The relay was not connected. I connected the Core2 directly to a Hub and used the following code. Do you see something that could be the reason for the error?
import os, sys, io
import M5
from M5 import *
from unit import WeightI2CUnit
from hardware import *
import time
from unit import PAHUBUnit
weight = None
airScale = None
notMedical = None
tareButton = None
measureButton = None
kg = None
i2c0 = None
pahub_0 = None
weight_i2c_0 = None
weight_i2c_1 = None
weight_i2c_2 = None
weight_i2c_3 = None
weight_i2c_4 = None
weight_i2c_5 = None
tare_weight = None
total_weight = None
adc0 = None
adc1 = None
Calibration
def calibration():
global tare_weight, total_weight, adc0, adc1, weight, airScale, notMedical, tareButton, measureButton, kg, i2c0, pahub_0, weight_i2c_0, weight_i2c_1, weight_i2c_2, weight_i2c_3, weight_i2c_4, weight_i2c_5
kg.setVisible(False)
weight.setText(str('START'))
time.sleep(5)
weight_i2c_0.set_reset_offset()
weight.setText(str('CAL'))
time.sleep(2)
adc0 = weight_i2c_0.get_adc_raw
weight.setText(str('WEIGHT'))
time.sleep(10)
adc1 = weight_i2c_0.get_adc_raw
weight.setText(str('DONE'))
time.sleep(2)
weight_i2c_0.set_calibration(0, adc0, 20000, adc1)
time.sleep(5)
weight_i2c_1.set_reset_offset()
weight.setText(str('CAL'))
time.sleep(2)
adc0 = weight_i2c_1.get_adc_raw
weight.setText(str('WEIGHT'))
time.sleep(10)
adc1 = weight_i2c_1.get_adc_raw
weight.setText(str('DONE'))
time.sleep(2)
weight_i2c_1.set_calibration(0, adc0, 20000, adc1)
time.sleep(5)
weight_i2c_2.set_reset_offset()
weight.setText(str('CAL'))
time.sleep(2)
adc0 = weight_i2c_2.get_adc_raw
weight.setText(str('WEIGHT'))
time.sleep(10)
adc1 = weight_i2c_2.get_adc_raw
weight.setText(str('DONE'))
time.sleep(2)
weight_i2c_2.set_calibration(0, adc0, 20000, adc1)
time.sleep(5)
weight_i2c_3.set_reset_offset()
weight.setText(str('CAL'))
time.sleep(2)
adc0 = weight_i2c_3.get_adc_raw
weight.setText(str('WEIGHT'))
time.sleep(10)
adc1 = weight_i2c_3.get_adc_raw
weight.setText(str('DONE'))
time.sleep(2)
weight_i2c_3.set_calibration(0, adc0, 20000, adc1)
time.sleep(5)
weight_i2c_4.set_reset_offset()
weight.setText(str('CAL'))
time.sleep(2)
adc0 = weight_i2c_4.get_adc_raw
weight.setText(str('WEIGHT'))
time.sleep(10)
adc1 = weight_i2c_4.get_adc_raw
weight.setText(str('DONE'))
time.sleep(2)
weight_i2c_4.set_calibration(0, adc0, 20000, adc1)
time.sleep(5)
weight_i2c_5.set_reset_offset()
weight.setText(str('CAL'))
time.sleep(2)
adc0 = weight_i2c_5.get_adc_raw
weight.setText(str('WEIGHT'))
time.sleep(10)
adc1 = weight_i2c_5.get_adc_raw
weight.setText(str('DONE'))
time.sleep(2)
weight_i2c_5.set_calibration(0, adc0, 20000, adc1)
weight.setText(str('END'))
Tare
def tare():
global tare_weight, total_weight, adc0, adc1, weight, airScale, notMedical, tareButton, measureButton, kg, i2c0, pahub_0, weight_i2c_0, weight_i2c_1, weight_i2c_2, weight_i2c_3, weight_i2c_4, weight_i2c_5
weight_i2c_0.set_reset_offset()
weight_i2c_1.set_reset_offset()
weight_i2c_2.set_reset_offset()
weight_i2c_3.set_reset_offset()
weight_i2c_4.set_reset_offset()
weight_i2c_5.set_reset_offset()
tare_weight = sum([weight_i2c_0.get_weight_float, weight_i2c_1.get_weight_float, weight_i2c_2.get_weight_float, weight_i2c_3.get_weight_float, weight_i2c_4.get_weight_float, weight_i2c_5.get_weight_float])
return tare_weight
Measure
def measure():
global tare_weight, total_weight, adc0, adc1, weight, airScale, notMedical, tareButton, measureButton, kg, i2c0, pahub_0, weight_i2c_0, weight_i2c_1, weight_i2c_2, weight_i2c_3, weight_i2c_4, weight_i2c_5
total_weight = sum([weight_i2c_0.get_weight_float, weight_i2c_1.get_weight_float, weight_i2c_2.get_weight_float, weight_i2c_3.get_weight_float, weight_i2c_4.get_weight_float, weight_i2c_5.get_weight_float])
return total_weight
def setup():
global weight, airScale, notMedical, tareButton, measureButton, kg, i2c0, pahub_0, weight_i2c_0, weight_i2c_1, weight_i2c_2, weight_i2c_3, weight_i2c_4, weight_i2c_5, tare_weight, total_weight, adc0, adc1
M5.begin()
Widgets.fillScreen(0x222222)
weight = Widgets.Label("250.0", 8, 90, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu72)
airScale = Widgets.Label("airScale", 5, 7, 1.0, 0x89c6ff, 0x222222, Widgets.FONTS.DejaVu12)
notMedical = Widgets.Label("Not for Medical Use!", 115, 5, 1.0, 0xff0000, 0x222222, Widgets.FONTS.DejaVu18)
tareButton = Widgets.Label("Tare", 23, 210, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu24)
measureButton = Widgets.Label("Measure", 210, 210, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu24)
kg = Widgets.Label("kg", 230, 90, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu72)
i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000)
pahub_0 = PAHUBUnit(i2c=i2c0, channel=0)
weight_i2c_0 = WeightI2CUnit(PAHUBUnit(i2c=i2c0, channel=0), 0x26)
weight_i2c_1 = WeightI2CUnit(PAHUBUnit(i2c=i2c0, channel=1), 0x26)
weight_i2c_2 = WeightI2CUnit(PAHUBUnit(i2c=i2c0, channel=2), 0x26)
weight_i2c_3 = WeightI2CUnit(PAHUBUnit(i2c=i2c0, channel=3), 0x26)
weight_i2c_4 = WeightI2CUnit(PAHUBUnit(i2c=i2c0, channel=4), 0x26)
weight_i2c_5 = WeightI2CUnit(PAHUBUnit(i2c=i2c0, channel=5), 0x26)
weight.setVisible(False)
weight_i2c_0.set_lowpass_filter(True)
weight_i2c_1.set_lowpass_filter(True)
weight_i2c_2.set_lowpass_filter(True)
weight_i2c_3.set_lowpass_filter(True)
weight_i2c_4.set_lowpass_filter(True)
weight_i2c_5.set_lowpass_filter(True)
weight_i2c_0.set_average_filter_level(50)
weight_i2c_1.set_average_filter_level(50)
weight_i2c_2.set_average_filter_level(50)
weight_i2c_3.set_average_filter_level(50)
weight_i2c_4.set_average_filter_level(50)
weight_i2c_5.set_average_filter_level(50)
weight.setText(str("%.1f"%((tare() / 1000))))
def loop():
global weight, airScale, notMedical, tareButton, measureButton, kg, i2c0, pahub_0, weight_i2c_0, weight_i2c_1, weight_i2c_2, weight_i2c_3, weight_i2c_4, weight_i2c_5, tare_weight, total_weight, adc0, adc1
M5.update()
if BtnA.wasClicked():
kg.setVisible(False)
weight.setText(str('Tare...'))
time.sleep(3)
weight.setText(str("%.1f"%((tare() / 1000))))
kg.setVisible(True)
if BtnB.wasHold():
calibration()
time.sleep(5)
weight.setText(str("%.1f"%((tare() / 1000))))
kg.setVisible(True)
if BtnC.wasClicked():
weight.setText(str('Warten..'))
time.sleep(10)
weight.setText(str("%.1f"%((measure() / 1000))))
kg.setVisible(True)
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")