Wire.h Library < PROVEN >
void setup() Wire.begin(); Serial.begin(9600); Serial.println("Temperature Monitor");
| Device | Typical Address | |--------|----------------| | OLED Display (SSD1306) | 0x3C | | RTC DS3231 | 0x68 | | Temperature Sensor (BMP280) | 0x76 or 0x77 | | EEPROM (24LC256) | 0x50 | | LCD Backpack (PCF8574) | 0x27 or 0x3F | Advanced Usage: Multiple Bytes // Sending multiple bytes Wire.beginTransmission(0x50); Wire.write(0x00); // Address high byte Wire.write(0x00); // Address low byte Wire.write("Hello"); Wire.endTransmission(); // Reading multiple bytes Wire.requestFrom(0x50, 10); while(Wire.available()) char data = Wire.read(); wire.h library
for(address = 1; address < 127; address++) Wire.beginTransmission(address); error = Wire.endTransmission(); void setup() Wire
if(error == 0) Serial.print("Found device at 0x"); if(address < 16) Serial.print("0"); Serial.println(address, HEX); devices++; void setup() Wire.begin()
void loop() byte error, address; int devices = 0;
#include <Wire.h> void setup() Wire.begin(0x08); // Join bus as slave with address 0x08 Wire.onReceive(receiveEvent); // Register receive handler Wire.onRequest(requestEvent); // Register request handler Serial.begin(9600);
Always add pull-up resistors (2.2kΩ to 10kΩ) on both SDA and SCL lines to 3.3V or 5V. Basic Functions Master Mode (Most Common) #include <Wire.h> void setup() Wire.begin(); // Join I2C bus as master Serial.begin(9600);