Hello,
I am trying to send data from a Mega 2560 via an Xbee Shield however, the data is being cut off. The data should look like:
COOP-041917D3522,N/A,Food_3,N/A,5/27/2016,20:41:27,
COOP-041917D3522,N/A,Food_3,N/A,5/27/2016,20:41:38,
COOP-04191795B66,N/A,Food_1,N/A,5/27/2016,20:41:40,
COOP-041917D3522,N/A,Food_3,N/A,5/27/2016,20:41:42,
COOP-04191795B66,N/A,Food_1,N/A,5/27/2016,20:41:43,
COOP-041917D3522,N/A,Food_3,N/A,5/27/2016,20:41:45,
And for the first few hours it does. However, after that the data starts looking like:
COOP-0419179FDEE,N/A,Food_2,N/A,COOP-04191798B11,N/A,Food_2,N/A,COOP-04191798B11,N/A,Food_2,N/A,5/28/2016,5:32:4,
5/28/2016,5:32:9,
5/28/2016,5:32:22,
COOP-04191798B11,N/A,Food_2,N/A,5/28/2016,5:32:43,
I didn't post the entire code below, this is just a sample of one Serial Port:
void readRfidPort3 () { // 3rd Pin (RX = pin 17 & TX = pin 16)
if(Serial2.available() > 0) { // if data available from reader
if((val = Serial2.read()) == 2) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial2.available() > 0) {
val = Serial2.read();
if((val == 2)||(val == 3)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread == 10) { // if 10 digit read is complete
//codeToSd();
//timeToSd();
Serial.print("RFID Aviary-Tag: ");
Serial.print(Avy);
Serial.print("-");
Serial.println(code);
Serial.print("No Data: ");
Serial.println(BkN);
Serial.print("Location & Location Type: ");
Serial.print(P2_L);
Serial.print(" | ");
Serial.println(P2_T);
Serial.print("Writing Time to File: ");
digitalWrite(13, HIGH); //indicate it by glowing LED at pin 13
delay(1500); // delay 1.5 seconds
dataFile.print(Avy);
dataFile.print("-");
dataFile.print(code);
dataFile.print(",");
dataFile.print(BkN);
dataFile.print(",");
dataFile.print(P2_L);
dataFile.print(",");
dataFile.print(P2_T);
dataFile.print(",");
XBee.print(Avy);
XBee.print("-");
XBee.print(code);
XBee.print(",");
XBee.print(BkN);
XBee.print(",");
XBee.print(P2_L);
XBee.print(",");
XBee.print(P2_T);
XBee.print(",");
timeToSd();
dataFile.flush();
digitalWrite(13, LOW); // glow off LED
}
bytesread = 0;
}
}
}
The TimetoSD is pretty straight forward, mostly a copy & paste from the ADAfruit website I believe:
void timeToSd() {
if (dataFile) {
//Serial.begin(57600);
DateTime now = RTC.now();
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print("/");
Serial.print(now.year(), DEC);
Serial.print(" | ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.println(now.second(), DEC);
Serial.println("");
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.day(), DEC);
dataFile.print('/');
dataFile.print(now.year(), DEC);
dataFile.print(',');
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.println(","); //"println" should be at the end, not at the "Time: "
XBee.print(now.month(), DEC);
XBee.print('/');
XBee.print(now.day(), DEC);
XBee.print('/');
XBee.print(now.year(), DEC);
XBee.print(',');
XBee.print(now.hour(), DEC);
XBee.print(':');
XBee.print(now.minute(), DEC);
XBee.print(':');
XBee.print(now.second(), DEC);
XBee.println(",");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
One concern I had is the Xbee shield cannot handle three serial connections, as this is too much data whereas the SD data logger can keep up (I forgot to mention the SD Datalogger works perfectly fine). Anyway, I am looking forward to any suggestions the community may have.
Thank you.