Arduino stops running - gt521f52 fingerprint & mfrc522 on one arduino.

Hi all,

I'm using the gt521f52 fingerprint sensor and mfrc522 rfid reader on an arduino nano for a project I'm working on. The project is effectively adding a lot of new functionality to an old 80s car.

I want to be able to have both RFID and fingerprint usable at anytime.

If I enable them at the same time in code, my arduino won't even make it to the loop and just stops running.

Is there an issue running both of these off one arduino?

If I disable one or the other (eg. use just RFID or just fingerprint) then everything works fine. However if I try to initiate them at the same time, I get the freeze happening after the serial monitor prints "SM2 v1.0 Starting up...".

Here is the code. I couldnt fit the entire thing but this is the majority that matters.

#include <SPI.h>
#include <MFRC522.h>
#include "FPS_GT511C3.h"
#include "SoftwareSerial.h"
#include <SimpleTimer.h>
#include <Wire.h>
FPS_GT511C3 fps(4, 5); // (Arduino SS_RX = pin 4, Arduino SS_TX = pin 5)
// the timer object
SimpleTimer timer;

int speakerOut = 6;

// RFID Reader Items
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

int debug = 0;

const int lock = 2;
const int unlock = 3;
const int doorstatepin = 7;

int doortoggle = 0;
int doorstate;
int fpstouchstate;
int keycardlocked = 0;
int keycardunlocked = 0;
int SM1wake = A0;
const int fpstouch = A1; // 
const int driverdetect = A2;


int SM1awake = 1;
boolean card_present = false;

int warning = 0;
int enroll = 0;
int rfid = 1;
int fingerprint = 1;
int deleteallFPS = 0;
int authorised = 0;

void setup() {
  Serial.begin(9600);   // Initiate a serial communication
  Serial.println("SM2 v1.0 Starting up...");
  //Wire.begin(7); // join i2c bus (address optional for master)
  //Wire.onReceive(receiveEvent); // register event
  //Wire.onRequest(requestEvent); // register event

  //RFID Initialisation
  if (fingerprint == 1) {
    fps.Open();         //send serial command to initialize fps
    //fps.SetLED(true);   //turn on LED so fps can see fingerprint
    Serial.println("Fingerprint OK...");
  }


  if (rfid == 1) {
    SPI.begin();      // Initiate  SPI bus
    mfrc522.PCD_Init();   // Initiate MFRC522
    Serial.println();
    Serial.println("RFID OK...");
    Serial.println();
  }





  timer.setInterval(100, FPSLedBlinkOFF);
  timer.setInterval(4000, FPSLedBlinkON);
  //timer.setInterval(9000, SM1sleep);


  pinMode(speakerOut, OUTPUT);

  // Pinmodes
  pinMode(lock, OUTPUT);
  pinMode(unlock, OUTPUT);
  pinMode(fpstouch, INPUT);
  pinMode(SM1wake, OUTPUT);
  pinMode(doorstatepin, INPUT_PULLUP);

  // Door relay initial states
  digitalWrite(lock, LOW);
  digitalWrite(unlock, LOW);

  // Initial relay states

  //digitalWrite(starterrelay, HIGH);
  //digitalWrite(ignitionrelay, HIGH);




  // Startup tone
  tone(speakerOut, 1400);
  delay(100);
  noTone(speakerOut);
  tone(speakerOut, 800);
  delay(100);
  noTone(speakerOut);
  delay(100);
  tone(speakerOut, 800);
  delay(100);
  noTone(speakerOut);
  delay(200);
 digitalWrite(SM1wake, HIGH);
  delay(10);


  Serial.println("Setup Done.");

}

void loop() {
  /*
     Wire.beginTransmission(8); // transmit to device #8
     Wire.write("A");        // sends five bytes
     Wire.endTransmission();    // stop transmitting
     delay(100);
  */

  if (authorised == 1) {
    while (Wire.available()) { // slave may send less than requested
      char c = Wire.read(); // receive a byte as character

      if (c == 'U') {
        Serial.println("Doors UNLOCKING via SM1 Touchscreen request");
        unlockDoors();
        break;
      }
      if (c == 'L') {
        Serial.println("Doors LOCKING via SM1 Touchscreen request");
        lockDoors();
        break;
      }
      if (c == 'X') {
        Serial.println("Logout request received via touchscreen");
        delay(200);
        SM1sleep();
        authorised = 0;
        break;

      }
    }
  }


  Serial.println("SM2 Running..."); // Tells you that it's still up
  timer.run();

  //Read Pins
  fpstouchstate = digitalRead(fpstouch);

  if (debug == 1) {


    switch (fpstouchstate) {
      case 0:
        Serial.print("FPS Touch State = Not touching");
        Serial.println();
        Serial.println();
        delay(100);
        break;
      case 1:
        Serial.print("FPS Touch State = Touching");
        Serial.println();
        Serial.println();
        delay(100);
        break;
      default:
        // if nothing else matches, do the default
        // default is optional
        break;
    }
  }

  if (deleteallFPS == 1) {
    deletefingerprints();
  }

  if (fpstouchstate == 1 && authorised == 0 && fingerprint == 1) {
    fps.SetLED(true);
  }

  if (fpstouchstate == 0 && authorised == 0 && fingerprint == 1) {
    fps.SetLED(false);
  }

  if (authorised == 1 && fingerprint == 1) {
    fps.SetLED(false);
  }


  if (fingerprint == 1 && doorstate == 1 && fpstouchstate == 1 && authorised == 0) {
    // Identify fingerprint test
    if (fps.IsPressFinger())
    {
      fps.CaptureFinger(false);
      int id = fps.Identify1_N();

      /*Note:  GT-521F52 can hold 3000 fingerprint templates
               GT-521F32 can hold 200 fingerprint templates
                GT-511C3 can hold 200 fingerprint templates.
               GT-511C1R can hold 20 fingerprint templates.
        Make sure to change the id depending on what
        model you are using */
      if (id < 200) //<- change id value depending model you are using
      { //if the fingerprint matches, provide the matching template ID
        Serial.print("Verified ID:");
        Serial.println(id);
        Serial.println("Authorised, connecting circuits...");
        digitalWrite(SM1wake, LOW); // WAKE SM1 with P channel mosfet
        delay(1000);

        // Tell SM1 that the system is now authorised
        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("A");        // sends five bytes. TELL SM1 that authorisation is 1
        Wire.endTransmission();    // stop transmitting
        SM1awake = 1;
        authorised = 1;
      }
      else
      { //if unable to recognize
        Serial.println("Finger not found");
      }
    }
    else
    {
      Serial.println("Please press finger");
    }
    delay(100);
  }

  // Door states. 0 = locked, 1 = unlocked
  doorstate = digitalRead(doorstatepin);
  //Serial.println(doorstate);



  if (enroll == 1 && fingerprint == 1) {
    Enroll();
  }



  if (doortoggle == 0 && doorstate == 1) {

    //Speaker Tone for Unlock
    tone(speakerOut, 900);
    delay(100);
    noTone(speakerOut);
    tone(speakerOut, 1500);
    delay(100);
    noTone(speakerOut);
    tone(speakerOut, 1500);
    delay(100);
    noTone(speakerOut);

    digitalWrite(unlock, HIGH); //on
    delay(100); // pulse delay
    digitalWrite(unlock, LOW); // off after pulse
    doortoggle = 1;
  }

  if (doortoggle == 1 && doorstate == 0) {
    //Speaker Tone for Lock
    tone(speakerOut, 1500);
    delay(100);
    noTone(speakerOut);
    tone(speakerOut, 500);
    delay(100);
    noTone(speakerOut);
    tone(speakerOut, 500);
    delay(100);
    noTone(speakerOut);

    digitalWrite(lock, HIGH); //on
    delay(100); // pulse delay
    digitalWrite(lock, LOW); // off after pulse
    doortoggle = 0;

  }

  if (rfid == 1) {
    // RFID Check
    if ( ! mfrc522.PICC_IsNewCardPresent())
    {
      return;
    }
    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
    {
      return;
    }
    //Show UID on serial monitor
    Serial.print("UID tag :");
    String content = "";
    byte letter;
    for (byte i = 0; i < mfrc522.uid.size; i++)
    {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
      Serial.print(mfrc522.uid.uidByte[i], HEX);
      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
      content.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    Serial.println();
    Serial.print("Message : ");
    content.toUpperCase();
    if (content.substring(1) == "8F 01 E3 29" || content.substring(1) == "8F 01 E3 28" || content.substring(1) == "04 6D 53 0A 6B 5B 80") //change here the UID of the card/cards that you want to give access
    {

      Serial.println("Authorized access");
      Serial.println();


      if (doorstate == 0) {
        unlockDoors();

      }
      else if (doorstate == 1) {
        lockDoors();
        authorised = 0;
      }
    }

    else   {
      Serial.println(" Access denied");
      tone(speakerOut, 500);
      delay(2000);
      noTone(speakerOut);
      delay(3000);
      warning++;

      if (warning >= 3) {
        delay(10000);
      }
    }
  }
}

Anyone?