I am trying to read a couple of I2C (both at 0x28) sensors through a PCA9548A MUX.
/boot/config.txt has the following to lines at the bottom:When i try to detect with, i get a listing at 0x70, or 0x71, depending on if I hardwire the MUX to either 0x00 or 0x01.
Both sensors work well when I test them without the MUX.
Here is the sketch:Prior to reloading the OS, a similar sketch was working well. I likely am doing something wrong in the RPi configuration.
One interesting observation: with config.txt set at addr:0x70 and the MUX set at 0x00, I used to get a `UU` at 0x70, when doing a i2cdetect. After reloading the OS, this error no longer occurs. I get `71` or `70`, according to MUX setting... Just in case this gives you a hint of what might be wrong.
I coonect to the Rpi via SSH.
Thanks for your help
Cheers.
/boot/config.txt has the following to lines at the bottom:
Code:
[all]dtoverlay=w1-gpiodtoverlay=i2c-mux,pca9548,addr=0x70
Code:
i2cdetect -y 1
Both sensors work well when I test them without the MUX.
Here is the sketch:
Code:
import smbus2import timedef read_data_from_device(): # PCA9548A multiplexer address multiplexer_address = 0x70 #<--- same result with 0x71 device_channel = 0 device_address = 0x28 # Create an SMBus object bus = smbus2.SMBus(1) print(f"bus:{bus}") try: while True: bus.write_byte(multiplexer_address, 1 << device_channel) print('wrote bus') # Read 4 bytes from the device read_data = bus.read_i2c_block_data(device_address, 0, 4) print('read_data', read_data) # Group the first two bytes and last two bytes first_two_bytes = read_data[:2] # Display the grouped values print(f"channel{device_channel}: {first_two_bytes}") # Delay for 1 second time.sleep(1) except KeyboardInterrupt: print("\nProgram interrupted by user.") except Exception as e: print(f"An error occurred: {e}") finally: # Close the SMBus connection bus.close()if __name__ == "__main__": read_data_from_device()
One interesting observation: with config.txt set at addr:0x70 and the MUX set at 0x00, I used to get a `UU` at 0x70, when doing a i2cdetect. After reloading the OS, this error no longer occurs. I get `71` or `70`, according to MUX setting... Just in case this gives you a hint of what might be wrong.
I coonect to the Rpi via SSH.
Thanks for your help
Cheers.
Statistics: Posted by TriLife — Tue Jan 02, 2024 11:59 pm