Complete the code to import the I2C library.
import [1]
We use the smbus2 library to communicate over I2C on Raspberry Pi.
Complete the code to create an I2C bus object.
bus = smbus2.SMBus([1])On Raspberry Pi, I2C bus 1 is commonly used for sensor communication.
Fix the error in reading a byte from the sensor at address 0x48.
data = bus.read_byte_data([1], 0x00)
The sensor's I2C address is 0x48, so we must use that address to read data.
Fill both blanks to read two bytes and combine them into a 16-bit value.
high = bus.read_byte_data(0x48, [1]) low = bus.read_byte_data(0x48, [2]) value = (high << 8) | low
Register 0x00 is usually the high byte and 0x01 the low byte for sensor data.
Fill all three blanks to convert the raw sensor value to temperature in Celsius.
if value & [1]: value = value - [2] temperature = value * [3]
The highest bit (0x8000) indicates negative temperature in two's complement. We subtract 65536 to convert. The scale factor 0.0078125 converts raw units to Celsius.
