Hi,
I am having difficulty getting this shield and code to work as detailed on this page:
I use the code for the IRQ2 communication method, and SPI interface.
I Get the following error:
C:\Program Files (x86)\Arduino\libraries\PN532_SPI/PN532_SPI.h:6:10: fatal error: PN532/PN532/PN532Interface.h: No such file or directory
#include "PN532/PN532/PN532Interface.h"
It seems somewhere in the include files the developer used a subfolder called:
"PN532_SPI/PN532_SPI.h"
I think it is because Linux uses forward slashes and Windows backslashes.
And thus the paths are not compatible.
Where do I find where this path has been used and fix it.
Really frustrating...
#include <SPI.h>
#include <PN532_SPI.h>
PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);
// FLAG_NONE used to signal nothing needs to be done
#define FLAG_NONE 0
// FLAG_IRQ_TRIGGERED used to signal an interrupt trigger
#define FLAG_IRQ_TRIGGERED 1
// FLAG_RESET_IRQ used to signal that the interrupt needs to be reset
#define FLAG_RESET_IRQ 2
// flags variable used to store the present flag
volatile int flags = FLAG_NONE;
String const myUID = "1B B3 C6 EF"; // replace this UID with your NFC tag's UID
// LED pins
int const greenLedPin = 3; // green led used for correct key notification
int const redLedPin = 4; // red led used for incorrect key notification
// the interrupt we'll be using (interrupt 0) is located at digital pin 2
int const irqPin = 2; // interrupt pin
String scannedUID = ""; // this is where we'll store the scanned tag's UID
void setup(void) {
// make LED pins outputs
pinMode(greenLedPin,OUTPUT);
pinMode(redLedPin,OUTPUT);
Serial.begin(115200); // start serial comm
Serial.println("NDEF Reader");
nfc.begin(); // begin NFC comm
// turn off the LEDs
digitalWrite(greenLedPin,LOW);
digitalWrite(redLedPin,LOW);
// attach the function "irq" to interrupt 0 on the falling edges
attachInterrupt(0,irq,FALLING);// digital pin 2 is interrupt 0, we'll call the irq function (below) on the falling edge of this pin
}
void loop(void) {
int flag = getFlag(); // get the present flag
switch(flag) // check which flag/signal we are on
{
case FLAG_NONE:
// nothing needs to be done
break;
case FLAG_IRQ_TRIGGERED: // the interrupt pin has been triggered
Serial.println("Interrupt Triggered");
if (nfc.tagPresent())
{
// an NFC tag is present
NfcTag tag = nfc.read(); // read the NFC tag
scannedUID = tag.getUidString(); // get the NFC tag's UID
if(myUID.compareTo(scannedUID) == 0) // compare the NFC tag's UID with the correct tag's UID (a match exists when compareTo returns 0)
{
// the scanned NFC tag matches the saved myUID value
Serial.println("Correct tag/key");
blinkLed(greenLedPin,200,4); // blink the green led
// put your here to trigger the unlocking mechanism (e.g. motor, transducer)
}else{
// the scanned NFC tag's UDI does not match the myUID value
Serial.println("Incorrect tag/key");
blinkLed(redLedPin,200,4); // blink the red led
// DO NOT UNLOCK! an incorrect NFC tag was used.
// put your code here to trigger an alarm (e.g. buzzard, speaker) or do something else
}
// return to the original state
setFlag(FLAG_NONE);
reset_PN532_IRQ_pin();
}else{
// a tag was not present (the IRQ was triggered by some other action)
setFlag(FLAG_NONE);
}
break;
default:
// do any other stuff for flags not handled above
break;
}
}
/*
* Name: setFlat
* Description: used to set actions/flags to be executed in the loop(void) function
* Parameters:
* int flag - the action/flag to store
* Returns: void
*/
void setFlag(int flag)
{
flags = flag;
}
/*
* Name: getFlag
* Description: used to get the present flag/action
* Parameters: void
* Returns: int - the flags variable. The action/flag set by setFlag
*/
int getFlag()
{
return flags;
}
/*
* Name: irq
* Description: Interrupt service routine (ISR). This function will be executed whenever there is a falling edge on digital pin 2 (the interrupt 0 pin)
* Parameters: void
* Returns: void
*/
void irq()
{
if(getFlag()==FLAG_NONE){
setFlag(FLAG_IRQ_TRIGGERED);
}
}
/*
* Name: reset_PN532_IRQ_pin
* Description: used to reset the PN532 interrupt request (IRQ) pin
* Parameters: void
* Returns: void
*/
void reset_PN532_IRQ_pin()
{
nfc.tagPresent();
}
/*
* Name: blinkLed
* Description: used to toggle a pin to blink an LED attached to the pin
* Parameters:
* ledPin - the pin where the led is connected to
* delayTime - the time in milliseconds between HIGH and LOW
* times - the number of times to toggle the pin
* Returns: void
*/
void blinkLed(int ledPin,int delayTime,int times)
{
for(int i=0;i<times;i++){
digitalWrite(ledPin,HIGH);
delay(delayTime);
digitalWrite(ledPin,LOW);
delay(delayTime);
}
}