Wire Library Arduino May 2026

void sendData() Wire.write(x);

#include <Wire.h> int x = 42; void setup() Wire.begin(0x08); // Join bus as slave at address 0x08 Wire.onRequest(sendData); // Call function when master requests

#include <Wire.h> void setup() Serial.begin(9600); Wire.begin(); wire library arduino

// Request 2 bytes from slave Wire.requestFrom(0x68, 2);

delay(500);

if (Wire.available() >= 2) int msb = Wire.read(); int lsb = Wire.read(); int data = (msb << 8) delay(100);

void loop()

Slave (Arduino #1):