So I want to communicatie between 2 arduinos. So I have connected the 2 arduinos using the gnd, tx and rx using the UNO.
Communication works, if I serial.write something it will get printed into the other arduino. Now I am having alot of difficulty with setting variables.
Senders code
char mystr = "Hello";
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
Serial.println("test");
delay(1000);
}
The sending code sends a char, the receiving code needs to put this into a variable.
Receiving code
void setup() {
Serial.begin(9600);
Serial.println("Is this on?...");
}
void loop() {
if (Serial.available() > 0) {
char var = Serial.read();
// tijd = Serial.parseInt();
String var1(var);
Serial.println(var1);
}
}
Output
Is this on?
t
e
s
t
When it prints it will print 1 letter at a time but I don't want that. It needs to print "test".
How can I do something like that?