Recall & Review
beginner
What is the purpose of the
smbus2 library in Raspberry Pi programming?The
smbus2 library allows easy communication with I2C devices by providing simple methods to read and write data over the I2C bus.Click to reveal answer
beginner
How do you open an I2C bus using
smbus2?You create an SMBus object with the bus number, for example:
bus = SMBus(1) opens I2C bus 1 on Raspberry Pi.Click to reveal answer
beginner
Which
smbus2 method would you use to write a single byte to a device?Use
write_byte(addr, value) where addr is the device address and value is the byte to send.Click to reveal answer
beginner
How can you read a byte from a specific register of an I2C device using
smbus2?Use
read_byte_data(addr, register) where addr is the device address and register is the register number to read from.Click to reveal answer
intermediate
Why is it important to close the SMBus object after communication?
Closing the SMBus object releases the I2C bus resource properly, preventing conflicts or errors when other programs try to use the bus.
Click to reveal answer
Which Python statement correctly opens I2C bus 1 using smbus2?
✗ Incorrect
The correct way is to create an SMBus object with the bus number:
bus = SMBus(1).What does the method
write_byte(addr, value) do?✗ Incorrect
It sends a single byte
value to the device at the given I2C address addr.Which method reads a byte from a specific register of an I2C device?
✗ Incorrect
read_byte_data(addr, register) reads a byte from the specified register.Why should you close the SMBus object after use?
✗ Incorrect
Closing releases the I2C bus so other programs can use it without conflicts.
What is the default I2C bus number on most Raspberry Pi models?
✗ Incorrect
Most Raspberry Pi models use I2C bus 1 by default.
Explain how to use the smbus2 library to write a byte to an I2C device on Raspberry Pi.
Think about opening the bus, sending data, and closing it.
You got /4 concepts.
Describe the steps to read a byte from a specific register of an I2C device using smbus2.
Focus on opening the bus, reading from a register, and closing the bus.
You got /4 concepts.
