Interfacing sensors using the I2C interface
In this section, we will make use of the I2C (pronounced I-squared-C) interface to read temperature and humidity from the HTU21D sensor. We will read the temperature and display it on an OLED display.
Introduction to the I2C interface
In the previous section, we discussed the UART interface, which is asynchronous; that is, there is no reference clock signal. Now, we are going to discuss the I2C interface, which is synchronous and typically consists of a clock pin (for the reference clock signal) and a data pin. The following figure shows a schematic representation of devices on an I2C bus where we have a host device, which is usually a microcontroller such as the RP2040, and the sensors interface using the clock and data lines. Each sensor on the bus has a unique address that enables the host to communicate with the devices present on the bus. The following figure shows the host and peripheral devices on an I2C bus.