Which of the following best explains why I2C is commonly used with Raspberry Pi?
Think about how many wires I2C uses and how many devices it can connect.
I2C uses just two wires (SDA and SCL) to connect multiple devices, which saves GPIO pins on the Raspberry Pi and simplifies wiring.
Consider this Python code snippet that scans for I2C devices connected to a Raspberry Pi:
import smbus
bus = smbus.SMBus(1)
for device in range(0x03, 0x78):
try:
bus.read_byte(device)
print(f"Device found at address: 0x{device:02X}")
except OSError:
passIf devices are connected at addresses 0x20 and 0x48, what will be printed?
import smbus bus = smbus.SMBus(1) for device in range(0x03, 0x78): try: bus.read_byte(device) print(f"Device found at address: 0x{device:02X}") except OSError: pass
The code tries to read from each address and prints only if a device responds.
The code scans addresses from 0x03 to 0x77. Devices at 0x20 and 0x48 respond, so their addresses are printed.
Look at this Python code snippet intended to write a byte to an I2C device:
import smbus bus = smbus.SMBus(1) address = 0x40 bus.write_byte(address, 0xFF)
When running, it raises an OSError: [Errno 121] Remote I/O error. What is the most likely cause?
Think about hardware connections and device presence on the bus.
The error usually means the Raspberry Pi cannot find a device at the given address, often because it is not connected or powered.
Choose the correct Python code to initialize the I2C bus 1 on Raspberry Pi.
Bus 1 is the standard I2C bus on Raspberry Pi models after revision 2.
Bus 1 is the correct bus number for I2C on most Raspberry Pi models. Bus 0 is for older models. The bus number must be an integer.
Given the 7-bit addressing scheme of I2C, what is the maximum number of unique devices that can be connected to a single I2C bus on a Raspberry Pi?
7-bit addressing means 2^7 minus reserved addresses.
I2C uses 7-bit addresses, allowing up to 128 addresses (0 to 127). Some addresses are reserved, so the practical max is 127 devices.
