Hi all,
I have 2 Arduinos. 1 is Master and 2 is Slave.
Master Arduino sending first signal and after a delay sends the second signal. But Slave signal only directs the second signal. ( even if I used flush to clear the previous signal ) .
but if I send signal individually it works.
Master -> signal 1 -> Slave = Working
Master-> signal 2 -> Slave = working
Master -> Signal 1 , delay (1000) ,signal 2 -> not working. Can some one help me on this. thanks
Master Code -
#include <SoftwareSerial.h>
SoftwareSerial YRCOM(5, 4);
SoftwareSerial softSerial(9, 8);
void setup()
{
softSerial.begin(9600);
YRCOM.begin(9600);
Serial.begin(9600);
}
void loop()
{
softSerial.print(1245);
softSerial.flush();
delay(1000);
YRCOM.print(1000);
YRCOM.flush();
delay(1000);
}
Slave Code -
#include <SoftwareSerial.h>
SoftwareSerial YRCOM(51, 50);
SoftwareSerial softSerial(11, 10);
char myData[20];
float number;
char myData1[20];
float number1;
int LED = 2;
void setup()
{
YRCOM.begin(9600);
Serial.begin(9600);
}
void loop()
{
if (YRCOM.read())
{
byte m = YRCOM.readBytesUntil('\n', myData1, 20);
myData1[m] = '\0'; //insert null-byte
Serial.println(number1);
number1 = atof(myData1);
Serial.println("YROCM");
Serial.println(number1, 3);
delay(1000);
}
if (softSerial.read())
{
byte m = softSerial.readBytesUntil('\n', myData, 20);
myData[m] = '\0'; //insert null-byte
Serial.println(number); //shows: 251313.212
number = atof(myData);
Serial.println("Serial");
Serial.println(number, 3); //shows: 251313.212 accurately? No! Why not?
delay(1000);
}
}