PN532 NFC Library [PORTED]


#124

Can you see the Photon in Device Manager?
Which COM port?
What serial monitor are you using?
Have you selected the correct port?
Do you see serial output when running another sketch which permanently does something like Serial.print(".")?


#125

Hi

i am using the serial monitor of particle dev on macbook pro.

Now i have an console output!!!:smile:

But when i put a mifare classic card to the reader, there is nothing happend


#126

I don’t know if this is required, but just to be on the safe side, try connecting _irq and _reset too.
And maybe @peekay123 or @jlkalberer could chime in again since I have no such hardware handy :pensive:


#127

Could it be a power problem?

Can i try to connect the PN532 board with the 5V pin to the VIN pin of the photon?


#128

_irq and _reset are = D0 and D1 or not?

I only connected SDA to D0 and SCL to D1

and in the code:

const int _irq = D0; // select your own pin for that
const int _reset = D1; // select your own pin for that


#129

I2C is safe to be used with 5V, so I wouldn’t see why it should be a problem.


Nope, D0/D1 are the interface pins the other two are seperate control pins and hence I used D3/D4
You have got dedicated pins on the shield (RSTOUT & IRQ) to connect to the respective (chosen) pins on the Photon.


#130

WOW!!!

THANK you very very much @ScruffR !!! :clap:

Now its running!!!

I never seen an better support before!!! I am absolutely excited!!!

You are really “ELITE”


#131

@peekay123 I was looking around for examples of implementing pullup on the NFC board in question I can see Resistors in parallel here but I cant see how thats improved the reading from the board; Im possibly being dense here or else my photon is now different from the one pictured above.


#132

@loudmouthman, pull-ups are used for I2C but not for SPI so I’m not sure which pull-ups you are referring to. What are you trying to achieve?


#133

Heres a link to a Google Photos Album showing the Arduino operation im using and a close up of the NFC board; https://goo.gl/photos/sfMUtzE6cjhcasc67 Looking at the code im working with in Build vs the code in the Sketch theres a difference there but hopefully you can see what ive been working towards on the photon.


#134

Is this Photon setup working? :confused:

You’ve got SDA/SCL connected to D3/D2, but I2C is on D0/D1.


#135

well in this and other cases I have amended the lines in the code to reflect moving the pins down and along; ive tried a few pin positions and updated the build code; let me move things around then post the code and the pins.


#136

Progress in the path to reading; I can get the code to at least see a board in play and now im down to getting it to read a Tag of any type. My Serial output now has

Opening serial monitor for com port: "COM4"
Hello!
Found chip PN5
3
Firmware ver.
50.1
Waiting for an ISO14443A Card …

nfc.readPassiveTarget Failed

I moved the pins and reset the relevant code you can see my TagWriter shows I have the respective MiFare iso14443A formatted dataset on the card https://goo.gl/photos/S6P12zafg6XabzmJA

Currently my Code; based on readMiFareClassic looks like this and again thanks for taking time to look it over

/**************************************************************************/
/*! 
    @file     readMifareClassic.cpp
    @author   Adafruit Industries, Paul Kourany, Technobly
    @license  BSD (see license.txt)

    This example will wait for any ISO14443A card or tag, and
    depending on the size of the UID will attempt to read from it.
   
    If the card has a 4-byte UID it is probably a Mifare
    Classic card, and the following steps are taken:
   
    Reads the 4 byte (32 bit) ID of a MiFare Classic card.
    Since the classic cards have only 32 bit identifiers you can stick
    them in a single variable and use that to compare card ID's as a
    number. This doesn't work for ultralight cards that have longer 7
    byte IDs!
   
    Note that you need the baud rate to be 115200 because we need to
    print out the data and read from the card at the same time!

This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout 
  ----> https://www.adafruit.com/products/364
 
Check out the links above for our tutorials and wiring diagrams 
These chips use SPI to communicate, 4 required to interface

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit

20160528 - Niks Notes
Added AdaFruit_PN532/ to the Include for Adafruit_PN52.h 
Aommented out spark_disable_wlan as its deprecated
Added particle.process within the core While loops as it was causing the breathing green error. 
Added SYSTEM_THREAD(ENABLED)  to help ensure photon processes are not blocked !
Commented out checking for Serial.Available it was just looping there forever.
Removed headers related to SPI and spurious SPARK_WLAN requests.
Current Particle.process() may be redundant but its a difference between breathing Cyan or Breathing green. 

!
*/
/**************************************************************************/

#define SYSTEM_THREAD(ENABLED)

#include "Adafruit_PN532/Adafruit_PN532.h"

#define IRQ_PIN  (D0) // This is how the PN532 Shield gets ready status in I2C mode
#define RST_PIN  (D1) // Necessary for I2C mode

Adafruit_PN532 nfc(IRQ_PIN, RST_PIN);


void setup(void) {
  Serial.begin(115200); // Make sure your serial terminal is closed before power the Core.
  
   
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata;
  
  do {
    versiondata = nfc.getFirmwareVersion();
    if (!versiondata) {
      Serial.print("Didn't find PN53x board\n");
      delay(1000);
      Particle.process();
    }
    Particle.process();
    
    
  }while(!versiondata);
  
  

  // Got ok data, print it out!
  Serial.print("Found chip PN5\n"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. \n"); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();

}


void loop(void) {

  Particle.process();
  Serial.println("Waiting for an ISO14443A Card ...\n");
  delay(1000);
  
  
  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);
  
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    
    if (uidLength == 4)
    {
      // We probably have a Mifare Classic card ... 
      uint32_t cardid = uid[0];
      cardid <<= 8;
      cardid |= uid[1];
      cardid <<= 8;
      cardid |= uid[2];  
      cardid <<= 8;
      cardid |= uid[3]; 
      Serial.print("Seems to be a Mifare Classic card #");
      Serial.println(cardid);
    }
    Serial.println("");
 
  }  else {
    Serial.println("nfc.readPassiveTarget Failed\n");
    
    }
}


#137

This is the same error that I’ve already pointed out earlier in this thread

You can’t have I2C and IRQ/RESET use the same pins!

BTW: The readMifareClassic.cpp that’s part of the Build library repo has this code snippet

// I2C Mode defines
#define IRQ_PIN  (D2) // This is how the PN532 Shield gets ready status in I2C mode
#define RST_PIN  (D3) // Necessary for I2C mode

Which would’ve worked better :wink:


#138

Ahh okay im getting turned around here your previous comment ( PN532 NFC Library [PORTED] ) was that I had them in D2/D3 and I had the respective code adapted; so I moved them to D0/D1 and then posted the last result. Anyway with pins in D0 and D1 I had the board listening but in D2/D3 not so much. Assume here that I double checked I didnt have the wires in IRQ/RST crossed.

I started in D2/D3 and I moved them to D0/D1 but as long as the respective Pin is connected Code to Kit it should not make a difference there.

So if I have the kit on D2/D3 as in the original code and photo im still seeing

“Didn’t find PN53x board
Didn’t find PN53x board


#139

I should point out … I dont have them on the same pins; or do I ? I mean i have them connected to the respective columns in the bread board ; if I swap out this project to a blinking LEDs on those pins I can see them working as I would expect.

So I have

NFC BOARD ----Breadboard ---- PHOTON
GND ----- 4 ---- GND
VCC ----- 1 ----- 3v3
SDA ----- 9 ---- D3
SCL ----- 10 ---- D2


#140

@loudmouthman, you seem to be misunderstanding me here.

The communication via I2C needs to use D0 (SDA) and D1 (SCL), but the code also requires to extra pins (IRQ and RESET) to control the device, and these extra pins are not allowed to be set to the same pins as your communication pins (even if you haven’t these pins connected).

The physical wiring has to be SDA <-> D0 / SCL <-> D1 but the code needs to leave these pins alone and not use D0/D1 for anything.

Looking at your pic, you have two solder eyes marked IRQ and RSTO on your board - these would be the places that’d need to be connected to the pins designated via IRQ_PIN and RST_PIN and hence SDA and IRQ can’t share D0 the same as SCL and RST can’t share D1!


#141

Cheers for that; okay so what I cant understand here is why the Arduino with similar code works on the same NFC reader example however getting the board to be identified and work correctly on the photon using the same SDA/SCL Pins on the Photon isnt working. Possibly I need to back a step and maybe look at the code/communication im trying to share in this discussion.

In the arduino example it can read tag over that board without the need to connect more pins; So possilbly im using the wrong example code .


#142

To avoid any further confusion, which pins are you now using for SDA/SCL on the Photon then?
And how have you defined the two extra pins?

And as this adivce seemed to help the OP try this just to be sure

You can always take them out and see if and how it works without them or how to tweak the code to not need them.


#143

Thanks Scruffr ; I made a rough ascii art to show how I was connecting things on the Photon/breadboard/Reader; Ive now moved them down to D1/D0

It finds the board, but it doesnt actually appear to be happy with the Reading of the Card process as it always fails . If I swap the NFC Board wires back to the Arduino then those same 4 wires out of the board are working to show me the data on the NFC Tag; At least I know that the Board is working and that the two wires SDA/SCL are transporting some information when prompted. However the Code in the Photon example readmifareClassic is apparently not pulling the data in; it might be reading something.