Skip to content

Commit 8688110

Browse files
committed
Update wire.md
1 parent 012be74 commit 8688110

File tree

1 file changed

+49
-5
lines changed
  • content/learn/05.communication/01.wire

1 file changed

+49
-5
lines changed

content/learn/05.communication/01.wire/wire.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@ tags: [I2C, Wire, SDA, SCL]
55
author: 'Nicholas Zambetti, Karl Söderby, Jacob Hylén'
66
difficulty: 'intermediate'
77
---
8+
## Introduction
9+
A good way of adding complexity of features to your projects without adding complexity of wiring, is to make use of the Inter-integrated circuit (I2C) protocol. It allows you to connect several peripheral devices, such as sensors, displays, motor drivers, and so on, with only a few wires. Giving you lots of flexibility and speeding up your prototyping, without an abundancy of wires. Keep reading to learn about how it works, how it is implemented into different standards, as well as how to use the [Wire Library](#wire-library) to build your own I2C devices.
810

11+
## Overview
12+
This section provides an overview of the topics covered in the article.
13+
14+
- [What Is I2C?](#what-is-i2c)
15+
- [Qwiic & STEMMA QT](#qwiic--stemma-qt)
16+
- [Wire Library](#wire-library)
17+
- [Examples](#examples)
18+
19+
## What Is I2C?
920
The I2C protocol involves using two lines to send and receive data: a serial clock pin **(SCL)** that the Arduino Controller board pulses at a regular interval, and a serial data pin **(SDA)** over which data is sent between the two devices.
1021

22+
In I2C, there is one controller device, with one or more peripheral devices connected to the controllers SCL and SDA lines.
23+
1124
As the clock line changes from low to high (known as the rising edge of the clock pulse), a single bit of information is transferred from the board to the I2C device over the SDA line. As the clock line keeps pulsing, more and more bits are sent until a sequence of a 7 or 8 bit address, and a command or data is formed. When this information is sent - bit after bit -, the called upon device executes the request and transmits it's data back - if required - to the board over the same line using the clock signal still generated by the Controller on SCL as timing.
1225

1326
Each device in the I2C bus is functionally independent from the controller, but will respond with information when prompted by the controller.
@@ -30,19 +43,50 @@ But how does the controller and peripherals know where the address, messages, an
3043

3144
However, you are nearly never going to *actually* need to consider any of this, in the Arduino ecosystem we have the [Wire library](https://www.arduino.cc/reference/en/language/functions/communication/wire/) that handles everything for you.
3245

33-
## Hardware & Software Needed
46+
## Qwiic & STEMMA QT
47+
When delving into the market of breakout modules and sensors, you'll find that there are entire ecosystems, where standards are built around the I2C protocol. Examples of such standards are Qwiic, developed by Sparkfun, and STEMMA QT, developed by Adafruit. Both Qwiic and STEMMA QT use a 4-pin JST SH connector for I2C devices, making it easier for third parties to design hardware with vast compatibility. By having a standardized connector, you'll know that if you see the word Qwiic or STEMMA QT in association with an item, that it will work together with an Arduino board with a Qwiic or STEMMA QT connector, such as the UNO R4 WiFi.
48+
49+
Both Qwiic and STEMMA QT bundle together wires for power, ground, as well as the SDA and SCL wires for I2C, making it a complete kit, one cable that bundles everything together.
50+
51+
### What's the difference between the two?
52+
Both Qwiic and STEMMA QT use I2C, and even when inspecting modules using the two standards up close, it may be difficult to tell what makes them unique from each other. But there is a difference! And it has some implications on how and for what you may use them.
53+
54+
Qwiic has level shifting and voltage regulation on the controller (but not on the peripherals). What this means is that Qwiic is 3.3 V logic **only**. This makes it easier to use, as for the end user, there is one less thing that can go wrong when designing and assembling your circuit.
3455

35-
- Arduino IDE ([online](https://create.arduino.cc/) or [offline](https://www.arduino.cc/en/main/software)).
36-
- 2x Arduino Boards
56+
STEMMA QT, on the other hand, doesn't have this. This lets you use both 3.3 V and 5 V logic for modules. This also means that there is one more thing you may need to consider when creating your circuit, but it also grants some more flexibility in power and logic requirements.
57+
58+
The pin order for STEMMA QT is designed to match the pin order for Qwiic, enabling cross-compatibility between the two standards
59+
60+
## Wire Library
61+
The Wire library is what Arduino uses to communicate with I2C devices. It is included in all board packages, so you don't need to install it manually in order to use it.
62+
63+
To see the full API for the Wire library, visit its [documentation page](https://www.arduino.cc/reference/en/language/functions/communication/wire/).
64+
65+
- `begin()` - Initialise the I2C bus
66+
- `end()` - Close the I2C bus
67+
- `requestFrom()`- Request bytes from a peripheral device
68+
- `beginTransmission()` - Begins queueing up a transmission
69+
- `endTransmission()` - Transmit the bytes that have been queued and end the transmission
70+
- `write()` - Writes data from peripheral to controller or vice versa
71+
- `available()` - returns the number of bytes available for retrieval
72+
- `read()` - Reads a byte that was transmitted from a peripheral to a controller.
73+
- `setClock()` - Modify the clock frequency
74+
- `onReceive()` - Register a function to be called when a peripheral receives a transmission
75+
- `onRequest()` - Register a function to be called hwen a controller requests data
76+
- `setWireTimeout()` - Sets the timeout for transmissions in controller mode
77+
- `clearWireTimeoutFlag()` - Clears the timeout flag
78+
- `getWireTimeoutFlag()` - Checks whether a timeout has occured since the last time the flag was cleared.
79+
80+
## Examples
81+
The remainder of this article is a collection of links to tutorials, schematics and code snippets that can get you off the ground with I2C.
3782

3883
***Please note that the I2C bus is attached to different pins depending on the board you are using. For example, the pins used for [MKR WiFi 1010](/hardware/mkr-wifi-1010) are D11, D12, while the pins for [UNO](/hardware/uno-rev3) are D18, D19. See the image below to understand how to locate the correct pins on your board.***
3984

4085
![I2C pins on the UNO.](assets/uno-i2c.png)
4186

4287
![I2C pins on the MKR WiFi 1010](assets/wifi-1010-i2c.png)
4388

44-
## Tutorials
45-
89+
## Tutorials
4690
Check out the following tutorials to get a more detailed step-by-step on how to use I2C on Arduino boards:
4791

4892
- [Connecting Two Nano 33 BLE Boards Through I2C](/tutorials/nano-33-ble/i2c)

0 commit comments

Comments
 (0)