Hello!
I'm still learning to cope with Arduino. Now there's a problem with data transmission from one uno to another. While I would like to send data only from MASTERA to slaves, everything's ok, learned and can transfer asmuch as I need. The problems started when I wanted to send data also in opposite direction. I need at the same time mutual communication. This is the link to the simulator - //circuits.io/circuits/4891134-the-unnamed-circuit.
End project is to connect 3 arduino, 1 master bearing the main program and 2 slave, where the two do what master forces, but master also has to recieve data from slave devices.
Master
#include <Wire.h>
int x;
int y;
void setup() {
Wire.begin();
}
void loop() {
x=5;
y=10;
Wire.beginTransmission(1);
Wire.write("Dati");
Wire.write(x);
Wire.write(y);
Wire.endTransmission();
delay(100);
}
slave
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int x;
int y;
void setup() {
lcd.begin(16, 2);
Wire.begin(1);
Wire.onReceive(receiveEvent);
}
void loop() {
x = Wire.read();
y = Wire.read();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(x);
lcd.setCursor(0, 1);
lcd.print(y);
delay(100);
}
void receiveEvent(int howMany) {
while (2 < Wire.available() ) {
char c = Wire.read();
}
}