You can also make one Arduino act as a slave. This is useful for multi-processor projects. Master Code (Sends a command): #include <Wire.h> void setup() Wire.begin(); Serial.begin(9600);
void loop() Wire.beginTransmission(8); // Slave address 8 Wire.write("Hello Slave!"); Wire.endTransmission(); arduino wire.h library
if(Wire.available() >= 5) Wire.read()) >> 4; float temperature = temp_raw * 0.0625; You can also make one Arduino act as a slave
void loop() // Tell sensor to start measurement Wire.beginTransmission(SENSOR_ADDR); Wire.write(0x12); // Pressure data register (MSB) Wire.endTransmission(false); // Repeated start void setup() Wire.begin()
#include <Wire.h> void receiveEvent(int bytes) while(Wire.available()) char c = Wire.read(); Serial.print(c);
Try the built-in I2C scanner (File → Examples → Wire → Scanner), then hook up a cheap OLED or RTC module. You’ll be amazed at what two wires can do.