Hi all,
I try to develop a project related on Leonardo to Leonardo serial communication with using TX and RX pins. The problem is, code is not robust. So, when you compile the same code some times e' seen(for u transmitted) some times the true sending data(u) seen at the receiving arduino. The codes are following:
For the transmitter arduino;
char u = 'o';
void setup() {
// put your setup code here, to run once:
Serial1.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial1.write(u);
}
For the receiving arduino;
char d;
void setup() {
// put your setup code here, to run once:
Serial1.begin(9600);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial1.available()>0){
d = Serial1.read();}
//d = d - '0';
Serial.println(d);
Serial.flush();
}
(I wrote Serial.flush to preventing java heap error.)
Can you help me? Thank you.
kycn