I connect my NodeMCU to Arduino Uno. The goal is to receive the whole string for example "12", every 1 sec.
This is my code on Arduino Uno side ( the sender)
int mock = 0;
void setup() {
Serial.begin(115200);
s.begin(115200);
}
void loop() {
//Write mock to NodeMCU
s.print((int)mock,DEC);
s.println();
mock++;
delay(1000);
}
On NodeMCU side ( the receiver)
char data; //Initialized variable to store recieved data
String line;
void setup() {
Serial.begin(115200);
s.begin(115200);
while (!Serial) {
;
}
}
void loop() {
if( s.available() >= 2) {
for (int i = 0; i< 2; i++ ) {
data = s.read();
line += data;
}
delay(1000);
}
Serial.print(line);
}
But the result on the serial panel is not what I expected
How can I make it so that I can receive something like
12
(wait one sec)
13
(wait one sec)
....
Node MCU just prints the whole thing, I can't delay it.