I2C (Advanced)

 I2C (Advanced)

Lesson Overview

In previous lessons, you used devices such as OLED displays, LCD screens, and sensors without needing to understand exactly how they communicated with the D1 R32.

For example, you may have used blocks like:

Display Text

or

Read Accelerometer Value

and everything worked automatically.

Behind the scenes, many of those devices were communicating using a protocol called I2C.

The I2C (Advanced) category allows you to work directly with that communication system.

Instead of using device-specific blocks, you can communicate directly with devices connected to the I2C bus.

This gives you more control, more flexibility, and a deeper understanding of how electronic devices communicate.


Introduction

Imagine a classroom where every student is connected to the same intercom system.

The teacher can send a message to a specific student by using that student's number.

Likewise, the student can send information back to the teacher.

I2C works in a similar way.

Several devices can share the same communication lines, and each device has its own address.

The D1 R32 can then communicate with individual devices using those addresses.


What Is I2C?

I2C stands for:

Inter-Integrated Circuit

I2C is a communication system that allows electronic devices to exchange information using only two signal wires.

Those two lines are:

ConnectionPurpose
SDAData line
SCLClock line

Using these two connections, multiple devices can communicate with a microcontroller at the same time.


Why Use I2C?

I2C greatly reduces wiring complexity.

Instead of needing many communication wires, devices can share the same two communication lines.

Examples of common I2C devices include:

  • OLED Displays
  • LCD Displays
  • Accelerometers
  • Temperature Sensors
  • Environmental Sensors
  • Real-Time Clocks
  • EEPROM Memory Modules

Device-Specific Blocks vs Advanced I2C

Students have already encountered I2C without realizing it.

Device-Specific Blocks

Using an OLED display:

Display "Hello"

Using an accelerometer:

Read X Acceleration

The communication details are hidden.


Advanced I2C

Instead of thinking about screens or sensors, students begin thinking about:

Bus

↓

Address

↓

Read

↓

Write

This reveals the communication happening underneath the device-specific blocks.


Understanding the I2C Bus

The communication path looks like this:

D1 R32

↔

SDA + SCL

↔

I2C Bus

↔

Connected Devices

Every connected device shares the same communication lines.

To prevent confusion, each device is assigned a unique address.


I2C Category

[INSERT CATEGORY IMAGE HERE: I2C Advanced Category]

Figure 15.1 – Blocks available in the I2C (Advanced) category.

The category contains six primary blocks:

  1. I2C Setup
  2. Read From Address
  3. Write To Address
  4. Scan I2C Devices
  5. I2C Read
  6. I2C Available

Understanding the I2C Workflow

Rather than memorizing individual blocks, it is easier to think of the complete process.

SETUP

↓

SCAN

↓

IDENTIFY DEVICE

↓

READ OR WRITE

↓

OBSERVE RESULTS

Most Advanced I2C projects follow this exact pattern.


Block 1: I2C Setup

[INSERT BLOCK IMAGE HERE: I2C Setup]

Before devices can communicate, the I2C bus must be configured.

The setup block defines:

  • SDA Pin
  • SCL Pin
  • Communication Frequency

Example:

SCL = 26

SDA = 17

Frequency = 100000


The Two Communication Lines

SDA

Serial Data Line

This line carries information between devices.

Think of SDA as the "conversation line."


SCL

Serial Clock Line

This line keeps communication synchronized.

Think of SCL as the "shared timing signal."


Frequency

Frequency controls how fast communication occurs.

Example:

100000 Hz

This means data can be exchanged 100,000 times per second.


Important Rule

 Setup comes first.

Every other I2C block depends on a configured I2C bus.


Understanding I2C Addresses

Every I2C device has an address.

An address acts like a unique identifier.

Example:

0x27

This tells the D1 R32 which device it wants to communicate with.


Why Do Devices Need Addresses?

Imagine five students sharing the same intercom.

The teacher needs to know who should receive the message.

Likewise:

D1 R32

↓

Address

↓

Specific Device

Without addresses, devices wouldn't know who a message was intended for.


Understanding Hexadecimal Addresses

Many I2C addresses appear in hexadecimal format.

Example:

0x27

The prefix:

0x

means the value is written in hexadecimal.

Students may already recognize hexadecimal values from:

  • Infrared Remote Commands
  • Memory Addresses
  • Electronics Data Sheets

Important Note

Although hexadecimal notation may appear in different categories, the values serve different purposes.

For example:

IR Command → 0x45

is not the same as:

I2C Address → 0x27

Both are hexadecimal values, but they represent different information.


Block 2: Read From Address

[INSERT BLOCK IMAGE HERE: Read From Address]

This block reads information from an I2C device.

Example:

i2c.readfrom(0x27, 1)

What Do the Values Mean?

First Value

0x27

The device address.


Second Value

1

The number of bytes requested.


Conceptual Flow

Device Address

+

Number of Bytes

↓

READ

↓

Data


Understanding readfrom()

The command:

i2c.readfrom(address, bytes)

asks a device for information.

Example:

i2c.readfrom(0x27, 1)

means:

Read 1 byte from the device located at address 0x27.

The second value is not device data.

It tells the device how much information to send back.


Block 3: Write To Address

[INSERT BLOCK IMAGE HERE: Write To Address]

Writing is the opposite of reading.

Instead of receiving information, the D1 R32 sends information.

Example:

i2c.writeto(0x27, 0)

Conceptual Flow

Device Address

+

Value

↓

WRITE

↓

Device


Example Interpretation

Address: 0x27

Value: 0

The D1 R32 sends the value 0 to the device located at address 0x27.


Read vs Write

Understanding the difference between these two operations is essential.


Read

Information comes from the device.

Device

↓

D1 R32

Example:

i2c.readfrom(...)

Write

Information goes to the device.

D1 R32

↓

Device

Example:

i2c.writeto(...)

Memory Tip

 READ = Information comes FROM the device

 WRITE = Information goes TO the device


Block 4: Scan I2C Devices

[INSERT BLOCK IMAGE HERE: Scan I2C Devices]

One of the most useful Advanced I2C tools is the Scan block.

Example:

i2c.scan()

The block searches the I2C bus and reports all detected addresses.


Why Is This Useful?

Students are often unsure what address a connected device is using.

Scanning allows the D1 R32 to discover connected devices automatically.


Conceptual Flow

I2C Bus

↓

Scan

↓

Detected Addresses


Recommended Workflow

Setup Bus

↓

Scan Bus

↓

Find Address

↓

Read or Write

This is often much easier than guessing addresses.


Why Scan Before Communicating?

Imagine trying to call someone without knowing their phone number.

It would be difficult.

I2C communication has the same problem.

Before communicating, you need the correct device address.


Best Practice

SETUP

↓

SCAN

↓

IDENTIFY ADDRESS

↓

COMMUNICATE

This should be the starting point for most Advanced I2C activities.


Block 5: I2C Read

[INSERT BLOCK IMAGE HERE: I2C Read]

This block generates:

i2c.read()

This operation is different from:

i2c.readfrom(...)

Because Clu-Blocks provides this as a separate operation, it should be treated as its own advanced communication tool.

For beginner and intermediate Advanced I2C activities, students will most commonly use:

i2c.readfrom(...)

Block 6: I2C Available

[INSERT BLOCK IMAGE HERE: I2C Available]

This block generates:

i2c.available()

The block checks the availability information provided by the configured I2C object.

Conceptually:

I2C

↓

Available?

↓

Result


Why Is This Useful?

Before reading data, programs often need to know whether information is available.

This block helps answer that question.

For now, students should simply think of it as:

"Can the I2C communication system provide information right now?"


Advanced I2C and Real Devices

Advanced I2C becomes especially useful when working with unfamiliar hardware.

Instead of waiting for a device-specific Clu-Blocks library, students can communicate directly with the device.


Example Process

Connect Sensor

↓

Scan Bus

↓

Find Address

↓

Read Data

↓

Display Results

This workflow is commonly used by engineers and developers when testing new devices.


Advanced I2C and the Serial Monitor

I2C communication is mostly invisible.

Because of this, the Serial Monitor becomes extremely important.


Scanning Example

Scan

↓

Address List

↓

Serial Monitor

Students can immediately see which devices were discovered.


Reading Example

Read Data

↓

Serial Monitor

This allows the returned information to be inspected and understood.


Learning Pattern

Throughout Clu-Blocks we follow the same process:

PERFORM

↓

OBSERVE

↓

INTERPRET

↓

USE

Advanced I2C follows the same model.


Why Is This Category Advanced?

Earlier categories focus on using devices.

Advanced I2C focuses on understanding communication itself.

Students must now think about:

SDA and SCL

 Bus configuration

 Addresses

 Reading

 Writing

 Byte quantities

 Device discovery

 Communication protocols


Device-Specific Thinking

Display Text


Advanced I2C Thinking

Bus

↓

Address

↓

Read Data

↓

Interpret Result

This deeper level of understanding is why the category is considered advanced.


Key Vocabulary

TermDefinition
I2CA communication protocol that uses SDA and SCL lines
SDASerial Data line
SCLSerial Clock line
I2C BusShared communication path between devices
AddressUnique identifier used by an I2C device
ScanDiscover devices connected to the bus
ReadReceive information from a device
WriteSend information to a device
ByteA unit of digital information
HexadecimalBase-16 number system commonly used in electronics

Summary

In this lesson, you learned how Advanced I2C allows direct communication with devices connected to an I2C bus.

You explored how to:

Configure an I2C bus

 Understand SDA and SCL

 Discover connected devices

 Identify device addresses

 Read information

 Write information

 Work with advanced communication blocks

 Use the Serial Monitor to investigate communication

Advanced I2C provides a deeper understanding of how many sensors, displays, and electronic modules communicate with the D1 R32. While device-specific blocks remain the easiest way to use common components, Advanced I2C gives you direct access to the communication system that powers those devices behind the scenes.


Key Takeaway

Advanced I2C allows you to communicate directly with devices by using addresses, reading data, and writing data across an I2C bus.

While device-specific blocks help students use hardware quickly, Advanced I2C reveals what is happening underneath those blocks and provides the tools needed to explore, debug, and communicate with I2C devices at a much deeper level.