Yun & NFC Shield

Im using the Yun with the Elecfreaks NFC Shield v1.6.
I have rewired everything as follows - to make it work using I2C.

+5V +5V
A4 D2 (SDA)
A5 D3 (SCL)
D6 D6 (IRQ)
D10 D10 (SS)

I am using Adafruit’s library (GitHub - adafruit/Adafruit_NFCShield_I2C: I2C Driver for Adafruit's PN532-based NFC Shield) and I have defined in the sketch the IRQ.

Nothing happens in the Serial - not even the Serial is initialized…

I have no idea why it is not working. I have checked a lot of forums and tried their advices, but I can’t see the problem.

You need to post to the Yun forum on this site. I've asked the moderator to move the posting.

Great, thanks

Ok, some progress on this.

At the moment using the following code I can see that the shield is working and able to read the tags (as appears activity from the LEDs of the boards).
But still, I get no Serial monitor whatsoever. Not even the “hello” message after the initialization.


    @file     readMifare.pde
    @author   Adafruit Industries
    @license  BSD (see license.txt)

    This example will wait for any ISO14443A card or tag, and
    depending on the size of the UID will attempt to read from it.
    If the card has a 4-byte UID it is probably a Mifare
    Classic card, and the following steps are taken:
    - Authenticate block 4 (the first block of Sector 1) using
      the default KEYA of 0XFF 0XFF 0XFF 0XFF 0XFF 0XFF
    - If authentication succeeds, we can then read any of the
      4 blocks in that sector (though only block 4 is read here)
    If the card has a 7-byte UID it is probably a Mifare
    Ultralight card, and the 4 byte pages can be read directly.
    Page 4 is read by default since this is the first 'general-
    purpose' page on the tags.

    This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
    This library works with the Adafruit NFC breakout 
    Check out the links above for our tutorials and wiring diagrams 
    These chips use I2C to communicate

    Adafruit invests time and resources providing this open source code, 
    please support Adafruit and open-source hardware by purchasing 
    products from Adafruit!
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>

#define IRQ   (6)
#define SDA   (2)
#define SCL   (3)
#define RESET (1)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

void setup(void) {


  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  // configure board to read RFID tags
  Serial.println("Waiting for an ISO14443A Card ...");

void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    if (uidLength == 4)
      // We probably have a Mifare Classic card ... 
      Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
      // Now we need to try to authenticate it for read/write access
      // Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
      Serial.println("Trying to authenticate block 4 with default KEYA value");
      uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
      // Start with block 4 (the first block of sector 1) since sector 0
      // contains the manufacturer data and it's probably better just
      // to leave it alone unless you know what you're doing
      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
      if (success)
        Serial.println("Sector 1 (Blocks 4..7) has been authenticated");
        uint8_t data[16];
        // If you want to write something to block 4 to test with, uncomment
        // the following line and this text should be read back in a minute
        //memcpy(data, (const uint8_t[]){ 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0 }, sizeof data);
        //success = nfc.mifareclassic_WriteDataBlock (4, data);

        // Try to read the contents of block 4
        success = nfc.mifareclassic_ReadDataBlock(4, data);
        if (success)
          // Data seems to have been read ... spit it out
          Serial.println("Reading Block 4:");
          nfc.PrintHexChar(data, 16);
          // Wait a bit before reading the card again
          Serial.println("Ooops ... unable to read the requested block.  Try another key?");
        Serial.println("Ooops ... authentication failed: Try another key?");
    if (uidLength == 7)
      // We probably have a Mifare Ultralight card ...
      Serial.println("Seems to be a Mifare Ultralight tag (7 byte UID)");
      // Try to read the first general-purpose user page (#4)
      Serial.println("Reading page 4");
      uint8_t data[32];
      success = nfc.mifareultralight_ReadPage (4, data);
      if (success)
        // Data seems to have been read ... spit it out
        nfc.PrintHexChar(data, 4);
        // Wait a bit before reading the card again
        Serial.println("Ooops ... unable to read the requested page!?");

I have disconnected everything, and even with the most simple example Yun does not print anything in the Serial. Searched the forum, but couldn't find any information to make it work. I don't know why this is happening; it was working a couple of days ago.

I'm dont have a Yun...

But are you sure that you are uploading ?

Can you write a blink program to confirm that the board is working at all ?

Yes uploading works fine, code seems to be ok, but no Serial printing!

Simplify you code, just do the bare minimum on the Yun to get print working

Actually, take Blink.ino and get it to print ever time it blinks (then you can confirm its running and printing)

As I said before, this is exactly what I did. Blink works fine except from the Serial.......

Plan B:

Connect reader with Yun side USB port.

How do you upload the code to your Yun? Via WiFi or USB cable?

Exactly how are you trying to read the serial output? Are you using the Arduino Serial Monitor? Are you using another terminal emulator application?

Keep in mind that unlike some other boards, on the Yun the USB serial port that is used with Serial is handled by the processor. Boards like an Uno use a separate chip to do the USB to serial conversion, but the Yun is like the Leonardo in that regard: the USB protocol is handled by the processor. That means that the USB connection is reset and re-initialized each time the sketch starts. This is important because it means that any connection that was active when the sketch starts is no longer valid: it will be necessary to close the serial port on the host side and re-open it. So, if you are using something like Hyperterminal to talk to the Yun through the USB port, you must restart the connection each time you restart the sketch.

Now, even if you do restart the connection each time, odds are you will never see the initial "Hello" output or much of the other serial output from setup(), because the sketch is likely to be well past that point by the time you successfully open the USB serial port on the host side. If you want to be sure to catch that initial output, it is customary to put a construct like this right after the Serial.begin() call:

while (!Serial)

This will cause the sketch to stop and wait for a serial connection to be established. However, be aware that this will prevent the sketch from working stand-alone without a host connection to the USB serial port, so you will likely want to remove it once you are done with debugging.

Any of this may or may not have anything to do with your situation. I don't want to sound condescending, that is not at all my intent, but it probably comes down to the details: there doesn't seem to be anything wrong with the sketch, so it may be a connection problem or user operation error in connecting to the USB device. So the question remains, how exactly are you trying to connect to the board to read the serial output?

Here is another source of information on the ElecFreaks products. It is the manufacturer's forum. The Url is:

They are a bit slow, but, do get around to answering the questions. I have used one of their Bluetooth shields.

I I hope this helps.

Thank you for your suggestions


Helped my issue with the Serial. It can print now.

But still, no shield coming… I have tried the forums…they are indeed very slow!!!

Glad to hear you got the serial output working. I hope you get the NFC reader working soon. (But at least now you can add some debug statements to print out status at key points to see what the code is doing.)

louisbourdon: while(!Serial){ ; }

Just a minor point on syntax: you can use either the curly braces, or the semicolon. Either will signal your desire that there be an empty do-nothing statement for the while loop. While it doesn't hurt to use both, it's a bit redundant.

You could even do this:

while (!Serial);

but I really don't recommend it. The semicolon on the end satisfies the compiler and signals an empty loop, but it's too easy to miss the semicolon while reading the code and assume that the next statement is the loop body. That's why my example above has the semicolon indented on the next line, to make it obvious it's an empty null loop.

Getting the Adafruit NFC Shield working on the Yun. (or Leonardo). Apart from moving the IRQ on the PN532 to Pin 6 (and cutting trace to Pin 2) you need to disconnect Pins 2 & 3 (bend the shield pins out or cut them) as the the Yun has SCL & SDA brought out twice on the board headers. So we have these signals on Pin 2/3 and 16/17. I use the latter pins and the shield works OK.