You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/micropython/06.communication/i2c/i2c.md
+9-8
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,13 @@
1
1
---
2
-
title: Communication Protocol - I2C
2
+
title: Inter-Integrated Circuit (I2C)
3
3
description: Learn how to use I2C on Micropython
4
4
author: Pedro Sousa Lima
5
5
---
6
6
7
-
#### Introduction
8
7
Inter-Integrated Circuit, or **I2C**, is one of the most widely used serial communication protocols, especially in the Arduino ecosystem. It enables multiple devices to communicate over just two wires, making it both efficient and versatile as you can easily add new modules more easily as the connections all happen across the same bus and standetizes them across manufacturers (and product lines).
9
8
10
9
11
-
####How I2C Works
10
+
## How I2C Works
12
11
I2C communication relies on two wires:
13
12
-**SDA (Serial Data):** Transfers data between devices.
14
13
-**SCL (Serial Clock):** Synchronizes data transmission.
@@ -17,14 +16,15 @@ Each device on an I2C bus has a unique address, allowing the controller to commu
2.**Address-Based Communication:** Each device has a unique address.
24
23
3.**Bidirectional Communication:** Enables data transfer in both directions.
25
24
26
25
27
-
#### Example: Reading Sensor Data Using I2C
26
+
## Example: Reading Sensor Data Using I2C
27
+
28
28
In this example, we will connect an **LIS3DHTR accelerometer** to an Arduino and read its data via I2C.
29
29
30
30
**Circuit Diagram:**
@@ -40,7 +40,7 @@ In this example, we will connect an **LIS3DHTR accelerometer** to an Arduino and
40
40
41
41
3. Copy the following code to your `main.py` file and run it.
42
42
43
-
**Code:**
43
+
**Code Example:**
44
44
```python
45
45
import lis3dh, time, math
46
46
from machine import Pin, I2C
@@ -92,15 +92,16 @@ if imu.device_check():
92
92
```
93
93
94
94
**Expected Output:**
95
-
In the REPL terminal, you will see accelerometer data displayed every second. For example:
95
+
In the REPL terminal, you will see accelerometer data displayed every second.
96
+
96
97

97
98
98
99
```
99
100
x = 0.001 G, y = -0.002 G, z = 1.000 G
100
101
pitch = -0.12, roll = 0.04
101
102
```
102
103
104
+
## Summary
103
105
104
-
#### Summary
105
106
I2C is a highly efficient protocol that enables multiple devices to communicate on just two wires. In this example, we demonstrated how to read data from an I2C-connected sensor, opening the door to integrating even more devices into your Arduino projects.
0 commit comments