Bird
0
0
Arduinoprogramming~10 mins

Connecting multiple I2C devices in Arduino - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Connecting multiple I2C devices
Start I2C Bus
Scan for Devices
Identify Device Addresses
Connect Devices with Unique Addresses
Communicate with Each Device
Handle Data Separately
End Communication
This flow shows how the Arduino starts the I2C bus, finds devices, connects to each with unique addresses, and communicates with them one by one.
Execution Sample
Arduino
Wire.begin();
Wire.beginTransmission(0x3C);
Wire.write(0x00);
Wire.endTransmission();
Wire.beginTransmission(0x68);
Wire.write(0x00);
Wire.endTransmission();
This code initializes I2C, then sends data to two devices with addresses 0x3C and 0x68 separately.
Execution Table
StepActionDevice AddressData SentResult
1Initialize I2C bus--Bus ready
2Begin transmission0x3C-Started communication with device 0x3C
3Write data0x3C0x00Data queued for device 0x3C
4End transmission0x3C-Data sent to device 0x3C
5Begin transmission0x68-Started communication with device 0x68
6Write data0x680x00Data queued for device 0x68
7End transmission0x68-Data sent to device 0x68
💡 All devices communicated with separately using their unique addresses.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6After Step 7
currentDevicenone0x3C0x3Cnone0x680x68none
dataBufferemptyempty0x00emptyempty0x00empty
Key Moments - 2 Insights
Why do we need to use different addresses for each I2C device?
Each device on the I2C bus must have a unique address so the Arduino knows which device to talk to, as shown in steps 2 and 5 where different addresses 0x3C and 0x68 are used.
Can we send data to multiple devices at the same time on I2C?
No, the Arduino communicates with one device at a time by starting and ending transmission separately for each device, as seen in steps 2-4 and 5-7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what device address is used at step 5?
A0x3C
B0x68
C0x00
DNo device
💡 Hint
Check the 'Device Address' column at step 5 in the execution_table.
At which step is data actually sent to the device 0x3C?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Look for 'End transmission' action for device 0x3C in the execution_table.
If both devices had the same address, what would happen in the communication?
ABoth devices receive data correctly
BArduino stops communication
COnly one device responds, causing conflicts
DData is sent to a new address automatically
💡 Hint
Recall the key moment about unique addresses and how Arduino communicates with one device at a time.
Concept Snapshot
Connecting multiple I2C devices:
- Each device must have a unique address.
- Use Wire.begin() to start I2C.
- Communicate by beginTransmission(address), write(data), endTransmission().
- Talk to devices one at a time.
- Addresses avoid conflicts on the bus.
Full Transcript
This lesson shows how to connect multiple I2C devices to an Arduino. The Arduino starts the I2C bus with Wire.begin(). It then communicates with each device separately by using the device's unique address. For example, it sends data to device 0x3C first, then to device 0x68. Each communication starts with beginTransmission(address), then data is written, and finally endTransmission() sends the data. Devices must have different addresses so the Arduino knows who to talk to. The execution table shows each step clearly. This method avoids conflicts and ensures each device gets the right data.