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 9 QWIIC-Compatible JST Connector#

Pin

JST Function

Arduino Compatibility

ESP32-S3 GPIO

GPIO Function

1

GND

GND

GND

GND

2

3.3V

3.3V

3.3V

3.3V

3

SDA / MUX IO

A4

GPIO5

RTC_GPIO5, GPIO5, TOUCH5, ADC1_CH4

4

SCL / MUX IO

A5

GPIO6

RTC_GPIO6, GPIO6, TOUCH6, ADC1_CH5

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(6), sda=machine.Pin(5))
devices = i2c.scan()

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

SSD1306 Display#

ssd1306 display

Fig. 15 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 10 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 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 ocks import SSD1306_I2C

i2c = machine.SoftI2C(freq=400000, timeout=50000, sda=machine.Pin(*), scl=machine.Pin(*))

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.