Library | Wire.h
| 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 |
Over the decades, the Wire.h library became the standard translation layer. It abstracted away the terrifying complexity of Start Conditions, Stop Conditions, ACK (Acknowledge) bits, and NACK (Not Acknowledge) bits. wire.h library
⚠️ - Without them, I2C won't work reliably ⚠️ Maximum bus capacitance - Limits total cable length and number of devices ⚠️ Address conflicts - No two devices on same bus can share the same address ⚠️ Voltage compatibility - Use level shifters when mixing 3.3V and 5V devices | Device | Typical Address | |--------|----------------| |
The Master couldn't just order the Slave to speak. It had to "request" a specific amount of bytes. It was like ordering pizza; you didn't just say "Food." You said, "Give me two slices." It had to "request" a specific amount of bytes
| Function | Description | Example | |----------|-------------|---------| | Wire.begin() | Initialize as master | Wire.begin() | | Wire.begin(address) | Initialize as slave | Wire.begin(0x08) | | Wire.beginTransmission(addr) | Start transmission | Wire.beginTransmission(0x3C) | | Wire.write(data) | Queue data to send | Wire.write(0xFF) | | Wire.endTransmission() | Send queued data | Wire.endTransmission() | | Wire.requestFrom(addr, bytes) | Request data from slave | Wire.requestFrom(0x3C, 6) | | Wire.available() | Check available bytes | if(Wire.available()) | | Wire.read() | Read a byte | byte b = Wire.read() |
void loop() float temp = readTemperature(); Serial.print("Temperature: "); Serial.print(temp); Serial.println("°C"); delay(1000);