NFC-Reader with WiFi-connection and TFT-module - Sketch stops mid-execution

Hi community,

I have posted about this project here before and received some great help. (last post about the topic)
Now I've run into another problem I can't quite get my head around.

I'm running an Arduino Uno R3 together with the CC3000 WiFi-module by adafruit, the PN532 NFC-Reader by Adafruit and the Sainsmart 1.8' TFT module.

With all the libraries my sketch is now at 32.248 Bytes. The free RAM is continually shown as 477, no matter where I call it.

My sketch stops at the initialization of the NFC-module, though, and I really have no answer as to why it does that.

I'll post both the old sketch without the TFT and the new one with the TFT for comparison.
Both sketches consist of four pages.
And so you don't get confused about it: In the old sketch I used LEDs to show the status of the Arduino
and The old sketch contains a lot of debuggind messages which I had to cut because of sketch size.

The old one works fine, but the newer version... :frowning:

Old sketch:

    //WLAN-Libs
    #include <Adafruit_CC3000.h>
    #include <ccspi.h>
    #include <SPI.h>
    #include <string.h>
    #include "utility/debug.h"
    
    //NFC-Libs
    #include <Wire.h>
    #include <Adafruit_NFCShield_I2C.h>
    
    //Motor-Libs
    #include <Servo.h>
    
    #define IRQ   (2)
    #define RESET (4)  // Not connected by default on the NFC Shield
    
    Adafruit_NFCShield_I2C nfc(IRQ, RESET);
    
    //Status-LEDs
    int dev_ready = 6, dev_proc = 8, dev_err = 9;
    
    unsigned long t = millis();
    const unsigned long connectTimeout = 15L * 1000L;
    
  //Motor-settings
    
    const int stepsPerRevolution = 180;  // change this to fit the number of steps per revolution
                                         // for your motor
    int pos = 0;
    
    Servo Motor;  // initialize the stepper library on pins 6 through 9:          
    
  //Wifi-settings
  
    // These are the interrupt and control pins
    #define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
    // These can be any two pins
    #define ADAFRUIT_CC3000_VBAT  5
    #define ADAFRUIT_CC3000_CS    10
    // Use hardware SPI for the remaining pins
    // On an UNO, SCK = 13, MISO = 12, and MOSI = 11
    Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                             SPI_CLOCK_DIV2); // you can change this clock speed
    
    #define WLAN_SSID       "WLAN"           // cannot be longer than 32 characters!
    #define WLAN_PASS       "PASSWORD"
    // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
    #define WLAN_SECURITY   WLAN_SEC_WPA2
    
    Adafruit_CC3000_Client www;  //defines how we will refer to the cc3000 connection object
    
    //Connection details
    #define WEBSITE  "10.2.10.72"  //enter host-IP here
    #define WEBPAGE  "/arduino/sql_entries.php"
    
 //used for storing data for upload
    int tag1_id, user_id;
    //int tag2_id, tag3_id, tag4_id, tag5_id;  //more vars for more devices to log (uncomment if needed)
    
 //tells the sketch whether to poll or not
    int pollCounter = 1;
    boolean pollFlag = false;
    
 //declare a variable to hold a numeric IP address
      uint32_t ip = cc3000.IP2U32(10,2,10,72);
      
    
    
    /**************************************************************************/
    /*!
        @brief  Initialization of the modules (Motor, Wifi, NFC-Reader)
    */
    /**************************************************************************/
    
    
    void setup(void)
    {
      
      Serial.begin(115200);
      
  //Set up LEDs for use
      
      pinMode( dev_ready, OUTPUT);
      pinMode( dev_proc, OUTPUT);
      pinMode( dev_err, OUTPUT);
      
      digitalWrite(dev_ready, HIGH);
      digitalWrite(dev_proc, HIGH);
      digitalWrite(dev_err, HIGH);
      delay(1000);
      digitalWrite(dev_ready, LOW);
      digitalWrite(dev_proc, LOW);
      digitalWrite(dev_err, LOW);
      delay(1000);
      
  //Set up the Motor for the lock
    
      Motor.attach(7);
      Motor.write(100);
      delay(500);
      Motor.write(55);
      delay(500);
      
  //Set up the Wifi module
      
      Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC);
      
      // Initialise the Wifi module 
      Serial.println(F("\nInitializing..."));
      if (!cc3000.begin())
        {
          Serial.println(F("Couldn't begin()! Check your wiring?"));
          digitalWrite(dev_err, HIGH);
          while(1);
        }
      
      cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
       
      Serial.println(F("Connected!"));
    
      // Wait for DHCP to complete
      Serial.println(F("Request DHCP"));
      do {
          digitalWrite(dev_proc, HIGH);
          delay(100);
          digitalWrite(dev_proc, LOW);
      } while((!cc3000.checkDHCP()) && ((millis() - t) < connectTimeout));
    
      // Display the IP address DNS, Gateway, etc.   
      while (! displayConnectionDetails()) {
          digitalWrite(dev_proc, HIGH);
          delay(100);
          digitalWrite(dev_proc, LOW);
      }
            
      //Set up the NFC module
      Serial.println(F("\nStarting NF-Reader..."));
  
      nfc.begin();
          
      uint32_t versiondata = nfc.getFirmwareVersion();
      if (! versiondata) {
        Serial.print(F("Didn't find PN53x board"));
        digitalWrite(dev_err, HIGH);
        while (1); // halt
      }
      // Got ok data, print it out!
      Serial.print(F("Found chip PN5")); Serial.println((versiondata>>24) & 0xFF, HEX); 
      Serial.print(F("Firmware ver. ")); Serial.print((versiondata>>16) & 0xFF, DEC); 
      Serial.println('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
            
      // configure board to read RFID tags
      nfc.SAMConfig();
    }
      
    
    /**************************************************************************/
    /*!
        @brief  If a TAG is read, the values are translated into an int ID
                that is then passed on to be send to the server. Differentiation
                between the User-TAG and the Device-TAG is being made.
    */
    /**************************************************************************/
    
    
    void loop(void)
    {
       //Text and LED for User to see system is ready
       digitalWrite(dev_ready, LOW);
       digitalWrite(dev_proc, LOW);
       digitalWrite(dev_err, LOW);
      
       digitalWrite(dev_ready, HIGH);
       Serial.println(F("Waiting for an ISO14443A Card ..."));
       
       NFC_ID_handler();
       
       if ( pollCounter > 1) {
          data_sender();
          pollCounter = 1;
       }
       else {
         pollCounter++;
       }
       
       delay(2000);
    }  //end of the loop
    
    
    /**************************************************************************/
    /*!
        @brief  Tries to read the IP address and other connection details
    */
    /**************************************************************************/
    bool displayConnectionDetails(void)
    {
      uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
      
      if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
      {
        Serial.println(F("Unable to retrieve the IP Address!\r\n"));
        digitalWrite(dev_err, HIGH);
        return false;
      }
      else
      {
        Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
        Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
        Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
        Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
        Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
        Serial.println();
      }
    }
  /**************************************************************************/
    /*!
        @brief  command is send here, to open/close the lock
    */
    /**************************************************************************/
    
  void command_open_handler(void)
  {
    if (pos == 100)
    {
      //Motor opens lock...
      Serial.println(F("open"));
      Motor.write(55);
    } else {
      Motor.write(100);
    }
    
  }
  
  void command_close_handler(void)
  {
    if (pos == 55)
    {
      //Motor closes lock...
      Serial.println(F("close"));
      Motor.write(100);
    } else {
      Motor.write(55);
    }
  }
  /**************************************************************************/
  /*
      @brief  NFC-Reader is reading TAGs here
  */
  /**************************************************************************/
  
  void NFC_ID_handler(void)
  {
     uint8_t success;
     uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
     uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
          
     // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
     // 'uid' will be populated with the UID, and uidLength will indicate
     // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
     
     success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
     Serial.print(F("Success: ")); Serial.println(success);
     
     tag1_id = 0;
     
     for (int i = 0; i < 4; i++) {          //iterate over array, take value and write to UID_final as an integer
       tag1_id = tag1_id + uid[i];
     }
           
     if(pollCounter == 1) {
           user_id = tag1_id; 
     }
     else if (pollCounter > 1 && tag1_id == user_id) {
           transactionFinished();
     }
     
     // Display some basic information about the card
     Serial.println(F("Found an ISO14443A card"));
     Serial.print(F("UID Length: "));Serial.print(uidLength, DEC);Serial.println(F(" bytes"));
     Serial.print(F("UID Value: "));
     nfc.PrintHex(uid, uidLength);
     Serial.println();
      
     for (int i = 0; i < 8; i++) {          //iterate over array, take value and Print it out
        Serial.print(F("UID Feld ")); Serial.print(i); Serial.print(F(" hat Wert: ")); Serial.println(uid[i]);
     }
      
     if (uidLength == 4)
     {
       // We probably have a Mifare Classic card ... 
       Serial.println(F("Seems to be a Mifare Classic card (4 byte UID)"));
   
       // Now we need to try to authenticate it for read/write access
       // Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
       Serial.println(F("Trying to authenticate block 4 with default KeyA value"));
       uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
   
   // Start with block 4 (the first block of sector 1) since sector 0
   // contains the manufacturer data and it's probably better just
   // to leave it alone unless you know what you're doing
       success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
   
       if (success)
       {
          Serial.println(F("Sector 1 (Blocks 4..7) has been authenticated"));
          uint8_t data[16];
   
          // If you want to write something to block 4 to test with, uncomment
      // the following line and this text should be read back in a minute
          // data = { 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0};
          // success = nfc.mifareclassic_WriteDataBlock (4, data);
  
          // Try to read the contents of block 4
          success = nfc.mifareclassic_ReadDataBlock(4, data);
   
          if (success)
          {
            // Data seems to have been read ... spit it out
            Serial.println(F("Reading Block 4:"));
            nfc.PrintHexChar(data, 16);
            Serial.println("");
    
            // Wait a bit before reading the card again
            delay(1000);
            pollFlag = true;
          }
          else
          {
            Serial.println(F("Ooops ... unable to read the requested block.  Try another key?"));
            digitalWrite(dev_err, HIGH);
            //UID_final = 0;
          }
       }
       else
       {
          Serial.println(F("Ooops ... authentication failed: Try another key?"));
          digitalWrite(dev_err, HIGH);
       }
     }
      
     if (uidLength == 7)
     {
        // We probably have a Mifare Ultralight card ...
        Serial.println(F("Seems to be a Mifare Ultralight tag (7 byte UID)"));
    
        // Try to read the first general-purpose user page (#4)
        Serial.println(F("Reading page 4"));
        uint8_t data[32];
        success = nfc.mifareultralight_ReadPage (4, data);
        if (success)
        {
          // Data seems to have been read ... spit it out
          nfc.PrintHexChar(data, 4);
          Serial.println("");
   
          // Wait a bit before reading the card again
          delay(1000);
       }
       else
       {
          Serial.println(F("Ooops ... unable to read the requested page!?"));
          digitalWrite(dev_err, HIGH);
       }
     }   
   }
    
    
    void transactionFinished (void)
    {
        data_sender();
        pollCounter = 1;
        user_id = 0;
    }
  /**************************************************************************/
  /*!
      @brief  The scanned IDs of the NFC-TAGs are send to the server as a json
              and the command that is answered (e.g. open/close) is being caught
  */
  /**************************************************************************/
  
    void data_sender(void) 
    {
      //build the URI and GET args
      String targetURI;
      
      targetURI = WEBPAGE;
      targetURI = targetURI + "?user=" + user_id;
      targetURI = targetURI + "&device=" + tag1_id; //more vars for more devices to log (uncomment if needed)
      //targetURI = targetURI + "&tag=" + tag2_id;
      //targetURI = targetURI + "&tag=" + tag3_id;
      //targetURI = targetURI + "&tag=" + tag4_id;
      //targetURI = targetURI + "&tag=" + tag5_id;
      
      /* Try connecting to the website */
      Serial.print(F("\r\nAttempting connection with data "));
      Serial.println(targetURI);
              
      do {
          www = cc3000.connectTCP( ip, 8888);
      } 
      while((!www.connected()) && ((millis() - t) < connectTimeout));
      
      if (www.connected()) {
          Serial.println(F("Connected; requesting commands"));
          www.fastrprint(F("GET "));
          //www.fastrprint(WEBPAGE);
          www.print(targetURI);  //can't use fastrprint because it won't accept a variable
          www.fastrprint(F(" HTTP/1.0\r\n"));
          www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\n"));
          www.fastrprint(F("Connection: close\n"));
          www.fastrprint(F("\n"));
          www.println();
      } 
      else {
          Serial.println(F("Connection failed"));
          digitalWrite(dev_err, HIGH);
          return;
      }
    
                                                                                                                                                                                                                                                                                                                                                                                                                                                       
      //define a String to hold our json object
      char command = '0';
      //set a flag for when to start adding to String
      boolean readflag = false;
      
      //read in data one character at a time while connected    
      while (www.connected()) {
          while (www.available()) {
              char c = www.read();
         
             //start storing at the [ marker
             if (c=='[') {readflag = true;}
              if (c==']') {readflag = false;}
             //build data read from www into a String
             if ((readflag == true) && (c != '['))  {
                 command = c;
             }
          }
      }
      www.close();
      Serial.print(F("command: "));
      Serial.println(command);
      
      //Open doorlock if authentication succeeded
      if (command = '1') {
        command_open_handler();
      } 
      else if (command = '0') {
        command_close_handler();
      }
      else if (command = '2') {
        Serial.println(F("Error reading DB!! Corrupt entries?"));
      }
    }

New sketch:

   //WLAN-Libs
   #include <Adafruit_CC3000.h>
   #include <ccspi.h>
   #include <SPI.h>
   #include <string.h>
   #include "utility/debug.h"
   
   //TFT-Libs
   #include <Adafruit_GFX.h>
   #include <Adafruit_ST7735.h>
    
   //NFC-Libs
   #include <Wire.h>
   #include <Adafruit_NFCShield_I2C.h>
   
   //Motor-Libs
   #include <Servo.h>
   
   //TFT-Setup
   #define sclk SCL
   #define mosi SDA
   #define cs   9
   #define dc   8
   #define rst  7
   
   Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
   
   unsigned long t = millis();
   const unsigned long connectTimeout = 15L * 1000L;
   
 //Motor-settings
   
   const int stepsPerRevolution = 1;  // change this to fit the number of steps per revolution
                                        // for your motor
   int pos = 0;
   
   Servo Motor;  // initialize the stepper library on pins 6 through 9:          
   
 //Wifi-settings
 
   // These are the interrupt and control pins
   #define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
   // These can be any two pins
   #define ADAFRUIT_CC3000_VBAT  5
   #define ADAFRUIT_CC3000_CS    10
   // Use hardware SPI for the remaining pins
   // On an UNO, SCK = 13, MISO = 12, and MOSI = 11
   Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                            SPI_CLOCK_DIV2); // you can change this clock speed
   
   #define WLAN_SSID       "WLAN"           // cannot be longer than 32 characters!
   #define WLAN_PASS       "PASSWORD"
   // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
   #define WLAN_SECURITY   WLAN_SEC_WPA2
   
   Adafruit_CC3000_Client www;  //defines how we will refer to the cc3000 connection object
   
   //Connection details
   #define WEBPAGE  "/arduino/sql_entries.php"
   
//used for storing data for upload
   int tag1_id, user_id;
   //int tag2_id, tag3_id, tag4_id, tag5_id;  //more vars for more devices to log (uncomment if needed)
   
//tells the sketch whether to poll or not
   int pollCounter = 1;
   boolean pollFlag = false;
   
//declare a variable to hold a numeric IP address
   uint32_t ip = cc3000.IP2U32(10,2,10,72);
     
//NFC-Settings
   #define IRQ   (2)
   #define RESET (4)  // Not connected by default on the NFC Shield
   
   Adafruit_NFCShield_I2C nfc(IRQ, RESET);
     
   
   
   /**************************************************************************/
   /*!
       @brief  Initialization of the modules (Motor, Wifi, NFC-Reader)
   */
   /**************************************************************************/
   
   
   void setup()
   {
     tft.initR(INITR_BLACKTAB);
     tft.fillScreen(ST7735_BLACK);
     
     testdrawtext("Mornin'", ST7735_WHITE);
     delay(500);
     
     Serial.begin(115200);
     
 //Set up the Motor for the lock
   
     Motor.attach(6);
     /*Motor.write(100);
     delay(500);
     Motor.write(55);
     delay(500);*/
     
 //Set up the Wifi module
     
     //Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC);
     
     // Initialise the Wifi module 
     testdrawtext("Initializing...", ST7735_WHITE);
     if (!cc3000.begin())
       {
         testdrawtext("Can't initialize...", ST7735_WHITE);
         while(1); //halt
       }
     
     cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
      
     testdrawtext("Connected", ST7735_WHITE);
   
     // Wait for DHCP to complete
     //Serial.println(F("Request DHCP"));
     do {
         testdrawtext("Requesting DHCP...", ST7735_WHITE);
         delay(1000);
     } while((!cc3000.checkDHCP()) && ((millis() - t) < connectTimeout));
   
     // Display the IP address DNS, Gateway, etc.   
     while (! displayConnectionDetails()) {
         testdrawtext("loading...", ST7735_WHITE);
         delay(500);
     }
           
     //Set up the NFC module
     testdrawtext("Starting Reader", ST7735_WHITE);
     Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC);
 
     nfc.begin();
         
     uint32_t versiondata = nfc.getFirmwareVersion();
     do {
         testdrawtext("Finding Reader...", ST7735_WHITE);
         delay(500);
         tft.fillScreen(ST7735_BLACK);
         delay(500);
     } while (!nfc.getFirmwareVersion());
     // Got ok data, print it out!
     //Serial.print(F("Found chip PN5")); Serial.println((versiondata>>24) & 0xFF, HEX); 
     //Serial.print(F("Firmware ver. ")); Serial.print((versiondata>>16) & 0xFF, DEC); 
     //Serial.println((versiondata>>8) & 0xFF, DEC);
           
     // configure board to read RFID tags
     nfc.SAMConfig();
   }
     
   
   /**************************************************************************/
   /*!
       @brief  If a TAG is read, the values are translated into an int ID
               that is then passed on to be send to the server. Differentiation
               between the User-TAG and the Device-TAG is being made.
   */
   /**************************************************************************/
   
   
   void loop(void)
   {
      //Text and LED for User to see system is ready
      
      testdrawtext("Please scan TAG", ST7735_WHITE);
      
      NFC_ID_handler();
      
      if ( pollCounter > 1) {
         data_sender();
         pollCounter = 1;
      }
      else {
        pollCounter++;
      }
      
      delay(2000);
   }  //end of the loop
   
   
   /**************************************************************************/
   /*!
       @brief  Tries to read the IP address and other connection details
   */
   /**************************************************************************/
   bool displayConnectionDetails(void)
   {
     uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
     
     if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
     {
       testdrawtext("Sorry, can't recieve IP-address", ST7735_WHITE);
       delay(500);
       return false;
     }
     else
     {
       testdrawtext("Everything worked out fine!", ST7735_WHITE);
       //testdrawtext("IP Addr: ", ST7735_WHITE); cc3000.printIPdotsRev(ipAddress);
       //testdrawtext("\nNetmask: ", ST7735_WHITE); cc3000.printIPdotsRev(netmask);
       //testdrawtext("\nGateway: ", ST7735_WHITE); cc3000.printIPdotsRev(gateway);
       //testdrawtext("DHCPsrv: ", ST7735_WHITE); cc3000.printIPdotsRev(dhcpserv);
       //testdrawtext("\nDNSserv: ", ST7735_WHITE); cc3000.printIPdotsRev(dnsserv);
       //Serial.println();
     }
   }
   
   void testdrawtext(char *text, uint16_t color) {
   tft.fillScreen(ST7735_BLACK);
   tft.setCursor(0, 0);
   tft.setTextColor(color);
   tft.setTextWrap(true);
   tft.print(text);
   }
   /**************************************************************************/
   /*!
       @brief  command is send here, to open/close the lock
   */
   /**************************************************************************/
   
 void command_open_handler(void)
 {
   if (pos == 100)
   {
     //Motor opens lock...
     //Serial.println(F("open"));
     Motor.write(55);
   } else {
     Motor.write(100);
   }
   
 }
 
 void command_close_handler(void)
 {
   if (pos == 55)
   {
     //Motor closes lock...
     //Serial.println(F("close"));
     Motor.write(100);
   } else {
     Motor.write(55);
   }
 }
   /**************************************************************************/
   /*
       @brief  NFC-Reader is reading TAGs here
   */
   /**************************************************************************/
   
   void NFC_ID_handler(void)
   {
      uint8_t success;
      uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
      uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
           
      // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
      // 'uid' will be populated with the UID, and uidLength will indicate
      // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
      
      success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
      //testdrawtext("Success: ", ST7735_WHITE); tft.print(success, ST7735_WHITE);
      
      tag1_id = 0;
      
      for (int i = 0; i < 4; i++) {          //iterate over array, take value and write to UID_final as an integer
        tag1_id = tag1_id + uid[i];
      }
            
      if(pollCounter == 1) {
            user_id = tag1_id; 
      }
      else if (pollCounter > 1 && tag1_id == user_id) {
            transactionFinished();
      }
      
      // Display some basic information about the card
      //testdrawtext("Found an ISO14443A card", ST7735_WHITE);
      //Serial.print(F("UID Length: "));Serial.print(uidLength, DEC);Serial.println(F(" bytes"));
      //Serial.print(F("UID Value: "));
      //nfc.PrintHex(uid, uidLength);
      testdrawtext("TAG-ID is " , ST7735_WHITE);
      tft.print(tag1_id , ST7735_WHITE);
      //Serial.println();
       
      for (int i = 0; i < 8; i++) {          //iterate over array, take value and Print it out
         //Serial.print(F("UID Feld ")); Serial.print(i); Serial.print(F(" hat Wert: ")); Serial.println(uid[i]);
      }
       
      if (uidLength == 4)
      {
        // We probably have a Mifare Classic card ... 
        //Serial.println(F("Seems to be a Mifare Classic card (4 byte UID)"));
    
        // Now we need to try to authenticate it for read/write access
        // Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
        //Serial.println(F("Trying to authenticate block 4 with default KeyA value"));
        uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
    
    // Start with block 4 (the first block of sector 1) since sector 0
    // contains the manufacturer data and it's probably better just
    // to leave it alone unless you know what you're doing
        success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
    
        if (success)
        {
           //Serial.println(F("Sector 1 (Blocks 4..7) has been authenticated"));
           uint8_t data[16];
    
           // If you want to write something to block 4 to test with, uncomment
       // the following line and this text should be read back in a minute
           // data = { 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0};
           // success = nfc.mifareclassic_WriteDataBlock (4, data);
   
           // Try to read the contents of block 4
           success = nfc.mifareclassic_ReadDataBlock(4, data);
    
           if (success)
           {
             // Data seems to have been read ... spit it out
             //Serial.println(F("Reading Block 4:"));
             //nfc.PrintHexChar(data, 16);
             //Serial.println("");
     
             // Wait a bit before reading the card again
             delay(1000);
             pollFlag = true;
           }
           else
           {
             //Serial.println(F("Ooops ... unable to read the requested block.  Try another key?"));
             testdrawtext("Couldn't read the TAG" , ST7735_WHITE);
             //UID_final = 0;
           }
        }
        else
        {
           //Serial.println(F("Ooops ... authentication failed: Try another key?"));
           testdrawtext("Couldn't read the TAG" , ST7735_WHITE);
        }
      }
       
      /*if (uidLength == 7)
      {
         // We probably have a Mifare Ultralight card ...
         //Serial.println(F("Seems to be a Mifare Ultralight tag (7 byte UID)"));
     
         // Try to read the first general-purpose user page (#4)
         //Serial.println(F("Reading page 4"));
         uint8_t data[32];
         success = nfc.mifareultralight_ReadPage (4, data);
         if (success)
         {
           // Data seems to have been read ... spit it out
           nfc.PrintHexChar(data, 4);
           //Serial.println("");
    
           // Wait a bit before reading the card again
           delay(1000);
          }
        else
        {
           //Serial.println(F("Ooops ... unable to read the requested page!?"));
           testdrawtext("Couldn't read the TAG. Try again?" , ST7735_WHITE);
        }
      }*/
    }
     
     
     void transactionFinished (void)
     {
         data_sender();
         pollCounter = 1;
         user_id = 0;
     }
   /**************************************************************************/
   /*!
       @brief  The scanned IDs of the NFC-TAGs are send to the server as a json
               and the command that is answered (e.g. open/close) is being caught
   */
   /**************************************************************************/
   
     void data_sender(void) 
     {
       //build the URI and GET args
       String targetURI;
       
       targetURI = WEBPAGE;
       targetURI = targetURI + "?user=" + user_id;
       targetURI = targetURI + "&device=" + tag1_id; //more vars for more devices to log (uncomment if needed)
       //targetURI = targetURI + "&tag=" + tag2_id;
       //targetURI = targetURI + "&tag=" + tag3_id;
       //targetURI = targetURI + "&tag=" + tag4_id;
       //targetURI = targetURI + "&tag=" + tag5_id;
       
       /* Try connecting to the website */
       //Serial.print(F("\r\nAttempting connection with data "));
       //Serial.println(targetURI);
               
       do {
           www = cc3000.connectTCP( ip, 8888);
       } while((!www.connected()) && ((millis() - t) < connectTimeout));
       
       if (www.connected()) {
           //Serial.println(F("Connected; requesting commands"));
           //www.fastrprint(F("GET "));
           //www.fastrprint(WEBPAGE);
           www.print(targetURI);  //can't use fastrprint because it won't accept a variable
           //www.fastrprint(F(" HTTP/1.0\r\n"));
           //www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\n"));
           //www.fastrprint(F("Connection: close\n"));
           //www.fastrprint(F("\n"));
           //www.println();
       } 
       else {
           //Serial.println(F("Connection failed"));
           return;
       }
     
                                                                                                                                                                                                                                                                                                                                                                                                                                                        
       //define a String to hold our json object
       char command = '0';
       //set a flag for when to start adding to String
       boolean readflag = false;
       
       //read in data one character at a time while connected    
       while (www.connected()) {
           while (www.available()) {
               char c = www.read();
          
              //start storing at the [ marker
              if (c=='[') {readflag = true;}
              if (c==']') {readflag = false;}
              //build data read from www into a String
              if ((readflag == true) && (c != '['))  {
                  command = c;
              }
           }
       }
       www.close();
       //Serial.print(F("command: "));
       //Serial.println(command);
       
       //Open doorlock if authentication succeeded
       if (command = '1') {
         command_open_handler();
       } 
       else if (command = '0') {
         command_close_handler();
       }
       else if (command = '2') {
         //Serial.println(F("Error reading DB!! Corrupt entries?"));
         return;
       }
     }

I've also made some photos of the project as it is wired right now with the TFT-module:


I hope you can see the wiring clearly. If you need more details,
I'll be happy to put up a Fritzing-layout or what else you might require :slight_smile:

And If you've got any other questions feel free to ask as well!

Regards,

Patrick

Oh, and sorry about all the posts... The forum kept bugging me about the postsize :-/

Plan B:

You could do everything you want by NFC enable android phone, I found this black Friday sales go down as ~$70.

Thanks for the idea sonnyyu, but that's not really possible, since the arduino will function as a kind of scanning station for devices so I can track who took them/currently has them.

Using a Phone for such a stationary purpose wouldn't be a long time possibility.

Regards,

Patrick

I best guess the problem is run out of memory, upgrade Uno to Mega might be work arround.

Plan C:

Arduino Yun, now you could move NFC to Linux side, It has WIFI build in. plus mysql server, web server. You could make it working fine either online or offline. leave arduino only handle LCD display.

Thanks again :slight_smile:

I'll look into the Yun. Sounds like it would be better suited for the project. Could I also then let the yun handle the TFT, or do i need to connect it with the arduino set to slave?

Can't quite get though, how it could run out of memory when it says there's 477 Bytes of ram free :-\

Regards,

Patrick

CPU AP9331 at Yun has 29 GPIOs (I2C/SPI/I2S) but Yun has not broken out any, only way handle the TFT by ATmega32u4 at Yun.