RFID Scanning System breaking after a bit of not scanning tags

I am creating a program that scans for RFID tags, and when it gets one, it reads, stores, and sends the tag over a network. But the issue that keeps occurring, is that after the system has gone a short period of time (I'm not sure exactly how long, but I think its like 5-10 minutes) without scanning tags, it becomes unable to read one. If I set a tag on the scanner and walk away, it'll run indefinitely. The code below is a sample piece I created to attempt to remove non-essential variables to diagnose:

#include <RFIDuino.h>  //include the RFIDuino Library
#define SERIAL_PORT Serial  //Serial port definition most Arduino Boards

RFIDuino* myRFIDuino = new RFIDuino(1.1);  //initialize an RFIDuino object for correct hardware version 1.1

byte* tagData = (byte*)malloc(5 * sizeof(byte));  //Holds the ID numbers from the tag

void setup() {  //Setup Code

  SERIAL_PORT.begin(19200);  //Declare Baud rate for Arduino at 19200
  //SERIAL_PORT.println("\nscan tag");  //Begins text for loop
  beep(1);

}

void beep(int bp) {  //Makes it beep
  int tkn = 0;  //Counting Token
  for (tkn; tkn < bp; tkn++) {
    digitalWrite(myRFIDuino->buzzer, HIGH);
    delay(50);
    digitalWrite(myRFIDuino->buzzer, LOW);
    delay(50);
  }
}

void flash(int fls){  //Makes it Flash
    int tkn = 0;
    for (tkn; tkn < fls; tkn++) {
        digitalWrite(myRFIDuino->led1, HIGH);
        delay(50);
        digitalWrite(myRFIDuino->led1, LOW);
        delay(50);
    }
}

int i = 0;  //Counting variable for counter function

void loop() {  //Main Loop Code
  if (myRFIDuino->scanForTag(tagData) == true) {  //scan for a tag - if a tag is successfully scanned, return a 'true' and proceed
    SERIAL_PORT.print("\nRFID Tag ID:");  //print a header to the Serial port.
    SERIAL_PORT.print("\n[");
    for (int n = 0; n < 5; n++) {  //loop through the byte array
      SERIAL_PORT.print(tagData[n], DEC);  //Print the byte in Decimal format
      if (n < 4) {  //only print the space on the first 4 numbers
        SERIAL_PORT.print(" ");  //Print separating space
      }
    }
    SERIAL_PORT.print("]\n\r");  //return character for next line 
    flash(1);
  }
  else if(i==10000){
    //SERIAL_PORT.print("| No Tag, 10000 ");  //Print that no tag has been found
    flash(1);  //Flash LED once
    i = 0;  //Reset counting variable
    SERIAL_PORT.print("Flashed\n");
  }
  i++;
}

The scripts scans for a tag, if no tag is found, it adds to the counter. Once the counter is at 10000, it flashes a LED, resets the counter, and continues. This leads to a LED flash every ~1 minute. When a tag is found it flashes the LED once as well. Due to the speed of the void() cycles, this results in the LED spazzing out.

Originally, the counter wasn't in the code, but I added it as I thought it may be stuck in a loop of doing nothing. Now, as the counter does it's thing, it flashes the LED continually; but, after it has broken, it continues to flash the LED, for the counter, but becomes unresponsive completely if it is presented a tag to scan. It resumes it's counter LED flashing once removed.

In attempt to maybe correct a memory leak, I allocated memory, and while it kind of seems to work, it still quits recognizing tag scans completely, leading to a frozen counter state.

I have been poking at this for a few weeks now, so any help would be beneficial.

Fair enough. I tried that originally, but it still broke after a bit.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.