I'm trying to connect 3 Arduinos with this scheme: Arduino1 Master, Arduino2 Slave, Arduino3 Slave. The slave devices need to communicate with each other and I'm trying to programming Arduino2 and transmit bytes to the other slave device Arduino3 and Master Arduino1 at the same time. Is that possible?
Master CODE:
#include <Wire.h>
void setup() {
Wire.begin();
}
void loop() {
Wire.requestFrom(0x04, 2);
while (Wire.available()) {
var1 = Wire.read();
var2 = Wire.read();
}
}
Arduino1 Slave:
#include <Wire.h>
void setup() {
Wire.begin(0x05);
Wire.onReceive(receiveEvent);
}
void loop() {
}
void receiveEvent(int howMany) {
var1 = Wire.read();
Serial.print("VAR1 is : ");
Serial.println(var1);
}
Adrduino2 Slave code:(Where I think I'm wrong)
#include <Wire.h>
int var = 123;
int var2 = 123;
int var3 = 123;
void setup() {
Wire.begin(0x04);
Wire.onRequest(requestEvent);
}
void loop() {
Wire.beginTransmission(0x05);
Wire.write(var);
Wire.endTransmission();
}
void requestEvent() {
Wire.write(var1);
Wire.write(var2);
}
Is this the correct way to make the Arduino2 send to 2 devices?