PN532 NFC Library [PORTED]

Hi,

thanks for fhe verry fast response!!!

I want to use I2C…and set the jumpers to I2C

But I don’t know, how to include the PN532 Library and which Library is the right one.

I want to run the simple example Script read_mifare

Thanks,

Stivi

Where did you see the read_mifare sample app?
If you saw it on Particle Build as part of this library, why not just import that and give it a try?

Just click on the sample and then press USE THIS EXAMPLE.
Then if you want to use I2C, you’d alter these lines in the sample

#include "Adafruit_PN532.h"

#ifdef SPARK_CORE
#define SCK  (A3)
#define MOSI (A5)
#define SS   (A2)
#define MISO (A4)
#else
#define SCK  (2)
#define MOSI (3)
#define SS   (4)
#define MISO (5)
#endif

Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);

to

#include "Adafruit_PN532/Adafruit_PN532.h"

const int _irq   = D3;  // select your own pin for that
const int _reset = D4;  // select your own pin for that

//Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
Adafruit_PN532 nfc(_irq, _reset);

And see what happens.

Since I haven’t got access to that exact board, I’d have to guess, but it might be worth a try, especially since this lib was ported by @peekay123 who is a highly valued fellow Elite in this forum and will definetly assist, if you have further questions.

Ok, i will try it later with the Particle Library.

With the Grove I had to set it to I2C mode. This wasn’t very useful since it couldn’t handle much data. I’m trying to send NDEF messages.

The I2C library I have in my code was working but for less than 48 bytes of data I think.

The chips I was using were the Adafruit PN532 board or the Seeed PN532 shield.

I plan on actually moving the NFC code outside the app I’m building because I just got it working great on all versions of Android last night. Stay tuned for a cleaned up library.

Yeah, use the Particle Library. I started with that just to prove that everything worked on my device. I also used it as a basis to port over the Seeed library before hardware SPI was functional.

Hello @ScruffR and @jlkalberer

i tried your helpful hints but i get compiler errors…

Here are my setup:

When i “Verify” in Particle Build, i get the following errors:

and:

Thank you a lot again for the professional help!!!

Stivi

Sorry forgot the semicolons here (updated above too) :blush:

const int _irq   = D3;  // select your own pin for that
const int _reset = D4;  // select your own pin for that

That’s a cryptic error message tho’

OMG!!! Sorry, the semicolons should i see too…

But now, other errors:

In file included from …/hal/inc/gpio_hal.h:31:0,
from …/hal/src/stm32f2xx/platform_headers.h:16,
from ./inc/application.h:32,
from nfc3.cpp:2:
…/hal/inc/pinmap_hal.h:91:12: error: expected initializer before numeric constant
#define D0 0
^

nfc3.cpp:4:18: note: in expansion of macro 'D0’
void loop(void);
^
…/hal/inc/pinmap_hal.h:92:12: error: expected initializer before numeric constant
#define D1 1
^

nfc3.cpp:5:18: note: in expansion of macro ‘D1’
#line 1
^
nfc3.cpp:8:20: error: ‘_irq’ was not declared in this scope

                ^

nfc3.cpp:8:26: error: ‘_reset’ was not declared in this scope

                      ^

make[1]: *** […/build/target/user/platform-6nfc3.o] Error 1
make: *** [user] Error 2

I’ll have to spin up Build with a fresh sample to check …

stay tuned …

Doh!!! :flushed: :stuck_out_tongue_closed_eyes:

The same two lines again.
I converted #defines to const int but forgot to add the already mentioned semicolon and also the assignment operator (=) (updated again)
That comes from typing it into the post rather than running it through Build - sorry

Yes! The compile and flash is now successful but after a few seconds, the photon switch into “Cloud not connected” (Green Led flash slow)

I guess this happens because of this in setup()

  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

Change it to

  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1) Particle.process(); // halt
  }

This way it will at least stay connected.
But in order to get the thing running, what firmware version have you got on your Photon?
Try swapping your I2C wires.

https://docs.particle.io/reference/firmware/photon/#wire-i2c-

Hmm...now the photon stays connected and one of the LED on the PN532 Board is flashing very fast.

But i am wondering, there is no console output

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(".")?

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

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:

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?

_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

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.

1 Like

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”

2 Likes

@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.