import time import board import busio from adafruit_mmc56x3 import MMC5603 from adafruit_bus_device.i2c_device import I2CDevice # Adressen der Multiplexer TCAADDR1 = 0x70 TCAADDR2 = 0x71 # Initialisiere I2C i2c = busio.I2C(board.SCL, board.SDA) # Funktion zur Auswahl des Kanals am Multiplexer def tcaselect(mux_address, channel): if channel > 7: return with I2CDevice(i2c, mux_address) as mux: mux.write(bytes([1 << channel])) # Überprüfen, ob die Multiplexer ansprechbar sind print("Überprüfe Multiplexer...") try: with I2CDevice(i2c, TCAADDR1) as mux: print("Multiplexer 1 (0x70) gefunden.") except: print("Multiplexer 1 (0x70) nicht gefunden.") try: with I2CDevice(i2c, TCAADDR2) as mux: print("Multiplexer 2 (0x71) gefunden.") except: print("Multiplexer 2 (0x71) nicht gefunden.") # Initialisiere jeden Sensor an den entsprechenden Kanälen der Multiplexer sensors = [] sensor_found = [] for i in range(16): mux_address = TCAADDR1 if i < 8 else TCAADDR2 channel = i % 8 tcaselect(mux_address, channel) print(f"Initialisiere Sensor auf MUX {1 if i < 8 else 2}, channel {channel}") try: sensor = MMC5603(i2c) sensors.append(sensor) sensor_found.append(True) print(f"Sensor gefunden auf MUX {1 if i < 8 else 2}, channel {channel}") except ValueError: sensors.append(None) sensor_found.append(False) print(f"Ooops, no MMC5603 detected on MUX {1 if i < 8 else 2}, channel {channel}") # Zeige Details für jeden gefundenen Sensor for i in range(16): if sensor_found[i]: print(f"Sensor {i + 1}:") print(sensors[i]) while True: for i in range(16): mux_address = TCAADDR1 if i < 8 else TCAADDR2 channel = i % 8 tcaselect(mux_address, channel) print(f"Abfrage Sensor auf MUX {1 if i < 8 else 2}, channel {channel}") if sensor_found[i]: sensor = sensors[i] mag_x, mag_y, mag_z = sensor.magnetic temp_c = sensor.temperature print(f"Sensor {i + 1}: X={mag_x} uT, Y={mag_y} uT, Z={mag_z} uT, Temp: {temp_c} *C") else: print(f"Sensor {i + 1}: X=0 uT, Y=0 uT, Z=0 uT, Temp: 0 *C") print("****************************") time.sleep(10)