# I2C

## How does it work?

I2C is a serial communication protocol, so data is transferred bit by bit along a single wire (the SDA line). The SCL line is used to synchronize the data transfer. The I2C protocol allows multiple devices to be connected to the same bus, and each device can be addressed individually. This is done by using a unique address for each device. Because of this, the I2C protocol is often used to connect sensors and other peripherals to microcontrollers. 

## How to use it with the **ESP32-S3 DevKitC**?

The **ESP32-S3 DevKitC** has a new method of using I2C. Instead of having default pins for the SDA and SCL lines, the user can assign any GPIO pin to be used as the SDA and SCL lines. This makes it more flexible to use I2C with the **ESP32-S3 DevKitC**. It also poses a new challenge because to use most sensors, the user needs to use a library that uses the default I2C pins. Since the **ESP32-S3 DevKitC** does not have default I2C pins, the user needs to modify the library to use the pins that they have assigned for the SDA and SCL lines. And that's whats so hard about it. 

## How did I use it?

I used the I2C protocol to connect the **ESP32-S3 DevKitC** to a SGP30 sensor, this sensor can measure the CO2 and TVOC levels in the air. I used the Adafruit_SGP30 library to communicate with the sensor. The library uses the default I2C pins, but after some testing and multiple sources listed below, I was able to the library without having to modify it, for the scl pin i used GPIO 8, and for the sda pin i used GPIO 9. 

When using an I2C scanner i was able to pick up addresses of sensors, oled displays and lcd displays using the GPIO 8 and 9 pins. None of the other pins worked without modification of the library. I did get the oled screen to work with a library where you can modify the pins. But this was not the case for the SGP30 sensor. 

Its pretty weird that it only works on default with GPIO 8 and 9, and i dont have a clear answer as to why this is the case. 

## Sources

- https://www.espressif.com/en/products/socs/esp32-s3
- https://learn.sparkfun.com/tutorials/i2c
- https://www.esp32.com/viewtopic.php?t=20070
- https://www.esp32.com/viewtopic.php?t=23659
- Copilot contributed to the grammatical correctness of this document.
  
This pinout diagram from an old esp32 board shows GPIO 8 and 9 as the default I2C pins. And this appears to be the case for the **ESP32-S3 DevKitC** as well. 

![ESP32-S2 Saola Pinout diagram](image.png)

**Written by Sietse**
