Go Down

Topic: Arduino Uno Wifi Rev2 and Adafruit PN532 v1.6 (Read 269 times) previous topic - next topic

bthayer2

I have been trying to setup peer to peer connection over SPI between an Android phone and the Adafruit PN532 NFC shield connected to the Uno Wifi Rev2. The Adafruit library does not provide sample code to do this, so I am using this Github to help because there is P2P example code. Here is the specific code I am using:
Code: [Select]
#include "SPI.h"
#include "PN532_SPI.h"
#include "snep.h"
#include "NdefMessage.h"

PN532_SPI pn532spi(SPI, 10);
SNEP nfc(pn532spi);
uint8_t ndefBuf[128];

void setup() {
    Serial.begin(9600);
    Serial.println("NFC Peer to Peer Example - Receive Message");
}

void loop() {
    Serial.println("Waiting for message from Peer");
    int msgSize = nfc.read(ndefBuf, sizeof(ndefBuf));
    if (msgSize > 0) {
        NdefMessage msg  = NdefMessage(ndefBuf, msgSize);
        msg.print();
        Serial.println("\nSuccess");
    } else {
        Serial.println("Failed");
    }
    delay(3000);
}


For the wiring, I am basing it off the example on the documentation. The NFC shield does work; I tested it with sample code to read a mifare card. From the image in the link, I have moved the wires from pin 2 to 13, 3 to 11, 4 to 10, and 5 to 12. From what I understand this board is similar to the Adruino Uno R3, so I used the connection table to help rewire the board. I speculate my problem has something to do with my SS (Slave Select) which is currently at pin 10 and that is in the parameter in the code I am using.
The code and wiring I described work correctly with an Adruino Uno R3 which makes it odd that this similar board does not work. Here is what appears inside the Serial Monitor. I never do see the start message: "NFC Peer to Peer Example - Receive Message" and am not sure if that has anything to do with it not working. When this is running, msgSize remains at -1 and I have my Android on the NFC tyring to beam over a url but can never get it to say "Success" in the Serial Monitor.

My Arduino board has firmware version 1.2.1 and my Arduino IDE version is 1.8.8. I am new to working with this board, so any help would be much appreciated.

pert

From the image in the link, I have moved the wires from pin 2 to 13, 3 to 11, 4 to 10, and 5 to 12. From what I understand this board is similar to the Adruino Uno R3, so I used the connection table to help rewire the board.
The Uno WiFi Rev2 is similar in form to the Uno R3, but there are significant differences as well. One of these differences is that the SPI pins of the Uno WiFi Rev2 are not on pins 11, 12, and 13, as on the Uno R3. Instead the SPI pins are only available on the 2x3 ICSP header. The ICSP header is standardized, so the ICSP header pins for the Uno on that table from the SPI documentation page are correct for the Uno WiFi Rev2 as well. So move your wires over to the appropriate pins on the ICSP header and give it another try.

I speculate my problem has something to do with my SS (Slave Select) which is currently at pin 10 and that is in the parameter in the code I am using.
Using pin 10 for SS as you are doing already should be fine.

bthayer2

#2
Mar 25, 2019, 04:32 am Last Edit: Mar 25, 2019, 05:46 pm by bthayer2
I just tried that. I moved the MISO, MOSI, and SCK pins into the ICSP header, but the result is the same. The Serial Monitor just spams Failed. It was a good suggestion because I did not try that yet.

--Update
I borrowed a friend's Arduino Uno R3 and uploaded the P2P code with the wiring to the ICSP header and it is working like it should. It is very strange that it does not work with the Uno Wifi Rev2. Maybe I missed something when I set the board up which is making it behave differently.

--Update 2
I finally got it working, I used pin 4 instead of pin 10 and that somehow did the trick. Thanks for helping. I am still a little confused about the slave select. The documentation here says that "The IMU and the WiFi module are connected to the SPI bus and have individual and dedicated pins for Chip Select (CS)." I do not fully understand what this means, but the issue was related to my Slave Select.

Go Up