Bird
0
0
Arduinoprogramming~10 mins

Connecting multiple I2C devices in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the I2C bus.

Arduino
#include <Wire.h>

void setup() {
  Wire.[1]();
}

void loop() {}
Drag options to blanks, or click blank then click option'
Ainit
Bstart
Cbegin
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using Wire.start() instead of Wire.begin()
Forgetting to include the Wire library
2fill in blank
medium

Complete the code to request 6 bytes from an I2C device with address 0x3C.

Arduino
Wire.[1](0x3C, 6);
Drag options to blanks, or click blank then click option'
ArequestFrom
Bsend
Cread
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using Wire.write() to request data
Using Wire.send() which is deprecated
3fill in blank
hard

Fix the error in the code to write a byte 0x01 to device address 0x50.

Arduino
Wire.beginTransmission(0x50);
Wire.[1](0x01);
Wire.endTransmission();
Drag options to blanks, or click blank then click option'
Asend
Bread
CrequestFrom
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using Wire.send() which is deprecated
Using Wire.requestFrom() which is for reading
4fill in blank
hard

Fill both blanks to create a dictionary of device addresses and their names.

Arduino
const char* devices[] = {"Sensor", "Display", "EEPROM"};
int addresses[] = {0x40, 0x3C, 0x50};

for (int i = 0; i < 3; i++) {
  Serial.print(devices[[1]]);
  Serial.print(" at address 0x");
  Serial.println(addresses[[2]], HEX);
}
Drag options to blanks, or click blank then click option'
Ai
B0
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed indices instead of the loop variable
Mixing different indices for devices and addresses
5fill in blank
hard

Fill all three blanks to read 4 bytes from device 0x3C and store them in an array.

Arduino
byte data[4];
Wire.beginTransmission([1]);
Wire.endTransmission();
Wire.requestFrom([2], [3]);
for (int i = 0; i < 4; i++) {
  if (Wire.available()) {
    data[i] = Wire.read();
  }
}
Drag options to blanks, or click blank then click option'
A0x3C
B0x50
C4
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using different addresses for transmission and request
Requesting wrong number of bytes