0

I've been building an add on to my garage door opener that will allow it to be opened from the outside with a valid RFID token or from inside using push buttons.

This works as expected when first plugged in, but then after a few hours, the RFID component stops responding to swipes. The push buttons continue to allow the door to be opened, closed or halted during an action.

I'm not sure if this is an electrical hardware issue or a code based bug, but any help is appreciated.

Hardware Sketch

#include <AddicoreRFID.h>
#include <SPI.h>

#define  uchar unsigned char
#define uint  unsigned int

uchar fifobytes;
uchar fifoValue;

AddicoreRFID myRFID; // create AddicoreRFID object to control the RFID module

// ------------
// Open / Close Garage Door
// ------------

/*-------------

Every program based on Wiring (programming language used by Arduino, and Particle devices) has two essential parts:
setup - runs once at the beginning of your program
loop - runs continuously over and over

-------------*/


// First, we're going to make some variables.
// This is our "shorthand" that we'll use throughout the program:

int re1 = 8                                                                                                                                                                                                                                                                                                                                 ; // Relay IN1 Blue
int re2 = 7; // Relay IN2 Purple
int re3 = 6; // Relay IN3 Orange
int re4 = 5; // Relay IN4 Yellow
int btn1 = 3;
int btn2 = 4;
int btn3 = 2;

int OpenButtonState = 0;
int CloseButtonState = 0;
int StopButtonState = 0;

int doorstate = 0; // 0 = "Closed", 1 = "Open"

//--Pins for RFID

const int chipSelectPin = 10;
const int NRSTPD = 9;

//Maximum length of the array
#define MAX_LEN 16

//End of RFID Pin Config

void setup() {

  Serial.begin(9600);      // open the serial port at 9600 bps:  
//setup the pins to output voltage
  pinMode(re1, OUTPUT);
  pinMode(re2, OUTPUT);
  pinMode(re3, OUTPUT);
  pinMode(re4, OUTPUT);
  pinMode(btn1, INPUT);
  pinMode(btn2, INPUT);
  pinMode(btn3, INPUT);


   // start the SPI library:
  SPI.begin();

  pinMode(chipSelectPin,OUTPUT);              // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin 
    digitalWrite(chipSelectPin, LOW);         // Activate the RFID reader
  pinMode(NRSTPD,OUTPUT);                     // Set digital pin 9 , Not Reset and Power-down
    digitalWrite(NRSTPD, HIGH);

  myRFID.AddicoreRFID_Init(); 



//setup web call functions 

//Particle.function("netopen", R1ON);
//Particle.function("netclose", R2ON);
//Particle.function("netstop", R3ON);


  digitalWrite(re1, HIGH); //turn off relay
  digitalWrite(re2, HIGH); //turn off relay
  digitalWrite(re3, HIGH); //turn off relay
  digitalWrite(re4, HIGH); //turn off relay


}

// This routine gets repeated over and over, as quickly as possible and as many times as possible, after the setup function is called.
// Note: Code that blocks for too long (like more than 5 seconds), can make weird things happen (like dropping the network connection).  The built-in delay function shown below safely interleaves required background activity, so arbitrarily long delays can safely be done if you need them.

void loop() {

//Loop for RFID ----------------------------------------------------------------------


uchar i, tmp, checksum1;
  uchar status;
        uchar str[MAX_LEN];
        uchar RC_size;
        uchar blockAddr;  //Selection operation block address 0 to 63
        String mynum = "";

        str[1] = 0x4400;
  //Find tags, return tag type
  status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str); 
  if (status == MI_OK)
  {
          Serial.println("RFID tag detected");
                 }


  //Anti-collision, return tag serial number 4 bytes
  status = myRFID.AddicoreRFID_Anticoll(str);
  if (status == MI_OK)
  {
          checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
          Serial.print("The tag's number is:\t");
          Serial.print(str[0]);
            Serial.print(" , ");
          Serial.print(str[1]);
            Serial.print(" , ");
          Serial.print(str[2]);
            Serial.print(" , ");
          Serial.println(str[3]);

//check if valid card combination
            if((str[0] == 333) && (str[1] == 444) && (str[2] == 555) && (str[3] == 666) )                   //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
            {
                Serial.println("\nKey fob identifed - Josh\n");

                if(doorstate == 1) {
                  //door is already open so close
                    // Close Garage Door  
                    R2ON(""); //turn on relay
                    doorstate = 0;
                    Serial.print("Relay 2 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R2OFF(); //turn off relay
                    Serial.print("Relay 2 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                      Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
                    Serial.println("");

                } else {
                  //door is closed so open

                    //Open Garage Door
                    R1ON(""); //turn on relay
                    doorstate = 1;
                    Serial.print("Relay 1 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R1OFF(); //turn off relay
                    Serial.print("Relay 1 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
                    Serial.println(""); 
                }




            } else if((str[0] == 111) && (str[1] == 2222) && (str[2] == 333) && (str[3] == 444) ) {             //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
                Serial.println("\nCar Charge Card Identified - Josh\n");

                if(doorstate == 1) {
                  //door is already open so close
                    // Close Garage Door  
                    R2ON(""); //turn on relay
                    doorstate = 0;
                    Serial.print("Relay 2 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R2OFF(); //turn off relay
                    Serial.print("Relay 2 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                      Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
                    Serial.println("");

                } else {
                  //door is closed so open

                    //Open Garage Door
                    R1ON(""); //turn on relay
                    doorstate = 1;
                    Serial.print("Relay 1 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R1OFF(); //turn off relay
                    Serial.print("Relay 1 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
                    Serial.println(""); 
                }
            } else if((str[0] == 000) && (str[1] == 11) && (str[2] == 22) && (str[3] == 333) ) {             //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
                Serial.println("\nCar Garage Card Identified - Charlotte\n");

                if(doorstate == 1) {
                  //door is already open so close
                    // Close Garage Door  
                    R2ON(""); //turn on relay
                    doorstate = 0;
                    Serial.print("Relay 2 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R2OFF(); //turn off relay
                    Serial.print("Relay 2 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                      Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
                    Serial.println("");

                } else {
                  //door is closed so open

                    //Open Garage Door
                    R1ON(""); //turn on relay
                    doorstate = 1;
                    Serial.print("Relay 1 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R1OFF(); //turn off relay
                    Serial.print("Relay 1 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
                    Serial.println(""); 
                }
            }
            Serial.println();
            delay(1000);
  }

        myRFID.AddicoreRFID_Halt();      //Command tag into hibernation 

   //End Loop For RFID  ----------------------------------------------------------------------



OpenButtonState = digitalRead(btn1);
CloseButtonState = digitalRead(btn2);
StopButtonState = digitalRead(btn3);

if (OpenButtonState == HIGH) {

  Serial.print("Open State Button HIGH - Opening Garage Door")  ;
  Serial.println(""); 
    //Open Garage Door
  R1ON(""); //turn on relay
  doorstate = 1;
  Serial.print("Relay 1 on") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  R1OFF(); //turn off relay
  Serial.print("Relay 1 off") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
  Serial.println(""); 
  } 

if (CloseButtonState == HIGH) {

  Serial.print("Close State Button HIGH - Closing Garage Door") ;
  Serial.println(""); 
    // Close Garage Door  
  R2ON(""); //turn on relay
  doorstate = 0;
  Serial.print("Relay 2 on") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  R2OFF(); //turn off relay
  Serial.print("Relay 2 off") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
    Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
  Serial.println("");

  } 

if (StopButtonState == HIGH) {

 Serial.print("Stop State Button HIGH - Stopping Garage Door")  ;
 Serial.println("");   
 // Stop
  R3ON(""); //turn on relay
  doorstate = 1;
  Serial.print("Relay 3 on") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  R3OFF(); //turn off relay
  Serial.print("Relay 3 off") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
      Serial.print("Stop State Button HIGH - Finished Stopping Garage Door")    ;
  Serial.println("");

  } 


  // And repeat!
}

int R1ON(String command) {

    digitalWrite(re1, LOW); //turn on relay
    //Particle.publish("Relay 1 on - Door Open");
    delay(1000); // wait 1 second
    digitalWrite(re1, HIGH); //turn off relay
    //Particle.publish("Relay 1 off");
}

void R1OFF() {
  digitalWrite(re1, HIGH); //turn off relay
    //delay(1000); // wait 1 second
}

int R2ON(String command) {

    digitalWrite(re2, LOW); //turn on relay
    //Particle.publish("Relay 2 on - Door Closing");
    delay(1000); // wait 1 second
    digitalWrite(re2, HIGH); //turn off relay
    //Particle.publish("Relay 2 off");
}

void R2OFF() {

    digitalWrite(re2, HIGH); //turn on relay
    //delay(1000); // wait 1 second
}

int R3ON(String command) {

    digitalWrite(re3, LOW); //turn on relay
    //Particle.publish("Relay 3 on - Door Stopped");
    delay(1000); // wait 1 second
    digitalWrite(re3, HIGH); //turn off relay
    //Particle.publish("Relay 3 off");
}

void R3OFF() {

    digitalWrite(re3, HIGH); //turn on relay
    //delay(1000); // wait 1 second
}

void R4ON() {

    digitalWrite(re4, LOW); //turn on relay
    //delay(1000); // wait 1 second
}

void R4OFF() {

    digitalWrite(re4, HIGH); //turn on relay
    //delay(1000); // wait 1 second
}

Updated Code 7/7/19 @20:53

#include <AddicoreRFID.h>
#include <SPI.h>

//#define  unsigned char unsigned char
#define uint  unsigned int

unsigned char fifobytes;
unsigned char fifoValue;

AddicoreRFID myRFID; // create AddicoreRFID object to control the RFID module

// ------------
// Open / Close Garage Door
// ------------

/*-------------

Every program based on Wiring (programming language used by Arduino, and Particle devices) has two essential parts:
setup - runs once at the beginning of your program
loop - runs continuously over and over

-------------*/


// First, we're going to make some variables.
// This is our "shorthand" that we'll use throughout the program:

int re1 = 8                                                                                                                                                                                                                                                                                                                                 ; // Relay IN1 Blue
int re2 = 7; // Relay IN2 Purple
int re3 = 6; // Relay IN3 Orange
int re4 = 5; // Relay IN4 Yellow
int btn1 = 3;
int btn2 = 4;
int btn3 = 2;

int OpenButtonState = 0;
int CloseButtonState = 0;
int StopButtonState = 0;

int doorstate = 0; // 0 = "Closed", 1 = "Open"

//--Pins for RFID

const int chipSelectPin = 10;
const int NRSTPD = 9;

//Maximum length of the array
#define MAX_LEN 16

//End of RFID Pin Config

void setup() {

  Serial.begin(9600);      // open the serial port at 9600 bps:  
//setup the pins to output voltage
  pinMode(re1, OUTPUT);
  pinMode(re2, OUTPUT);
  pinMode(re3, OUTPUT);
  pinMode(re4, OUTPUT);
  pinMode(btn1, INPUT);
  pinMode(btn2, INPUT);
  pinMode(btn3, INPUT);


   // start the SPI library:
  SPI.begin();

  pinMode(chipSelectPin,OUTPUT);              // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin 
    digitalWrite(chipSelectPin, LOW);         // Activate the RFID reader
  pinMode(NRSTPD,OUTPUT);                     // Set digital pin 9 , Not Reset and Power-down
    digitalWrite(NRSTPD, HIGH);

  myRFID.AddicoreRFID_Init(); 



//setup web call functions 

//Particle.function("netopen", R1ON);
//Particle.function("netclose", R2ON);
//Particle.function("netstop", R3ON);


  digitalWrite(re1, HIGH); //turn off relay
  digitalWrite(re2, HIGH); //turn off relay
  digitalWrite(re3, HIGH); //turn off relay
  digitalWrite(re4, HIGH); //turn off relay


}

// This routine gets repeated over and over, as quickly as possible and as many times as possible, after the setup function is called.
// Note: Code that blocks for too long (like more than 5 seconds), can make weird things happen (like dropping the network connection).  The built-in delay function shown below safely interleaves required background activity, so arbitrarily long delays can safely be done if you need them.

void loop() {

//Loop for RFID ----------------------------------------------------------------------


//unsigned char checksum1;
  unsigned char status;
        unsigned char str[MAX_LEN];
        //unsigned char RC_size;
        //unsigned char blockAddr;  //Selection operation block address 0 to 63
        //String mynum = "";

        str[1] = 0x4400;
  //Find tags, return tag type
  status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str); 
  if (status == MI_OK)
  {
          Serial.println("RFID tag detected");
                 }


  //Anti-collision, return tag serial number 4 bytes
  status = myRFID.AddicoreRFID_Anticoll(str);
  if (status == MI_OK)
  {
//          checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
          Serial.print("The tag's number is:\t");
          Serial.print(str[0]);
            Serial.print(" , ");
          Serial.print(str[1]);
            Serial.print(" , ");
          Serial.print(str[2]);
            Serial.print(" , ");
          Serial.println(str[3]);

//check if valid card combination
            if((str[0] == 333) && (str[1] == 444) && (str[2] == 555) && (str[3] == 666) )                   //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
            {
                Serial.println("\nKey fob identifed - Josh\n");

                if(doorstate == 1) {
                  //door is already open so close
                    // Close Garage Door  
                    R2ON(); //turn on relay
                    doorstate = 0;
                    Serial.print("Relay 2 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R2OFF(); //turn off relay
                    Serial.print("Relay 2 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                      Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
                    Serial.println("");

                } else {
                  //door is closed so open

                    //Open Garage Door
                    R1ON(); //turn on relay
                    doorstate = 1;
                    Serial.print("Relay 1 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R1OFF(); //turn off relay
                    Serial.print("Relay 1 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
                    Serial.println(""); 
                }




            } else if((str[0] == 222) && (str[1] == 333) && (str[2] == 444) && (str[3] == 555) ) {             //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
                Serial.println("\nCar Charge Card Identided - Josh\n");

                if(doorstate == 1) {
                  //door is already open so close
                    // Close Garage Door  
                    R2ON(); //turn on relay
                    doorstate = 0;
                    Serial.print("Relay 2 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R2OFF(); //turn off relay
                    Serial.print("Relay 2 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                      Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
                    Serial.println("");

                } else {
                  //door is closed so open

                    //Open Garage Door
                    R1ON(); //turn on relay
                    doorstate = 1;
                    Serial.print("Relay 1 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R1OFF(); //turn off relay
                    Serial.print("Relay 1 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
                    Serial.println(""); 
                }
            } else if((str[0] == 111) && (str[1] == 222 && (str[2] == 333) && (str[3] == 444) ) {             //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
                Serial.println("\nCar Garage Card Identided - Charlotte\n");

                if(doorstate == 1) {
                  //door is already open so close
                    // Close Garage Door  
                    R2ON(); //turn on relay
                    doorstate = 0;
                    Serial.print("Relay 2 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R2OFF(); //turn off relay
                    Serial.print("Relay 2 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                      Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
                    Serial.println("");

                } else {
                  //door is closed so open

                    //Open Garage Door
                    R1ON(); //turn on relay
                    doorstate = 1;
                    Serial.print("Relay 1 on") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    R1OFF(); //turn off relay
                    Serial.print("Relay 1 off") ;
                    Serial.println(""); 
                    delay(1000); // wait 1 second
                    Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
                    Serial.println(""); 
                }
            }
            Serial.println();
            delay(1000);
  }

        myRFID.AddicoreRFID_Halt();      //Command tag into hibernation 

   //End Loop For RFID  ----------------------------------------------------------------------



OpenButtonState = digitalRead(btn1);
CloseButtonState = digitalRead(btn2);
StopButtonState = digitalRead(btn3);

if (OpenButtonState == HIGH) {

  Serial.print("Open State Button HIGH - Opening Garage Door")  ;
  Serial.println(""); 
    //Open Garage Door
  R1ON(); //turn on relay
  doorstate = 1;
  Serial.print("Relay 1 on") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  R1OFF(); //turn off relay
  Serial.print("Relay 1 off") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  Serial.print("Open State Button HIGH - Finished Opening Garage Door")    ;
  Serial.println(""); 
  } 

if (CloseButtonState == HIGH) {

  Serial.print("Close State Button HIGH - Closing Garage Door") ;
  Serial.println(""); 
    // Close Garage Door  
  R2ON(); //turn on relay
  doorstate = 0;
  Serial.print("Relay 2 on") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  R2OFF(); //turn off relay
  Serial.print("Relay 2 off") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
    Serial.print("Close State Button HIGH - Finished Closing Garage Door")    ;
  Serial.println("");

  } 

if (StopButtonState == HIGH) {

 Serial.print("Stop State Button HIGH - Stopping Garage Door")  ;
 Serial.println("");   
 // Stop
  R3ON(); //turn on relay
  doorstate = 1;
  Serial.print("Relay 3 on") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
  R3OFF(); //turn off relay
  Serial.print("Relay 3 off") ;
  Serial.println(""); 
  delay(1000); // wait 1 second
      Serial.print("Stop State Button HIGH - Finished Stopping Garage Door")    ;
  Serial.println("");

  } 


  // And repeat!
}

void R1ON() {

    digitalWrite(re1, LOW); //turn on relay
    //Particle.publish("Relay 1 on - Door Open");
    delay(1000); // wait 1 second
    digitalWrite(re1, HIGH); //turn off relay
    //Particle.publish("Relay 1 off");

}

void R1OFF() {
  digitalWrite(re1, HIGH); //turn off relay
    //delay(1000); // wait 1 second


}

void R2ON() {

    digitalWrite(re2, LOW); //turn on relay
    //Particle.publish("Relay 2 on - Door Closing");
    delay(1000); // wait 1 second
    digitalWrite(re2, HIGH); //turn off relay
    //Particle.publish("Relay 2 off");

}

void R2OFF() {

    digitalWrite(re2, HIGH); //turn on relay
    //delay(1000); // wait 1 second

}

void R3ON() {

    digitalWrite(re3, LOW); //turn on relay
    //Particle.publish("Relay 3 on - Door Stopped");
    delay(1000); // wait 1 second
    digitalWrite(re3, HIGH); //turn off relay
    //Particle.publish("Relay 3 off");

}

void R3OFF() {

    digitalWrite(re3, HIGH); //turn on relay
    //delay(1000); // wait 1 second

}

void R4ON() {

    digitalWrite(re4, LOW); //turn on relay
    //delay(1000); // wait 1 second

}

void R4OFF() {

    digitalWrite(re4, HIGH); //turn on relay
    //delay(1000); // wait 1 second

}
5
  • What should the line str[1] = 0x4400; do? It currently just don't make sense
    – chrisl
    Jul 7 '19 at 15:17
  • 1
    Welcome to C++. That out of the way, looks like you wanted to made a call to fuction AddicoreRFID_Request(int,unsigned int). But instead made a call to AddicoreRFID_Request(int,unsigned char). See the difference? The compiler did. This is call Overloaded in C++. Going on, do clean up your code. But my bet is that you have a memory leak.
    – st2000
    Jul 7 '19 at 15:31
  • Re 0x4400 line I'm not entirely sure, it was from the RFID sample code and I think may have something to do with FRAM via the included libraries. But not sure! Jul 7 '19 at 18:05
  • reduce your code to only read the RFID tag and print out that it has been detected .... if that continues to work, then add code to print out data from the card and test again .... keep adding code and testing
    – jsotola
    Jul 7 '19 at 18:57
  • Can you provide a link to the sample code? Writing an int to a char does not make sense, so there is definitely something wrong there. You can try another compatible RFID library. like this one which was linked at the manufacturers site.
    – chrisl
    Jul 8 '19 at 10:28
2

In 50+ years of dealing with hardware/software issues, I've found that the culprit is almost never the hardware. So, your problem is most likely the software.

To start with, there are several major problems with your code:

  1. You are using an unsigned char type to represent integer values > 256; this will not work. When I tried to compile your code, one of the many error messages was "StackOvrFl.ino: 107:8: warning: large integer implicitly truncated to unsigned type [-Woverflow]" on the line 'str[1] = 0x4400;' You need to declare 'str' as 'unsigned int str[MAX_LEN];'.
  2. It's really bad form to use 'nicknames' ('uchar') for types; If someone else needs to maintain or modify your code (or help you with it as in this case), they are going to trip over that and emit 4-letter words in your direction.
  3. Turn on compiler warnings and errors, and don't stop debugging until all such warnings/errors are cleared. The compiler is your friend; let it help you.
  4. If you had turned on compiler warnings/errors, you would have found that the identifier 'MI_OK' was never declared, and so can have ANY VALUE when you check it.

The combination of the integer overflow and undeclared symbol problems will almost undoubtedly cause undefined behavior, but there may be other issues as well. Clean up your code, pay attention to compiler warnings, and then see what happens.

Good luck!

Frank

5
  • Thanks for your response Frank. I took the code used in that section from the manufacturers example, so had trusted that it would be suitable. #2 I've removed the short hand as you suggested. #3 I've set the compiler to show 'more' in the preferences. #4 Again this came from the example, but I tried to declare it and then the compile failed. Is it possible this is declared within the includes? #1 I tried to change to your suggestion and this then threw up: Jul 7 '19 at 14:49
  • no matching function for call to 'AddicoreRFID::AddicoreRFID_Request(int, unsigned int [16])' Jul 7 '19 at 14:50
  • This error says that the call to 'AddicoreRFID_Request(int, unsigned int [16])' in your code has an argument list that isn't EXACTLY the same as the argument list for the definition of that function. Compare them very carefully and you'll find the problem
    – starship15
    Jul 7 '19 at 22:04
  • Presumably because the type has changed from char to int in the calling code but not in the function it calls? I guess that means updating the function and anything it does too. Would it be useful to post the code from the include here too? Jul 8 '19 at 9:17
  • I didn't spend much time looking at the code closely after noting the type definition and undeclared variable issues. I think you need to work your way through the code carefully, fixing ALL the issues before proceeding. You might consider radically simplifying the code to start with, and only adding functionality when what you have works as intended
    – starship15
    Jul 9 '19 at 12:50
1

Consider removing the type String from the code including removing where String is used in passing formal values to some functions. It appears to do nothing. And if the compiler does not optimize it out, could actually be consuming what little RAM the embedded processor contains.

The type String loads in all kinds of help you may or may not need. Generally String is a bad idea for embedded processors because Sting consumes a large amount of resources to support all of String's features. And sometimes those resources are not given back. This is generally referred to as a memory leak. Briefly, this is when the RAM in an embedded processor is considered used by the program, but is not actually being used by the programmer.

7
  • Thanks I've made some combined amendments and have re flashed the code... I'll test in the morning and let you all know if it worked :) Jul 7 '19 at 18:07
  • I'm curious. Does the RFID stop working after a fixed time? Or after a fixed number of garage-door-operations?
    – st2000
    Jul 7 '19 at 18:53
  • I've not been able to identify the exact point at which it stops, but can confirm it has stopped again. I'll paste the revised code below. jotola may be right though that I may need to break it down to work out whats causing the issue. Jul 7 '19 at 19:44
  • I've edited the question to show the revisions thus far. Jul 7 '19 at 19:55
  • You still have some weird stuff going on. You say you copied the code from a working project? But I see stuff like "unsigned char str[MAX_LEN];" followed by "str[1] = 0x4400;". But, normally, an unsigned char is 8 bits large. That's 2^8 or a maximum of 256 or 0x00FF. But 0x4400 is way bigger than that. So that's not going to work.
    – st2000
    Jul 7 '19 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.