@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).
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?
@lomuscio, I'm not quite sure what you are missing
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, ...
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.
#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.
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.
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
I’ll have to spin up Build with a fresh sample to check …
stay tuned …
Doh!!!
The same two lines again.
I converted #defines to const int but forgot to add the already mentioned semicolonand also the assignment operator (=) (updated again)
That comes from typing it into the post rather than running it through Build - sorry
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.