I2C Mux Support with BME280 Temperature / Humidity Sensor #391

Open
opened 2021-02-09 03:19:54 +00:00 by wickedbeernut · 1 comment
wickedbeernut commented 2021-02-09 03:19:54 +00:00 (Migrated from github.com)

Would you please consider supporting an TCA9548A I2C 8-channel multiplexer (e.g., SparkFun Qwiic Mux Breakout BOB-16784) in order to enable more than two BME280 temperature / humidity sensors (addresses 0x76 and 0x77)? In addition to an enclosure temperature / humidity sensor, I would like to enable a temperature / humidity sensor corresponding to up to five filament dryers. The mux may (should?) support other I2C temperature / humidity sensors such as SI7021, TMP102 and MCP9808.

The Python syntax is straightforward,

import qwiic_tca9548a
mux = qwiic_tca9548a.QwiicTCA9548A()
mux.enable_channels(CHANNEL)
# read BME280 temperature and humidity here
mux.disable_channels(CHANNEL)
Would you please consider supporting an TCA9548A I2C 8-channel multiplexer (e.g., [SparkFun Qwiic Mux Breakout BOB-16784](https://www.sparkfun.com/products/16784)) in order to enable more than two BME280 temperature / humidity sensors (addresses 0x76 and 0x77)? In addition to an enclosure temperature / humidity sensor, I would like to enable a temperature / humidity sensor corresponding to up to five filament dryers. The mux may (should?) support other I2C temperature / humidity sensors such as SI7021, TMP102 and MCP9808. The [Python syntax](https://learn.sparkfun.com/tutorials/qwiic-mux-hookup-guide#python-package-overview) is straightforward, ``` import qwiic_tca9548a mux = qwiic_tca9548a.QwiicTCA9548A() mux.enable_channels(CHANNEL) # read BME280 temperature and humidity here mux.disable_channels(CHANNEL) ```
wickedbeernut commented 2021-02-15 21:54:18 +00:00 (Migrated from github.com)

Here's a screen shot of the Dashboard plugin with four BME280 sensors ("Enclosure", "Dryer 1", "Dryer 2", and "Dryer 3" ... all four with address 0x77) and two TMP102 sensors ("Dryer 4" and "Dryer 5" ... both with address 0x48). For this proof of concept, I entered the mux channel number (0x00 - 0x07) as the "high byte" in the sensor address field (e.g., 0x0477). Here's a summary of the changes to BME280.py. Equivalent changes were made to tmp102.py.

import smbus
import sys
import time
import qwiic_tca9548a ###
from ctypes import c_short
from ctypes import c_byte
from ctypes import c_ubyte

if len(sys.argv) == 2:
    CHANNEL = int(sys.argv[1],16) >> 8 ###
    DEVICE = int(sys.argv[1],16) & 0xFF ###
else:
    print('-1 | -1')
    sys.exit(1)

bus = smbus.SMBus(1) # Rev 2 Pi, Pi 2 & Pi 3 uses bus 1
                     # Rev 1 Pi uses bus 0

mux = qwiic_tca9548a.QwiicTCA9548A() ###

# ...

def main():
  try:
    mux.enable_channels(CHANNEL) ###
    temperature,pressure,humidity = readBME280All()
    mux.disable_channels(CHANNEL) ###
    print('{0:0.1f} | {1:0.1f}'.format(temperature, humidity))
  except:
     print('-1 | -1')

if __name__=="__main__":
   main()

bcd

cde

Here's a screen shot of the Dashboard plugin with four BME280 sensors ("Enclosure", "Dryer 1", "Dryer 2", and "Dryer 3" ... all four with address 0x77) and two TMP102 sensors ("Dryer 4" and "Dryer 5" ... both with address 0x48). For this proof of concept, I entered the mux channel number (0x00 - 0x07) as the "high byte" in the sensor address field (e.g., 0x0477). Here's a summary of the changes to BME280.py. Equivalent changes were made to tmp102.py. ``` import smbus import sys import time import qwiic_tca9548a ### from ctypes import c_short from ctypes import c_byte from ctypes import c_ubyte if len(sys.argv) == 2: CHANNEL = int(sys.argv[1],16) >> 8 ### DEVICE = int(sys.argv[1],16) & 0xFF ### else: print('-1 | -1') sys.exit(1) bus = smbus.SMBus(1) # Rev 2 Pi, Pi 2 & Pi 3 uses bus 1 # Rev 1 Pi uses bus 0 mux = qwiic_tca9548a.QwiicTCA9548A() ### # ... def main(): try: mux.enable_channels(CHANNEL) ### temperature,pressure,humidity = readBME280All() mux.disable_channels(CHANNEL) ### print('{0:0.1f} | {1:0.1f}'.format(temperature, humidity)) except: print('-1 | -1') if __name__=="__main__": main() ``` ![bcd](https://user-images.githubusercontent.com/47407361/107995067-32edee80-6f9b-11eb-9d48-7df576e5d54b.png) ![cde](https://user-images.githubusercontent.com/47407361/107995905-51081e80-6f9c-11eb-92a9-ff15a6d05453.png)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Gandalf/OctoPrint-Enclosure#391