Adafruit Data Logger Shield Overloaded?

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
CodenameAter
 
Posts: 23
Joined: Tue Jun 09, 2015 11:20 am

Adafruit Data Logger Shield Overloaded?

Post by CodenameAter »

I am using a Mega2560 with the Adafruit Data Logger Shield with 4 RFID readers (https://wiki.seeedstudio.com/125Khz_RFID_module-UART/). In short, I use the RFID antennas to track the location of my birds on our foraging array and their nests.

Sometimes the Data Logger stops logging data after working for a little while (i.e. the red light stops flashing when the RFID detects a bird and is no longer writing anything to the SD card). If I turn the power off and on it starts working normally. The design works great on the nests, but the birds do not swarm the nests like they do our foraging arrays. I am thinking it might be caused by too many birds present on the arrays but I have not had much success replicating the issue myself so I am not convinced.

I am hoping someone might have an idea of what is causing the issue. Below is an example of the code I use to program the Mega's to track the nests, and below that is the code I use to set up the real-time clock (although I am not sure that is the issue since it's almost a carbon copy of the Adafruit code).

Let me know if you have any ideas or have any questions.

RFID CODE

Code: Select all

#include <EEPROM.h> 
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <RTClib.h>
#include <SoftwareSerial.h>
File dataFile;

int val = 0;
char code[11];
int bytesread = 0;
File myFile;
RTC_DS1307 RTC;
SoftwareSerial XBee(2, 3); 

// VALUES TO CHANGE //////////////////////////////////////////
//////////////////////////////////////////////////////////////

//New Block Marker// - DO NOT TOUCH
char NewD[]="NewDataBlock";           

//Experiment// CHANGE FOR EXPERIMENT
char Avy[]="NESTS"; //ex. NESTS or STINGRAY

//Empty Data Field//
char BkN[]="DARW"; //ex. ="N/A";

//Location IDs// UNIQUE TO ARDUINO
char P0_L[]="Loca_01"; //Location 0 Name
char P1_L[]="Loca_02"; //Location 1 Name (ex. Nest_1)
char P2_L[]="Loca_03"; //Location 2 Name (ex. Nest_2)
char P3_L[]="Loca_04"; //Location 3 Name (ex. Nest_3)

//Location Type// UNIQUE TO ARDUINO
char P0_T[]="N/A"; //Location 0 Type
char P1_T[]="N/A"; //Location 1 Name
char P2_T[]="N/A"; //Location 2 Name
char P3_T[]="N/A"; //Location 3 Name


//////////////////////////////////////////////////////////////
//Time to SD Code/////////////////////////////////////////////
//////////////////////////////////////////////////////////////

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: "
        } else {
        // if the file didn't open, print an error:
        Serial.println("error opening test.txt");
        }
}

//////////////////////////////////////////////////////////////
// Code for intializing the unit & SD card ///////////////////
//////////////////////////////////////////////////////////////

void setup() {
  XBee.begin(9600);
  Serial.begin(9600); // RFID reader works at 9600 BAUD rate
  Serial1.begin(9600);
  Serial2.begin(9600);
  Serial3.begin(9600);
  Wire.begin();
  RTC.begin();
  
 
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(SS, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(10,11,12,13)) { // this will need to be changed to chipselect for non-mega boards
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1) ;
  }
  Serial.println("card initialized.");
  Serial.println("");
  
  // Open up the file we're going to log to!
  dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ; 
  }else {
    
    DateTime now = RTC.now();
    //New Data Block 0 Pin//
    Serial.print("Starting New Data Block: "); 
    Serial.print(Avy);
    Serial.print(" , ");
    Serial.print(BkN);
    Serial.print(" , ");
    Serial.print(P0_L);
    Serial.print(" , ");
    Serial.print(P0_T);
    Serial.print(" , ");
      dataFile.print(Avy);
      dataFile.print("-");
      dataFile.print(NewD);
      dataFile.print(",");
      dataFile.print(BkN);
      dataFile.print(",");
      dataFile.print(P0_L);
      dataFile.print(",");
      dataFile.print(P0_T);
      dataFile.print(",");

     timeToSd();
    //New Data Block 1st Pin//
    Serial.print("Starting New Data Block: "); 
    Serial.print(Avy);
    Serial.print(" , ");
    Serial.print(BkN);
    Serial.print(" , ");
    Serial.print(P1_L);
    Serial.print(" , ");
    Serial.print(P1_T);
    Serial.print(" , ");
      dataFile.print(Avy);
      dataFile.print("-");
      dataFile.print(NewD);
      dataFile.print(",");
      dataFile.print(BkN);
      dataFile.print(",");
      dataFile.print(P1_L);
      dataFile.print(",");
      dataFile.print(P1_T);
      dataFile.print(",");

        timeToSd();
    //New Data Block 2nd Pin//
    Serial.print("Starting New Data Block: "); 
    Serial.print(Avy);
    Serial.print(" , ");
    Serial.print(BkN); 
    Serial.print(" , ");
    Serial.print(P2_L);
    Serial.print(" , ");
    Serial.print(P2_T);
    Serial.print(" , ");
      dataFile.print(Avy);
      dataFile.print("-");
      dataFile.print(NewD);
      dataFile.print(",");
      dataFile.print(BkN);
      dataFile.print(",");
      dataFile.print(P2_L);
      dataFile.print(",");
      dataFile.print(P2_T);
      dataFile.print(",");
      
        timeToSd();
    //New Data Block 3rd Pin//
    Serial.print("Starting New Data Block: "); 
    Serial.print(Avy);
    Serial.print(" , ");
    Serial.print(BkN);
    Serial.print(" , ");
    Serial.print(P3_L);
    Serial.print(" , ");
    Serial.print(P3_T);
    Serial.print(" , ");
      dataFile.print(Avy);
      dataFile.print("-");
      dataFile.print(NewD);
      dataFile.print(",");
      dataFile.print(BkN);
      dataFile.print(",");
      dataFile.print(P3_L);
      dataFile.print(",");
      dataFile.print(P3_T);
      dataFile.print(",");

      timeToSd();
  }
}

//////////////////////////////////////////////////////////////
//Logging the RFID tags///////////////////////////////////////
//////////////////////////////////////////////////////////////
 
void loop() {
  readRfidPort1();
  readRfidPort4();
  readRfidPort3();
  readRfidPort2();
}  


//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

void readRfidPort1() { //1st Pin (RX = pin 0 & TX = pin 1)
  if(Serial.available() > 0) { // if data available from reader
    if((val = Serial.read()) == 2) { // check for header
    bytesread = 0;
    while(bytesread<10) { // read 10 digit code
      if( Serial.available() > 0) {
        val = Serial.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(Avy);
    Serial.print("-");
    Serial.print(code);
    Serial.print(",");
    Serial.print(BkN);
    Serial.print(","); 
    Serial.print(P0_L);
    Serial.print(",");
    Serial.print(P0_T);
    Serial.print(",");  
    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(P0_L);
        dataFile.print(",");
        dataFile.print(P0_T);
        dataFile.print(",");
                    
    timeToSd();
    dataFile.flush();
    digitalWrite(13, LOW); // glow off LED
    }
    bytesread = 0;
    }
  
} 
}
//////////////////////////////////////////////////////////////////////////////////////////////

void readRfidPort4 () { // 2nd Pin (RX = pin 15 & TX = pin 14)
  if(Serial3.available() > 0) { // if data available from reader
    if((val = Serial3.read()) == 2) { // check for header
    bytesread = 0;
    while(bytesread<10) { // read 10 digit code
      if( Serial3.available() > 0) {
        val = Serial3.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(Avy);
    Serial.print("-");
    Serial.print(code);
    Serial.print(",");
    Serial.print(BkN);
    Serial.print(","); 
    Serial.print(P1_L);
    Serial.print(",");
    Serial.print(P1_T);
    Serial.print(",");   
    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(P1_L);
        dataFile.print(",");
        dataFile.print(P1_T);
        dataFile.print(",");
                    
    timeToSd();
    dataFile.flush();
    digitalWrite(13, LOW); // glow off LED
    }
    bytesread = 0;
    }
  
} 
}

//////////////////////////////////////////////////////////////////////////////////////////////

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(Avy);
    Serial.print("-");
    Serial.print(code);
    Serial.print(",");
    Serial.print(BkN);
    Serial.print(","); 
    Serial.print(P2_L);
    Serial.print(",");
    Serial.print(P2_T);
    Serial.print(","); 
    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(",");
          
    timeToSd();
    dataFile.flush();
    digitalWrite(13, LOW); // glow off LED
    }
    bytesread = 0;
    }
  
}
}

////////////////////////////////////////////////////////////////////////////////////////////// 

void readRfidPort2() { // 4th Pin (RX = pin 19 & TX = pin 18)
  if(Serial1.available() > 0) { // if data available from reader
    if((val = Serial1.read()) == 2) { // check for header
    bytesread = 0;
    while(bytesread<10) { // read 10 digit code
      if( Serial1.available() > 0) {
        val = Serial1.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(Avy);
    Serial.print("-");
    Serial.print(code);
    Serial.print(",");
    Serial.print(BkN);
    Serial.print(","); 
    Serial.print(P3_L);
    Serial.print(",");
    Serial.print(P3_T);
    Serial.print(","); 
    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(P3_L);
        dataFile.print(",");
        dataFile.print(P3_T);
        dataFile.print(",");   
   
   timeToSd();
   dataFile.flush();
   digitalWrite(13, LOW); // glow off LED
    }
    bytesread = 0;
    }
  
  }
}


RTC Code

Code: Select all

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
 
#include <Wire.h>
#include "RTClib.h"
 
RTC_DS1307 RTC;
 
void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();
 
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    // uncomment it & upload to set the time, date and start run the RTC!
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
 
}
 
void loop () {
    DateTime now = RTC.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    Serial.print(" since 1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
    
    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now.unixtime() + 7 * 86400L + 30);
    
    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
    
    Serial.println();
    delay(3000);
}

User avatar
CodenameAter
 
Posts: 23
Joined: Tue Jun 09, 2015 11:20 am

Re: Adafruit Data Logger Shield Overloaded?

Post by CodenameAter »

Just to add some more information to this. I thought it might be a memory issue but when I compiled and upload the code to my Mega, the RTC uses about 7% and the actual RFID code uses 23%, which I assume means there is a significant amount of free memory leftover but that could be a bad assumption.

User avatar
CodenameAter
 
Posts: 23
Joined: Tue Jun 09, 2015 11:20 am

Re: Adafruit Data Logger Shield Overloaded?

Post by CodenameAter »

After playing around with it some more, it appears the issue might be the delay(1500) in my code.

Based on some reading, I understand the delay() is just a "busy wait" that monopolizes the processor. I think because the readers were providing too much data and the data logger was not able to keep up, it was probably causing a memory issue crashing the whole thing. I reduced the delay(100) and it appears the data logger can not keep up with my RFID readers.

If anyone is aware of any issues reducing this delay might cause, let me know but based on some very preliminary testing, it appears to have solved the issue.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”