I2C (Inter-Integrated Circuit)#

Discover the I2C communication protocol and learn how to communicate with I2C devices using the PULSAR H2 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 H2 development board, powered by the ESP32-H2, features advanced I2C communication capabilities with two I2C controllers that support:

  • Standard mode (100 kbit/s) and Fast mode (400 kbit/s)

  • Master and slave modes

  • 7-bit and 10-bit addressing

  • Dual address mode support

  • Programmable digital noise filtering

  • SCL clock stretching in slave mode

Pinout Details#

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

PULSAR H2 Pinout

Fig. 16 PULSAR H2 Pinout#

Table 4 ESP32-H2 I2C Pinout#

Pin

Function

A4 (SDA)/D18

GPIO12 / I2C SDA

A5 (SCL)/D19

GPIO22 / I2C SCL

I2C Features on ESP32-H2#

The ESP32-H2 is designed as an ultra-low-power microcontroller, making it inherently energy-efficient for I2C communication. Key features include:

  • Ultra-low power consumption: The ESP32-H2 is optimized for battery-powered applications

  • Two I2C controllers: Support for multiple I2C buses

  • Flexible GPIO assignment: I2C pins can be assigned to any available GPIO

  • Standard and Fast modes: Support for 100 kbit/s (Standard) and 400 kbit/s (Fast mode)

  • Master and slave modes: Can operate as either I2C master or slave device

Note

Unlike other ESP32 variants, the ESP32-H2 doesn’t have a separate “LP I2C” mode because the entire chip is designed for low power operation.

I2C Connection Example

Fig. 17 I2C Device Connection Example#

Scanning for I2C Devices#

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

import machine

# PULSAR H2 I2C pins: A4 (SDA) = GPIO12, A5 (SCL) = GPIO22
i2c = machine.I2C(0, scl=machine.Pin(22), sda=machine.Pin(12))
devices = i2c.scan()

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

SSD1306 Display#

ssd1306 display

Fig. 18 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 5 SSD1306 Display Pinout#

Pin

Connection

1

GND

2

VCC

3

SDA

4

SCL

Library Support#

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

Installation

  1. Open Thonny.

  2. Navigate to Tools -> Manage Packages.

  3. Search for ocks and click Install.

Alternatively, download the library from ocks.py.

Microcontroller Configuration

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

Change the following line depending on your microcontroller:

For PULSAR H2 (ESP32-H2):

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

Example Code

import machine
from ocks import SSD1306_I2C

# PULSAR H2 I2C pins: A4 (SDA) = GPIO12, A5 (SCL) = GPIO22
i2c = machine.SoftI2C(freq=400000, timeout=50000, sda=machine.Pin(12), scl=machine.Pin(22))

oled = SSD1306_I2C(128, 64, i2c)

# Fill the screen with white and display
oled.fill(1)
oled.show()

# Clear the screen (fill with black)
oled.fill(0)
oled.show()

# Display text
oled.text('UNIT', 50, 10)
oled.text('ELECTRONICS', 25, 20)
oled.show()

Replace sda=machine.Pin(*) and scl=machine.Pin(*) with the appropriate GPIO pins for your setup.