NFC v2.0 with arduino Leonardo eth

I just bought a NFC shield v2.0b and I want to make it work on Arduino Leonardo eth, but I just can’t figure out how… I tested the shield on arduino one and worked fine, so I know the shield it’s ok.

Can someone please tell me what should I do? I’m a bit new working with leonardo, so I can’t think what could it be…

Thank you on advance! :smiley:

no one? :frowning:

Hello,

Sorry for the delayed reply

1.Please cut the connection between D10 and SS pin with a knife.
2.Connect the D9 and SS by soldering them as shown in the picture
3.Modify the following lines in the code as follows

[code]// Enable SPI NFC Shield

PN532_SPI pn532spi(SPI, 9); [/code]

Add the following lines in the setup

[code]// Disable SD card SPI to Arduino Leonardo ETH

pinMode(4, OUTPUT);

digitalWrite(4, HIGH);

// Disable Ethernet chip SPI to Arduino Leonardo ETH

pinMode(10, OUTPUT);

digitalWrite(10, HIGH);

[/code]

Thanks and Regards
Pn532-nfc-shield-pin-description.jpg

thanks!!! it worked great :smiley:

Hey everyone,

sorry for hijacking this thread, it just fits in nicely. I have had the same issue which was resolved changing this pin assignment. However, it seems the NFC shield and Leonardo ETH’s networking functionality seem to be mutually exclusive.
After nfc.begin(); any existing network connection is dropped or cannot be established. I fail to find the reason for that. Explanations greatly appreciated.

Thanks,
o.

Hi,

Both NFC shield and Leonardo ETH uses SPI.This causes conflict in your issue.If you are using NFC enable the 9th pin and disable 10th pin and do the vice versa when you want to use the ETH.

In the example code that we have given in this thread we would have disabled the 10th pin always in the setup function which was exclusively written for NFC shield to work.

Please remove that part of code and include appropriate enable and disabling of pin in the loop function according to your requirement.

Thanks and Regards

Dear kavi,

thanks for your reply. It clarified the method but still no success. Below is the condensed version of my ardu code which flips pins when the networking happens. Still, any previous link is down or cannot be created inside. Guess I’m still doing it wrong. :slight_smile:

Thanks a bunch,
o.

[code]#include <Ethernet2.h>
#include <SPI.h>
#include “PN532_SPI.h”
#include “PN532.h”
#include “NfcAdapter.h”

// ottona: default pin is 10, this one here is needed for the leonardo eth
PN532_SPI interface(SPI, 9); // create a PN532 SPI interface with the SPI CS terminal located at digital pin 9
NfcAdapter nfc = NfcAdapter(interface); // create an NFC adapter object
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x1B, 0x97 };
byte server[] = { 192, 168, 5, 76 };
byte myip[] = { 192, 168, 5, 115 };

void setup(void) {
Serial.begin(115200); // begin serial communication
Serial.println(“NDEF Reader”);
delay(1000);

pinMode(4, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(4, HIGH);
pinMode(10, OUTPUT);

Ethernet.begin(mac, myip);
Serial.println(Ethernet.localIP());
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
nfc.begin(); // begin NFC communication

}

void loop(void) {

if (nfc.tagPresent()) // Do an NFC scan to see if an NFC tag is present
{
    NfcTag tag = nfc.read(); // read the NFC tag into an object, nfc.read() returns an NfcTag object.
    tag.print(); // prints the NFC tags type, UID, and NDEF message (if available)
    
    digitalWrite(9, HIGH);  // disable nfc shield
    digitalWrite(10, LOW);  // enable networking
	EthernetUDP udp;
    udp.beginPacket(server, 44789);
    udp.write("TESTMSG"/*tag.getUidString()*/);
    udp.endPacket();
    digitalWrite(10, HIGH); // disable networking
    digitalWrite(9, LOW);   // enable nfc shield
    
    
}
delay(500); // wait half a second (500ms) before scanning again (you may increment or decrement the wait time)

}[/code]

Hi,

We have modified your code please let us know if it helps.

[code]#include <Ethernet2.h>
#include <SPI.h>
#include “PN532_SPI.h”
#include “PN532.h”
#include “NfcAdapter.h”

// ottona: default pin is 10, this one here is needed for the leonardo eth
PN532_SPI interface(SPI, 9); // create a PN532 SPI interface with the SPI CS terminal located at digital pin 9
NfcAdapter nfc = NfcAdapter(interface); // create an NFC adapter object
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x1B, 0x97 };
byte server[] = { 192, 168, 5, 76 };
byte myip[] = { 192, 168, 5, 115 };

void setup(void) {
Serial.begin(115200); // begin serial communication
Serial.println(“NDEF Reader”);
delay(1000);

    pinMode(4, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    digitalWrite(4, HIGH);  //Always disable SD card SPI
   
    digitalWrite(10, LOW); //Enable ETh
    digitalWrite(9, HIGH); //Disable NFC
    Ethernet.begin(mac, myip);
    Serial.println(Ethernet.localIP());
    digitalWrite(10, HIGH); //Disable ETh
    digitalWrite(9, LOW);   // Enable NFC
    nfc.begin(); // begin NFC communication
}

void loop(void) {

    Serial.println("\nScan an NFC tag\n");

    if (nfc.tagPresent()) // Do an NFC scan to see if an NFC tag is present
    {
        NfcTag tag = nfc.read(); // read the NFC tag into an object, nfc.read() returns an NfcTag object.
        tag.print(); // prints the NFC tags type, UID, and NDEF message (if available)
       
    }

   digitalWrite(9, HIGH);  // disable nfc shield
   digitalWrite(10, LOW);  // enable networking
   
   Ethernet.begin(mac, myip); 
   
   EthernetUDP udp;
   udp.beginPacket(server, 44789);
   udp.write("TESTMSG"/*tag.getUidString()*/);
   udp.endPacket();

   delay(500); // wait half a second (500ms) before scanning again (you may increment or decrement the wait time)

   digitalWrite(10, HIGH); // disable networking
   digitalWrite(9, LOW);   // enable nfc shield
   
   nfc.begin(); // begin NFC communication
}[/code]

Thank you again kavi for your support!

Still no luck sending data. I tried the sketch you sent and printf-debugged to the line the code freezes: digitalWrite(9, HIGH); // disable nfc shield digitalWrite(10, LOW); // enable networking Ethernet.begin(mac, myip); EthernetUDP udp; udp.begin(1234); udp.beginPacket(server, 44789); udp.write("TESTMSG"); udp.endPacket(); // <-- THIS CALL NEVER RETURNS udp.stop(); [...] digitalWrite(10, HIGH); // disable networking digitalWrite(9, LOW); // enable nfc shield
I’m getting the impression that it is not possible to use ethernet and the shield intermittently. Currently, I blame the Arduino for that, as the pin setting procedures work with the shield (in other words: when commenting out the UDP part the code runs nicely). I’ll check up with the ardu forums and report back for further reference.

Cheers,
o.

Success!

Reporting back to let others know there’s a solution to this problem. The main issue is the bit ordering that the NFC shield sets to LSB. Now, when the ethernet tries to communicate with the chip, it basically reads nonsense.
We hence modified the read and write functions in PN532_SPI to set the order to LSBFIRST prior to any comm with the shield (right before setting the own pin to low) and reset it to MSBFIRST after the access. That way we assure the ethernet link receives data as expected.
Furthermore, it is advisable to set the SPI bus clock to 4MHz (default for the NFC shield is 2MHz, 5MHz is max, according to a comment in the code) by setting the clock divider to 21. A higher bus clock is usually better for the ethernet chip’s performance. As a side note, it’s not necessary to set any SPI pins manually, this is all done internally by PN532 and the ethernet2 lib.
If it’s of interest to somebody, I’d be happy to elaborate in more detail.

Cheers,
o.

Good day

I had the same problem, now it is cleared. Thanks
Could You pls explain, Is there a way to use Ethernet and NFC in the same time, or i must choose one of them, and disable other one?

Thanks