Multiple I2C Devices on Same Bus
📖 Scenario: You have a Raspberry Pi connected to two I2C sensors on the same bus. You want to read data from both sensors without conflicts.
🎯 Goal: Write a Python program that communicates with two I2C devices on the same bus by specifying their addresses and reading data from each.
📋 What You'll Learn
Create a dictionary called
devices with two I2C device addresses as keys and their names as valuesCreate a variable called
bus_number and set it to 1 (the default I2C bus on Raspberry Pi)Use a
for loop with variables address and name to iterate over devices.items()Inside the loop, create an
SMBus object for bus_number and read a byte from each device addressPrint the device name and the byte read in the format:
Device {name} at address {address} returned {data}💡 Why This Matters
🌍 Real World
Many projects use multiple sensors on the same I2C bus to save wiring and pins. This skill helps you manage multiple devices efficiently.
💼 Career
Understanding how to communicate with multiple I2C devices is important for embedded systems, IoT development, and hardware interfacing roles.
Progress0 / 4 steps
