Hello guys
as stated before PaHUB and ENV III units cannot be used together as they share the same I2C address 0x70 by default. That said the I2C address of the PaHUB unit can be modified (let's say to use 0x71) to avoid the conflict.
And in UIFlow2 it is possible to use a PaHUB unit with modified I2C address. So in UIFlow2 add an ENV III unit and select PAHUB as BUS (which automatically will add a PaHUB unit as well). Then replace the resulting Init env3_0 block with an Execute code block with the following content:
env3_0 = ENVUnit(i2c=PAHUBUnit(i2c=i2c0, channel=0, address=0x71), type=3)
Note: ENV III unit is connected to the first channel of the PaHUB unit, e.g. channel 0.
Complete Micropython code:
import os, sys, io
import M5
from M5 import *
from hardware import *
import time
from unit import *
label0 = None
label1 = None
label2 = None
i2c0 = None
pahub_0 = None
env3_0 = None
def setup():
global label0, label1, label2, i2c0, pahub_0, env3_0
M5.begin()
label0 = Widgets.Label("label0", 3, 4, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
label1 = Widgets.Label("label1", 2, 22, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
label2 = Widgets.Label("label2", 2, 44, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
env3_0 = ENVUnit(i2c=PAHUBUnit(i2c=i2c0, channel=0 , address=0x71), type=3)
def loop():
global label0, label1, label2, i2c0, pahub_0, env3_0
M5.update()
time.sleep(1)
label0.setText(str(env3_0.read_temperature()))
label1.setText(str(env3_0.read_pressure()))
label2.setText(str(env3_0.read_humidity()))
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")
BTW: In UIFlow1 I have not been able to figure out how (if at all) it is possible to use a PaHUB unit with non default I2C address.
Thanks
Felix