PN532 - need to know what arduino pins does it use

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
edusor
 
Posts: 6
Joined: Thu May 31, 2012 2:36 pm

PN532 - need to know what arduino pins does it use

Post by edusor »

hi, i have purchased PN532 (product 789) and i saw the video that just plug the shield onto arduino, i need to know
what arduino pins does this shiled uses because i need to add a new shield onto the PN532. the video do not explain
what are the arduino pins being used. thank you

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: PN532 - need to know what arduino pins does it use

Post by adafruit_support_rick »

By default, the shield communicates using I2C, which uses Analog pins 4 and 5. The shield also uses Digital 2.
If you configure the shield for SPI, you can use any four pins for the SPI signals, plus it will still need Digital 2.

edusor
 
Posts: 6
Joined: Thu May 31, 2012 2:36 pm

Re: PN532 - need to know what arduino pins does it use

Post by edusor »

my problem is: I need to attach a RTC to the PN532, but the code of the RTC does not allow me to chane the pins that
it uses (and it also uses pin 4 and 5 analog) . so, how can I do to attach my RTC to the PN532? how can I change the pins used
by RTC if the code does not show this info?,thank you

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: PN532 - need to know what arduino pins does it use

Post by adafruit_support_rick »

I2C is a bus. That is, you can attach multiple devices to the same two data lines.

You can connect both the PN532 AND the RTC to analog 4 and 5 with no changes and no conflicts! :D

edusor
 
Posts: 6
Joined: Thu May 31, 2012 2:36 pm

Re: PN532 - need to know what arduino pins does it use

Post by edusor »

hi, i have attached the RTC at the PN532, it can get the datetime.now() only at the first time,
after the first time in the loop, it lost the date and time, i guess the pin 4 and 5 are creating
a conflict somehow. so, i decided to run another sketch with only the RTC and it worked fine.
do you have any sugestion about how to solve this?

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: PN532 - need to know what arduino pins does it use

Post by adafruit_support_bill »

Post the code you are using. As driverblock says, I2C is a bus and it is designed to work with multiple devices connected to the same two pins.

edusor
 
Posts: 6
Joined: Thu May 31, 2012 2:36 pm

Re: PN532 - need to know what arduino pins does it use

Post by edusor »

[Edit - moderator - please use the 'code' button when submitting code]

Code: Select all

#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>

#include <SD.h>
#include "RTClib.h"

RTC_DS1307 RTC;
#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);
File myFile;
void setup(void) {
  Wire.begin();
    RTC.begin();
  Serial.begin(115200);
  Serial.println("Hello!");
  pinMode(10, OUTPUT);
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // Set the max number of retry attempts to read from a card
  // This prevents us from waiting forever for a card, which is
  // the default behaviour of the PN532.
  nfc.setPassiveActivationRetries(0xFF);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
    
  Serial.println("Waiting for an ISO14443A card");
   if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test3.txt", FILE_WRITE);
}

void loop(void) {
  DateTime now = RTC.now();
  String mytime = "         ";
  String auxtime = " ";
  auxtime = String(now.year(), DEC);
  mytime += auxtime;
  mytime += "/";
  auxtime = String(now.month(), DEC);
  mytime += auxtime;
  mytime += "/";
  auxtime = String(now.day(), DEC);
  mytime += auxtime;
  mytime += "/";
  auxtime = String(now.hour(), DEC);
  mytime += auxtime;
  mytime += "/";
  auxtime = String(now.minute(), DEC);
  mytime += auxtime;
  mytime += "/";
  auxtime = String(now.second(), DEC);
  mytime += auxtime;
  
  
  
  boolean success;
  String myUID = ""; 
  
  String oneUID = "    ";
  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[0], &uidLength);
  
  if (success) {
    //Serial.println("Found a card!");
    //Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    //Serial.print("UID Value: ");
    for (uint8_t i=0; i < uidLength; i++) 
    {
      //Serial.print(" ");Serial.print(uid[i], DEC); 
      
      //myUID =  String(myUID + (uid[i],DEC));
      //myUID = myUID + (uid[i],DEC);
      oneUID = String(uid[i],DEC);
      myUID += oneUID;
    }
    Serial.println(myUID);
    Serial.println("");
    Serial.println(mytime);
    Serial.println("");
    myUID += ";";
    myUID += mytime;
    // write at SD card what was read 
    myFile.println(myUID);
    // close the file:
    myFile.close();
    // Wait 1 second before continuing
    delay(1000);
    myFile = SD.open("test3.txt", FILE_WRITE);
  }
  else
  {
    // PN532 probably timed out waiting for a card
    Serial.println("Timed out waiting for a card");
  }
}

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: PN532 - need to know what arduino pins does it use

Post by adafruit_support_bill »

Keep in mind that this line:

Code: Select all

 success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
will block until a card is detected. You should get a time-stamp after the card is detected.

edusor
 
Posts: 6
Joined: Thu May 31, 2012 2:36 pm

Re: PN532 - need to know what arduino pins does it use

Post by edusor »

thank you so much, now its working fine.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”