Bird
0
0
Raspberry Piprogramming~5 mins

smbus2 library for I2C in Raspberry Pi - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Abus = SMBus(1)
Bbus = SMBus.open(1)
Cbus = smbus2(1)
Dbus = open_smbus(1)
What does the method write_byte(addr, value) do?
ACloses the I2C bus
BReads a byte from the device at address <code>addr</code>
CWrites a byte to the device at address <code>addr</code>
DOpens the I2C bus
Which method reads a byte from a specific register of an I2C device?
Aread_byte_data(addr, register)
Bwrite_byte_data(addr, register, value)
Cread_byte(addr)
Dread_word_data(addr)
Why should you close the SMBus object after use?
ATo save memory
BIt is not necessary
CTo speed up the program
DTo release the I2C bus resource
What is the default I2C bus number on most Raspberry Pi models?
A0
B1
C2
D3
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.