Bird
0
0
Raspberry Piprogramming~10 mins

Why I2C is used with Raspberry Pi - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the library needed for I2C communication on Raspberry Pi.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Arandom
Bsmbus2
Cos
Dmath
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated libraries like os or math.
2fill in blank
medium

Complete the code to create an I2C bus object on Raspberry Pi.

Raspberry Pi
bus = smbus2.SMBus([1])
Drag options to blanks, or click blank then click option'
A0
B3
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using bus 0 which is often not enabled by default.
3fill in blank
hard

Fix the error in the code to write a byte value 0x01 to device address 0x20 on the I2C bus.

Raspberry Pi
bus.write_byte([1], 0x01)
Drag options to blanks, or click blank then click option'
A0x40
B0x30
C0x10
D0x20
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong device address causing no response.
4fill in blank
hard

Fill both blanks to read a byte from register 0x01 of device 0x20 using I2C.

Raspberry Pi
data = bus.read_byte_data([1], [2])
Drag options to blanks, or click blank then click option'
A0x20
B0x01
C0x10
D0x02
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping device and register addresses.
5fill in blank
hard

Fill all three blanks to write the value 0xFF to register 0x02 of device 0x20 using I2C.

Raspberry Pi
bus.write_byte_data([1], [2], [3])
Drag options to blanks, or click blank then click option'
A0x20
B0x02
C0xFF
D0x01
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up register and value positions.