Issues with Pahub - Some I2C units work, others don't
-
Hi. I am a newbie. I am having issues getting some, but not all I2C units to work with the pahub. I have a Core S3 (lite) and am using Uiflow 2.0. I want to connect the following units to the hub: NCIR, Weight I2C, Tof4m and ENVIII via the Pahub. I can get the NCIR weight I2C units to work without any trouble, but I cannot get the Tof4m and ENVIII to work with the hub although they work fine connected directly to the S3.
Here is some example code. I have included the NCIR, weight I2C and the ToF4m. If I delete the Init for the Tof4m and "get target distance" blocks then the program runs fine and displays the output from the NCIR and Weight I2C on the screen as I want it to. Here is the code before I delete the Tof4m related blocks:import os, sys, io
import M5
from M5 import *
from hardware import *
from unit import TOF4MUnit
from unit import NCIRUnit
from unit import PAHUBUnit
from unit import WeightI2CUnit
import timelabel0 = None
label1 = None
label2 = None
i2c0 = None
pahub_0 = None
ncir_0 = None
weight_i2c_0 = None
tof4m_0 = Nonedef setup():
global label0, label1, label2, i2c0, pahub_0, ncir_0, weight_i2c_0, tof4m_0M5.begin()
Widgets.fillScreen(0x222222)
label0 = Widgets.Label("label0", 2, 30, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
label1 = Widgets.Label("label1", 1, 62, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
label2 = Widgets.Label("label2", -2, 88, 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=2), 0x29)
pahub_0 = PAHUBUnit(i2c=i2c0, channel=0)
ncir_0 = NCIRUnit(PAHUBUnit(i2c=i2c0, channel=0))
weight_i2c_0 = WeightI2CUnit(PAHUBUnit(i2c=i2c0, channel=1), 0x26)def loop():
global label0, label1, label2, i2c0, pahub_0, ncir_0, weight_i2c_0, tof4m_0
M5.update()
label0.setText(str(ncir_0.get_ambient_temperature()))
label1.setText(str(weight_i2c_0.get_adc_raw))
label1.setText(str(tof4m_0.get_distance))
time.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")With the ToF4m blocks added I get the following error:
Traceback (most recent call last):
File "<stdin>", line 39, in <module>
File "<stdin>", line 26, 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'I get a similar one with the ENVIII. I always ensure that the bus is set to PAHUB for the units and the PAHUB numbers match the physical port. Any help would be appreciated as I am getting very frustrated. I have even bought a new hub and tried that, but it didn't help.
-
Hello @BJHSartorius
first of all for your setup there is no need for a PaHub as all four I2C units have different I2C addresses and therefore all four units can be connected in parallel using these. You can read about I2C here.
I2C addresses of your four units: NCIR: 0x5A; Weight I2C: 0x26; Tof4m: 0x29; ENV III: 0x44/0x70
That said, I don't know why there is an issue when ToF4m is added.
However, I do know why there is an issue with PaHub and ENV III. They both share the same I2C address (0x70). In other words PaHub and ENV III can never be used on the same I2C bus unless you manually (soldering required) change the I2C address of the PaHub; see here.
Thanks
Felix