# Import necessary libraries import smbus2 import time # Define the I2C bus number (usually 1 for Raspberry Pi) bus_number = 1 # Define the I2C address of the device device_address = 0x04 # Initialize the I2C bus bus = smbus2.SMBus(bus_number) def read_integer_from_i2c(): try: # Read a byte from the I2C bus, switch to read_i2c_block_data if multiple bytes are sent data = bus.read_byte(device_address) print("Data received:", data) except Exception as e: print("Error reading from I2C bus:", e) while True: read_integer_from_i2c() time.sleep(1) # Delay of 1 second between reads