Connecting multi TOF4m units via PA.hub - weird behaviour
-
Greetings I am trying to connect 2 TOF4m sensors to M5Stack Core Basic via Pa.hub.
Below basic blockly schematics. As soon as I connect second sensor to PAhub- labels react in a weird way. For example: If I put something near one of sensors - both labels change and show some random distance. As soon as I connect only one sensor to pahub - everything works fine and distance information works.
-
Hello @sqbaczek
assuming the programming is correct my best guess would be that the two ToF4m influence each other due to the signal they both send out. Maybe the signal of one gets reflected from the walls and then is picked up by both (and vice versa)?
BTW: have you tried the UIFlow2 instead? Do you get the same results?
Thanks
Felix -
Greetings @felmue!
Thank you for your reply,
Even if I space apart both sensors and direct them in different spots - they still get weird readings. As soon as I disconnect one of them from pa.hub one label gets proper readings - and other gets very simillar reading to first label (even though it is linked with disconnected sensor).
Below screenshot of readings with one sensor disconnected from pa.hub - and both labels change as soon as I get some object near the connected sensor.For UIflow 1 code is:
from m5stack import * from m5ui import * from uiflow import * import time import unit setScreenColor(0x222222) tof4m_0 = unit.get(unit.TOF4M, unit.PAHUB0) tof4m_1 = unit.get(unit.TOF4M, unit.PAHUB2) label0 = M5TextBox(43, 36, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0) label1 = M5TextBox(45, 88, "label1", lcd.FONT_Default, 0xFFFFFF, rotate=0) while True: label0.setText(str((str('odl 1 ') + str(((str(((tof4m_0.get_single_distance_value) / 10)) + str('cm'))))))) label1.setText(str((str('odl 2 ') + str(((str(((tof4m_1.get_single_distance_value) / 10)) + str('cm'))))))) wait_ms(500) wait_ms(2)
When I try to run it on UIflow 2.0 with pa.hub I get error:
Traceback (most recent call last):
File "<stdin>", line 29, in <module>
File "<stdin>", line 20, in setup
File "driver/vl53l1x.py", line 60, in init
File "driver/vl53l1x.py", line 176, in get_model_info
File "driver/vl53l1x.py", line 273, in _read_register
TypeError: unexpected keyword argument 'addrsize'This is my code for uiflow 2 - and it does not work
import os, sys, io import M5 from M5 import * from hardware import * from unit import TOF4MUnit from unit import PAHUBUnit label0 = None label1 = None i2c1 = None pahub_0 = None tof4m_2 = None tof4m_0 = None def setup(): global label0, label1, i2c1, pahub_0, tof4m_2, tof4m_0 M5.begin() Widgets.fillScreen(0x222222) label0 = Widgets.Label("label0", 44, 65, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label1 = Widgets.Label("label1", 43, 111, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) i2c1 = I2C(1, scl=Pin(22), sda=Pin(21), freq=100000) tof4m_0 = TOF4MUnit(PAHUBUnit(i2c=i2c1, channel=1), 0x29) tof4m_2 = TOF4MUnit(PAHUBUnit(i2c=i2c1, channel=0), 0x29) def loop(): global label0, label1, i2c1, pahub_0, tof4m_2, tof4m_0 M5.update() label0.setText(str((str('Odl1 ') + str((tof4m_2.get_distance))))) label0.setText(str((str('Odl2 ') + str((tof4m_0.get_distance))))) 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")
Thank you for help,
best,
Matt -
Hello @sqbaczek
unfortunately I don't have the proper hardware, e.g. TOF4m unit, so I cannot test this myself. Sorry.
BTW: are you aware that in UIFlow1 you use PaHUB channel 0 and 2 and in UIFlow2 you setup PaHUB channel 0 and 1.
Thanks
Felix -
Hi @felmue,
thanks for response - yes I have tried different ports on PA.hub so between two uiflows sensors might have different port values.best,
-
@sqbaczek
I think this might be some weird hardware problem, like a damaged component in the PaHUB causing the transmitted information to be incorrect... etc. Maybe the best way is to find a working one to test it. -
Greetings everyone! I have very similar error as @sqbaczek when running 1 ToF4M via PaHUB2 with CoreS3 and also Cardputer on UIflow 2.0. The ToF4M works fine when directly connected to the I2C port of either CoreS3 or Cardputer. It appears that ToF4M cannot be initiated when connected via PaHUB2 on UIflow 2.0.
Below is the error I get with CoreS3 when on UIflow 2.0:
Traceback (most recent call last): File "<stdin>", line 24, in <module> File "<stdin>", line 17, in setup File "driver/vl53l1x.py", line 60, in __init__ File "driver/vl53l1x.py", line 176, in get_model_info File "driver/vl53l1x.py", line 273, in _read_register TypeError: unexpected keyword argument 'addrsize'
Below is my code on UIflow 2.0:
import os, sys, io import M5 from M5 import * from hardware import * from unit import TOF4MUnit from unit import PAHUBUnit label0 = None i2c0 = None pahub_0 = None tof4m_0 = None def setup(): global label0, i2c0, pahub_0, tof4m_0 M5.begin() Widgets.fillScreen(0x222222) label0 = Widgets.Label("label0", 0, 0, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) tof4m_0 = TOF4MUnit(PAHUBUnit(i2c=i2c0, channel=0), 0x29) def loop(): global label0, i2c0, pahub_0, tof4m_0 M5.update() label0.setText(str(tof4m_0.get_distance)) 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")
I tested other units via PaHUB2 with CoreS3 on UIflow 2.0. These include Gesture Unit, 8Servos Unit, ENV Pro Unit, EXT.IO2 Unit. They all appear to work fine, at least not showing any initiation error.