- Install
- Basic operation
- Basics of programming for electronic work
- Basics of programming for Excel
- Machine learning with scikit-learn
- Visualizing data with matplotlib
- Web programming
- RPA programming
- Miscellaneous programming
- Reference
I2C Connection
It is very common to connect various sensors and other devices using I2C.
It has the advantage of being relatively easy to use, as you only need to connect four lines: power (VCC/GND), data (SDA), and clock (SCL).
This page explains how to connect with I2C.
Pins used for I2C connection
Depending on the microcontroller, the pins used for I2C connection (SDA/SCL) may be fixed, or you may be able to freely set the pin assignment.
Microcontrollers with fixed pins
The SDA/SCL pins are fixed on the following microcontrollers.
| Microcontroller | SDA pin | SCL pin | Pin position |
|---|---|---|---|
| ESP32 (unbranded) | GPIO21 | GPIO22 | See GPIO21/22 in this diagram |
| Raspberry Pi | GPIO2 | GPIO3 | See GPIO2/3 in this diagram |
| Raspberry Pi Pico (not W) | GP4 | GP5 | See GP4/5 in this diagram |
If you are using a microcontroller with fixed SDA/SCL pins and an I2C-connected module, use a block that does not specify a pin number during initialization.
For example, in the case of the temperature/pressure sensor BMP280, use the following block.
![]()
Microcontrollers with free pin assignments
In the following microcontrollers, you can freely change the pins assigned to SDA/SCL.
- ESP32-S3
- ESP32-C3
- Raspberry Pi Pico W
When using I2C-connected modules with these microcontrollers, use a block that specifies the pin number during initialization.
For example, in the case of the temperature/pressure sensor BMP280, use the following block.