Server not working with NFC shield on Arduino Yun

I am currently trying to make a buzzer go off when it detects a certain NFC tag which works but i also want to control 2 servo motors remotely from a website that i made which they both work separately but the Server won’t work (it won’t check for commands send by the website) when NFC is working and i need them both working in the same section of code. So how can i get both the NFC and the server working at the same time.

Here is my current code:

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#include <Servo.h>
#include <SPI.h>
#include "PN532_SPI.h"
#include "PN532.h"
#include "NfcAdapter.h"

String const myUID1 = "04 A7 86 9A 79 40 80" ;
String const myUID2 = "04 8B 86 9A 79 40 80" ;
int Buzzer = 8;

PN532_SPI interface(SPI, 10); // create a SPI interface for the shield with the SPI CS terminal at digital pin 10
NfcAdapter nfc = NfcAdapter(interface); // create an NFC adapter object

YunServer server;
Servo PanServo;
Servo TiltServo;

void setup() {

  PanServo.attach(5);
  TiltServo.attach(6);
  Bridge.begin();
  server.listenOnLocalhost();
  server.begin();
  Console.begin();
  Console.println("NDEF Reader");
  nfc.begin();
  pinMode(Buzzer, OUTPUT);
  
}

void loop() {

      YunClient client = server.accept();

    if (client) {
      process(client);
      client.stop();
    }
    delay(20);
  
  Console.println("Scanning...");
  if (nfc.tagPresent())
  {
    NfcTag tag = nfc.read();
    String scannedUID = tag.getUidString();

    if ( myUID1.compareTo(scannedUID) == 0) 
    {
      Console.println("Correct Key");

      digitalWrite(Buzzer, HIGH);
      delay(50);
      digitalWrite(Buzzer, LOW);
      delay(50);
      
    } else {
      if (myUID2.compareTo(scannedUID) == 0)
      {
        Console.println("Correct Key");

        digitalWrite(Buzzer, HIGH);
        delay(50);
        digitalWrite(Buzzer, LOW);
        delay(50);
        
      } else {
        Console.println("Incorrect key");
        digitalWrite(Buzzer, HIGH);
        delay(250);
        digitalWrite(Buzzer, LOW);
        delay(250);
        digitalWrite(Buzzer, HIGH);
        delay(125);
        digitalWrite(Buzzer, LOW);
        delay(125);
      }
    }




    delay(15);
    
    
  }
}

  //Below to commented works
  void process(YunClient client) {
    String command = client.readStringUntil('/');

    if (command == "servo") {
      servoCommand(client);
    }

  }

  void servoCommand(YunClient client) {
    int pin, value;

    pin = client.parseInt();

    if (client.read() == '/') {
      value = client.parseInt();

      if (pin == 5)
      {
        PanServo.write(value);
      }

      else if (pin == 6)
      {
        TiltServo.write(value);        
      }
      else if (pin == 99)
      {
        PanServo.write(value);
        TiltServo.write(value);        
      }
    }

  }

Plan B: Move it to Linux side

Openwrt/YunOS has very good lib to support NFC

PLAN C:
Just work on the NFC, remove the other code.

I tried to move the NFC to the Linux side but it is say "No NFC device found" which i think is because its a NFC shield and not plugged in via usb. the shield i am using is NFC Shield V2.0 http://www.seeedstudio.com/wiki/NFC_Shield_V2.0

Use NXP NFC IC chip above PN532

i'm not going to get another chip over the shield i already have. So i want a solution for my current NFC shield not another one

Among NXP IC list:

  • NXP PN531 Obsolete
  • NXP PN532 Most of NFC shield, if not all.
  • NXP PN533 (SCM SCL3711)
  • NXP PR533
  • NXP PN544
  • NXP PN65N
  • NXP PN65V10 Apple Iphone 6
  • NXP PN7120

I test all but exclude PN65V10 and PN7120. PN65V10 is only available for Apple anyway.
However you need to compile software for individual chip set (PN533/PN544/PN65N shared the same software driver). I personally focus on NXP PN65N since PN65V10 made NXP stock price doubled in less than year.

@RK23,
Sorry for the delay,

On Sunday, I bumped my elbow and have been incapacitated. My elbow is okay, except for a large grapefruit-sized bump . No broken or cracked bones, just a big ugly bruise. I've had it on ice for the last three day.

On your issue, I am again going to recommend that you try JUST the NFC shield. I see in your code that you have several SERVOs. It is very possible that one of the servos is conflicting with you NFC device. We have scant details about the shield you choose. The best we know at this point is you are using a SEEED NFC shield.

Just looking at the page I can see, it likely works via SPI and has an interrupt.

Lastly, I am not a hardware guy, so someone else will have answer your hardware question. Fear not, there are plenty of people on this forum.

Jesse

The NFC shield v2 from seed should work just fine with Yun. I use it extensively.

You might want to move the NFC into an interrupt based flow (see example on seeed wiki) to let your server routine do its tasks.

And lastly for servos.. make sure you don't power the servo from the Yun's power pins if you have an alternate source. Servos are electrically noisy and won't play well with micro controllers in the long run.