I changed the code, but there is no difference. Here you can see that the delta increases.
Communication through connecting TX/RX directly. The code is at hte bottom of this post.
Counter : 10062 (millis sent from arduino one to arduino 2)
Counter 2: 13787 (millis from arduino 2)
Delta : 3725
Counter : 11071
Counter 2: 14796
Delta : 3725
Counter : 12079
Counter 2: 15806
Delta : 3727
Counter : 13086
Counter 2: 16817
Delta : 3731
Counter : 14094
Counter 2: 17826
Delta : 3732
Counter : 15101
Counter 2: 18836
Delta : 3735
Counter : 16110
Counter 2: 19847
Delta : 3737
Counter : 17118
Counter 2: 20856
Delta : 3738
Counter : 18125
Counter 2: 21866
Delta : 3741
Counter : 19133
Counter 2: 22876
Delta : 3743
Counter : 20142
Counter 2: 23886
Delta : 3744
Counter : 21149
Counter 2: 24896
Delta : 3747
Counter : 22157
Counter 2: 25906
Delta : 3749
Code Arduino one:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
unsigned long counter = 0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
}
mySerial.begin(9600);
Serial.println("Port init ok");
}
void loop()
{
counter = millis();
mySerial.print('<');
mySerial.print(counter); //send counter to the serial port
mySerial.print('>');
Serial.print('<');
Serial.print(counter); // send countr to the serial monitor
Serial.println('>');
delay(1000);
}
Code Arduino two
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
unsigned long counter = 0;
unsigned long counter2 = 0;
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) { }
mySerial.begin(9600);
Serial.println("Port init ok");
}
void loop()
{ // run over and over
recvWithStartEndMarkers();
showNewData();
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (mySerial.available() > 0 && newData == false) {
rc = mySerial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
//Serial.print("This just in ... ");
counter = atoi(receivedChars);
counter2 = millis();
Serial.print("Counter : ");Serial.println(counter);
Serial.print("Counter 2: ");Serial.println(counter2);
Serial.print("Delta : ");Serial.println(counter2 - counter);
Serial.println("");
newData = false;
}
}