Complete the code to initialize the I2C bus.
#include <Wire.h> void setup() { Wire.[1](); } void loop() {}
The Wire.begin() function initializes the I2C bus on Arduino.
Complete the code to request 6 bytes from an I2C device with address 0x3C.
Wire.[1](0x3C, 6);
The Wire.requestFrom(address, quantity) function requests bytes from a device on the I2C bus.
Fix the error in the code to write a byte 0x01 to device address 0x50.
Wire.beginTransmission(0x50); Wire.[1](0x01); Wire.endTransmission();
The Wire.write() function sends data bytes to the I2C device.
Fill both blanks to create a dictionary of device addresses and their names.
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);
}Using the loop variable i accesses the corresponding device name and address.
Fill all three blanks to read 4 bytes from device 0x3C and store them in an array.
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(); } }
The device address is 0x3C and we request 4 bytes to read into the array.
