I2C is a widely used protocol for communicating with sensors, displays, and other peripherals. CodeCell simplifies I2C communication by automatically configuring the I2C bus at initialization, so you can start using it right away.
The I2C's SDA and SCL pins are located on the lower side of the CodeCell board.
CodeCell automatically configures I2C in the Init()
function, and this configuration cannot be changed if you plan to use the onboard light and motion sensors, as they are connected to the same I2C bus.
The following onboard sensors are already using I2C, so make sure not to use the same addresses when connecting other I2C devices like displays, additional sensors, or modules:
Sensor | Address |
---|---|
VCNL4040 (Light Sensor) | 0x60 |
BNO085 (IMU - Motion Sensor) | 0x4A |
Note: If a new I2C device has the same address as one of these onboard sensors, they will conflict, and you may get incorrect or no data.
To ensure stable I2C communication, CodeCell has 2kΩ pull-up resistors already connected to the SDA and SCL lines. This means you don’t need to add external pull-ups when using external I2C sensors.
To communicate with an external I2C device, use the standard 'Wire.h' library.
Unlike standard Arduino I2C devices, CodeCell has multiple onboard sensors on the same I2C bus. Calling Wire.endTransmission(false);
ensures the bus stays active, allowing the onboard sensors to function properly.
Wire.beginTransmission(SLAVE_ADDRESS); // Start communication with the device
Wire.write(SLAVE_REG); // Send the register we want to read
Wire.endTransmission(false); // Don't release the bus (needed for onboard sensors)
Wire.requestFrom(SLAVE_ADDRESS, 1); // Request 1 byte from the slave
if (Wire.available()) {
uint8_t data = Wire.read(); // Read received byte
Serial.println(data);
}
CodeCell automatically configures the I2C bus, so no need to manually set it up. It also automatically configures the onboard sensors, while also supporting additional I2C devices!
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.