PN532 NFC Library [PORTED]


#104

Hi guys, I’m trying to get this library working with the following shield:
http://linksprite.com/wiki/index.php5?title=NFC_PN532_Shield

I’ve wired it up to what looks like a valid SPI configuration and set :
PN532_MODE (PN532_SPI_MODE)
PN532_HW_SPI (0)

It seems to be eventually return something at readstatus (after quite a lot of 0’s) however it then fails at readAck.

Am I perhaps missing something and using the wrong library : https://github.com/pkourany/AdafruitPN532_Library ?

Any help would be appreciated :smile:

Regards,
Kyle


#105

@jlkalberer, @Kyle, I got the seeed studio reader to work with hardware spi (actually I use spi1 but shouldn’t matter). The seeed shield has a voltage translation onboard so you have to connect power to VCC on the icsp header (5V if using the Photon wth a shield-shield).

You also have to be mindful of the jumper connection lengths to reduce noise/crosstalk. SPI and all the level shifting is a picky animal. PN532 supports a 5Mhz SCK. The library’s software spi runs at ~120Khz SCK (it varies). You have to adjust your hardware SCK accordingly for your particular setup (start slow and walk it up).


#106

Yeah, I also got mine working. I ported the seeed PN532 library but it’s mixed in with my other code here.


#107

Preface: I’m the consummate newbie when it comes to microcontroller/arduino-type programming and I use a Chromebook to flash my Electron. When I soldered the headers to my PN532, it was my time holding a soldering iron in 7 years. I’m fresh at this stuff.

My goal is to use my Elechouse PN532 with my Electron to read cards from a distance of 20cm (or if the operating range of the chip is less than that, as far as it will allow). My learning style is “change things and see what happens”, and it appears that all of the code available is geared toward serial connected MCs; I don’t have the capability at the moment, and the best I can do is use Particle.publish to send feedback to my device dashboard or, more simply, flash an LED to let me know what’s going on.

All of that is to say there isn’t anything out there for me to tweak/break/fix/explore in order to learn how to use my PN532 with my Electron. Alas! (I’ve read through about 70% of this and related threads on the PN532, but if I’m wrong on this, I’m gladly wrong and would appreciate if you point me to the gem I missed.)

Does anyone here have an Electron ready PN5323 example application I can hack around with?

I’d appreciate any advice or tutelage! (@jlkalberer, @BDub, @simon)

James


#108

@lomuscio, I’m not quite sure what you are missing :confused:
The stuff that works on the Photon is most likely also working on the Electron since both use the same MC and are mostly pin compatible.
The one thing that is a major difference (apart from the radio obviously) is that you can’t power 5V sensors off the Vin pin when only running on battery. For this you’d need an extra buck converter that boosts the 3.7V of the Li+ pin up to 5V.

What other option would you like to see?
There are multiple serial interfaces like RX/TX (the common serial) and other serial protocols like SPI, I²C, CAN, …


#109

Hey @jlkalberer,

are you using the grove nfc-shield?

could you post the connection scheme of your working solution and the .ino code?

Thank you verry much!

Regards,

Stivi


#110

Hello @jlkalberer or any other “seeing” Professional :wink:

i need help with nfc on photon…
I want to use this PN532 board:

I don’t know how to connect the PN532 board to the photon…which Pins of the photon should i connect to which Pins of the PN532???

I added the following files to my app from:

is it correct???

Thank you verry much!!!

Stivi


#111

It depends what interface you intend to use.
You have two jumpers (SEL0 & SEL1) and a table on the board that tells you how to set the jumpers to choose the desired interface.

Once decided on that have a look in the docs which pins are used for that interface.
https://docs.particle.io/datasheets/photon-datasheet/#pin-out-diagrams


#112

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


#113

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.


#114

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


#115

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.


#116

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.


#117

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


#118

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’


#119

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


#120

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


#121

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


#122

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-


#123

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