I2C (Inter-Integrated Circuit)#

Discover the I2C communication protocol and learn how to communicate with I2C devices using the PULSAR C6 board. This section will cover I2C bus setup and communication with I2C peripherals.

I2C Overview#

I2C (Inter-Integrated Circuit) is a synchronous, multi-master, multi-slave, packet-switched, single-ended, serial communication bus. It is commonly used to connect low-speed peripherals to processors and microcontrollers. The PULSAR C6 development board features I2C communication capabilities, allowing you to interface with a wide range of I2C devices.

Pinout Details#

Below is the pinout table for the I2C connections on the PULSAR C6, detailing the pin assignments for SDA and SCL.

Table 2 ESP32-C6 Pinout#

Pin

Function

A4 (SDA)/D18

GPIO22 / SDIO_DATA2

A5 (SCL)/D19

GPIO23 / SDIO_DATA3

I2C LP - Inter-Integrated Circuit Low Power#

The I2C LP (Low Power) mode is designed to reduce power consumption during I2C communication. This is particularly useful for battery-powered devices that need to conserve energy. In this mode, the I2C bus operates at lower frequencies and employs various techniques to minimize power usage.

I2C

Fig. 14 I2C Pins#

Table 3 ESP32-C6 Pinout LP#

Pin

Function

D13 (SDA)

GPIO6 /LP_SDA

D11 (SCL)

GPIO7 / LP_SCL

I2C

Fig. 15 I2C Pins#

Scanning for I2C Devices#

To scan for I2C devices connected to the bus, you can use the following code snippet:

import machine

i2c = machine.I2C(0, scl=machine.Pin(7), sda=machine.Pin(6))
devices = i2c.scan()

for device in devices:
    print("Device found at address: {}".format(hex(device)))

SSD1306 Display#

ssd1306 display

Fig. 16 SSD1306 Display#

The display 128x64 pixel monochrome OLED display equipped with an SSD1306 controller is connected using a JST 1.25mm 4-pin connector. The following table provides the pinout details for the display connection.

Table 4 SSD1306 Display Pinout#

Pin

Connection

1

GND

2

VCC

3

SDA

4

SCL

Library Support#

The ssd1306.py library for MicroPython on ESP32 & RP2040 is compatible with the SSD1306 display controller.

Installation

  1. Open Thonny.

  2. Copy the library from ssd1306.py.

  3. Paste the library into a new file in Thonny and save it as ssd1306.py on your device.

Microcontroller Configuration

SoftI2C(scl, sda, *, freq=400000, timeout=50000)

Change the following line depending on your microcontroller:

For ESP32:

>>> i2c = machine.SoftI2C(freq=400000, timeout=50000, sda=machine.Pin(21), scl=machine.Pin(22))

For RP2040:

>>> i2c = machine.SoftI2C(freq=400000, timeout=50000, sda=machine.Pin(4), scl=machine.Pin(5))

Example Code

import machine
from ssd1306 import SSD1306_I2C

I2C_SDA_PIN = 6
I2C_SCL_PIN = 7

i2c = machine.SoftI2C(sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN))

oled = SSD1306_I2C(128, 32, i2c)

oled.fill(1)
oled.show()

oled.fill(0)
oled.show()
oled.text('UNIT', 50, 10)
oled.text('ELECTRONICS', 25, 20)

oled.show()

Replace I2C_SDA_PIN and I2C_SCL_PIN with the appropriate GPIO pins for your setup.

Application Example#

Emotionally – Reacting Face with MicroPython on Pulsar C6#

Bring your board to life with emotions! This project demonstrates how to use the SSD1306 OLED display and MPU6050 IMU sensor with the PULSAR C6 board to create an interactive, emotionally-reacting face.

Project Overview

Emotionally is a cute and expressive project that reacts to how you move it: shake it hard and it gets angry, leave it alone and it gets sleepy. It’s the perfect example of using sensors and displays to give character to embedded systems.

Hardware Components

  • PULSAR C6 development board

  • SSD1306 OLED display (128x64)

  • MPU6050 IMU sensor

  • I2C Qwiic connector

Emotions Logic

  • Happy: Gentle movement

  • Surprised: Moderate shaking

  • Angry: Harsh motion

  • Sleepy: Still (with ZzZ animation)

Software Setup

  1. Flash MicroPython to the Pulsar C6

  2. Upload main.py and mpu6050.py using mpremote or Thonny

  3. Power on the board — the face will appear on the screen

  4. Move the board and watch the expression change in real-time!

This project is ideal for STEM education, IoT toys, wearables, and user-interface experiments.

Emotionally Demo

Fig. 17 Emotionally – Reacting Face Demo#

For complete code, schematics, and detailed instructions, visit the Hackster.io project page.