Menu
Microbots
0
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • ProtoBot
    • Modules & Parts
    • Tools & Gears
    • Coming Soon
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Sign in
  • English
  • Your Cart is Empty
Microbots
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • ProtoBot
    • Modules & Parts
    • Tools & Gears
    • Coming Soon
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

CodeCell: I2C Communication

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.

I2C Pin Configuration

The I2C's SDA and SCL pins are located on the lower side of the CodeCell board.

  • SDA (Data Line) → GPIO8
  • SCL (Clock Line) → GPIO9
  • Speed → 400kHz (Fast Mode I2C)

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.

Built-in I2C Pull-up Resistors

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.

Reading Data from an I2C Device

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.

Basic Example: 

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);
}

I2C Scanner Example: 

The example below can be used to test external I²C devices connected to CodeCell’s pins. It will display the detected I²C slave addresses, including the onboard sensor.

#include <CodeCell.h>

CodeCell myCodeCell;

void setup() {
  Serial.begin(115200); // Set Serial baud rate to 115200 - Ensure Tools/USB_CDC_On_Boot is enabled if using Serial

  myCodeCell.Init(LIGHT); // Initializes Light Sensor

  // I2C Scanner
  Serial.println("Scanning I2C devices...");
  Wire.begin();
  byte error, address;
  int nDevices = 0;

  for (address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println(" !");
      nDevices++;
    } else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }

  if (nDevices == 0)
    Serial.println("No I2C devices found.\n");
  else
    Serial.println("Scan complete.\n");
}

void loop() {
  if (myCodeCell.Run(10)) { // Run every 10Hz
    
  }
}

External Sensor Example: 

Next up, we hook up an APDS9960 color sensor to the I²C pins and display the readings on the Serial monitor.

#include <CodeCell.h>
#include <Adafruit_APDS9960.h<

CodeCell myCodeCell;
Adafruit_APDS9960 apds;

uint16_t r, g, b, c;

void setup() {
  Serial.begin(115200);  // Set Serial baud rate to 115200 - Ensure Tools/USB_CDC_On_Boot is enabled if using Serial

  myCodeCell.Init(LIGHT);  // Initializes Light Sensor

  if (!apds.begin()) {
    Serial.println("failed to initialize device! Please check your wiring.");
  } else Serial.println("Device initialized!");

  //enable color sensign mode
  apds.enableColor(true);
}

void loop() {
  if (myCodeCell.Run(10)) {     //Run every 10Hz
    myCodeCell.PrintSensors();  //Print sensors data

    if (apds.colorDataReady()) {
      apds.getColorData(&r, &g, &b, &c);
      Serial.print(">> Color Sensors: R");
      Serial.print(r);
      Serial.print(",G");
      Serial.print(g);
      Serial.print(",B");
      Serial.println(b);
    }
  }
}

Conclusion

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!

  • Share:

Follow

Github

  • About
  • Software
  • Education
  • Contact
  • FAQs
  • Terms
  • Refund Policy
  • Privacy Policy

Join our Community ~ Be the first to know about new products and get exciting deals!

© 2026 Microbots.

★ Reviews

Let customers speak for us

67 reviews
Write a review
85%
(57)
6%
(4)
1%
(1)
3%
(2)
4%
(3)
62
21
C
CodeCell C3
Cloke74

Great piece of kit, had just what i needed to complete the project i had in mind. Shame shipping to the UK is so expensive, but appreciate this isn’t necessarily in the hands of MicroBots

A
CodeCell C6
Anonymous

I had an issue, got a red light, I used too much flux. Support said clean it, then the one sensor worked fine. I got the help and answer same day I provided a foto.

A
CodeCell C6 Drive
Anonymous

I think this is the best of the ESP offered, most versatile.

User picture
P
CodeCell C6
Prudhvi tej Chinimilli

Been testing the Microbots CodeCell C6 and honestly impressed with how much functionality they packed into such a tiny module. Great form factor for rapid prototyping wearable/embedded sensing applications. ESP32-C6 + IMU integration makes development much easier compared to building everything from scratch.

Still exploring battery optimization and compact LiPo options for our use case, but overall the platform is promising for low-cost real-time sensing systems. Excited to keep building with it.

F
CodeCell C6
Francisco Estivallet

Amazing hardware, my go to for compact projects.

User picture
123