Arduino Nano - PN5180 Unsure of Operation

This is my first project and I have extremely limited knowledge of coding and Arduino in general. I took a semester of C++ and a semester of Fortran and bombed both. I've researched everything I could find but haven't found a solution.

That being said, my goal is to use an Arduino Nano clone (ATmega328P) with a PN5180 RFID reader to record/display card data and switch an LED from green to red or red to green. This would be to account for tool sign out and sign in at my place of employment where everyone has ISO15693 badges.

Unfortunately, I can't use my work computer due to security reasons so I have been using my wife's ancient Macbook. I was able to load the blink example and altered the illumination duration so I know the Nano is functional.

I've been trying to use ATrappmann's GItHub code (GitHub - ATrappmann/PN5180-Library: PN5180 library for Arduino) and have wired everything up exactly as the schematic shown on that page. I did however read that using the D13 pin on a Nano may not work the same as on an Uno. Additionally, I'm using a EPLZON EP-TXSO-108 level shifter - VA for the low voltage pins, VB for the high voltage pins, and GND and 0E for the grounds.

The code compiled and uploaded to the Nano successfully but unfortunately, opening the serial monitor immediately crashes the Macbook. I'm therefore unable to determine if the PN5180 is actually detecting a card or not. I attempted to copy some code from the blink example with hopes of illuminating the LED when a card is detected but was unsuccessful.

My question is, does anyone have a solution to keep the serial monitor from crashing? If not, any advice on what code to add to illuminate the LED when detecting a card?

I am not a MAC person but I highly recommend being sure everything is up to date on the MAC.

Unfortunately, her Mac is as up to date as it will go but many things struggle to function or don't funcion. Had to use her computer to email myself the code so I can post it here.

// NAME: PN5180-FeliCa.ino
//
// DESC: Example usage of the PN5180 library for the PN5180-NFC Module
//       from NXP Semiconductors.
//
// Copyright (c) 2018 by Andreas Trappmann. All rights reserved.
// Copyright (c) 2019 by Dirk Carstensen.
// Copyright (c) 2020 by CrazyRedMachine.
//
// This file is part of the PN5180 library for the Arduino environment.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public 
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// BEWARE: SPI with an Arduino to a PN5180 module has to be at a level of 3.3V
// use of logic-level converters from 5V->3.3V is absolutly neccessary
// on most Arduinos for all input pins of PN5180!
// If used with an ESP-32, there is no need for a logic-level converter, since
// it operates on 3.3V already.
//
// Arduino <-> Level Converter <-> PN5180 pin mapping:
// 5V             <-->             5V
// 3.3V           <-->             3.3V
// GND            <-->             GND
// 5V      <-> HV
// GND     <-> GND (HV)
//             LV              <-> 3.3V
//             GND (LV)        <-> GND
// SCLK,13 <-> HV1 - LV1       --> SCLK
// MISO,12        <---         <-- MISO
// MOSI,11 <-> HV3 - LV3       --> MOSI
// SS,10   <-> HV4 - LV4       --> NSS (=Not SS -> active LOW)
// BUSY,9         <---             BUSY
// Reset,7 <-> HV2 - LV2       --> RST
//
// ESP-32    <--> PN5180 pin mapping:
// 3.3V      <--> 3.3V
// GND       <--> GND
// SCLK, 18   --> SCLK
// MISO, 19  <--  MISO
// MOSI, 23   --> MOSI
// SS, 16     --> NSS (=Not SS -> active LOW)
// BUSY, 5   <--  BUSY
// Reset, 17  --> RST
//

/*
 * Pins on ICODE2 Reader Writer:
 *
 *   ICODE2   |     PN5180
 * pin  label | pin  I/O  name
 * 1    +5V
 * 2    +3,3V
 * 3    RST     10   I    RESET_N (low active)
 * 4    NSS     1    I    SPI NSS
 * 5    MOSI    3    I    SPI MOSI
 * 6    MISO    5    O    SPI MISO
 * 7    SCK     7    I    SPI Clock
 * 8    BUSY    8    O    Busy Signal
 * 9    GND     9  Supply VSS - Ground
 * 10   GPIO    38   O    GPO1 - Control for external DC/DC
 * 11   IRQ     39   O    IRQ
 * 12   AUX     40   O    AUX1 - Analog/Digital test signal
 * 13   REQ     2?  I/O   AUX2 - Analog test bus or download
 *
 */

//#define WRITE_ENABLED 1

#include <PN5180.h>
#include <PN5180FeliCa.h>

#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_ARCH_SAM)

#define PN5180_NSS  10
#define PN5180_BUSY 9
#define PN5180_RST  7

#elif defined(ARDUINO_ARCH_ESP32)

#define PN5180_NSS  16   // swapped with BUSY
#define PN5180_BUSY 5  // swapped with NSS
#define PN5180_RST  17

#else
#error Please define your pinout here!
#endif

PN5180FeliCa nfc(PN5180_NSS, PN5180_BUSY, PN5180_RST);

void setup() {
  Serial.begin(115200);
  Serial.println(F("=================================="));
  Serial.println(F("Uploaded: " __DATE__ " " __TIME__));
  Serial.println(F("PN5180 FeliCa Demo Sketch"));

  nfc.begin();

  Serial.println(F("----------------------------------"));
  Serial.println(F("PN5180 Hard-Reset..."));
  nfc.reset();

  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading product version..."));
  uint8_t productVersion[2];
  nfc.readEEprom(PRODUCT_VERSION, productVersion, sizeof(productVersion));
  Serial.print(F("Product version="));
  Serial.print(productVersion[1]);
  Serial.print(".");
  Serial.println(productVersion[0]);

  if (0xff == productVersion[1]) { // if product version 255, the initialization failed
    Serial.println(F("Initialization failed!?"));
    Serial.println(F("Press reset to restart..."));
    Serial.flush();
    exit(-1); // halt
  }
  
  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading firmware version..."));
  uint8_t firmwareVersion[2];
  nfc.readEEprom(FIRMWARE_VERSION, firmwareVersion, sizeof(firmwareVersion));
  Serial.print(F("Firmware version="));
  Serial.print(firmwareVersion[1]);
  Serial.print(".");
  Serial.println(firmwareVersion[0]);

  Serial.println(F("----------------------------------"));
  Serial.println(F("Reading EEPROM version..."));
  uint8_t eepromVersion[2];
  nfc.readEEprom(EEPROM_VERSION, eepromVersion, sizeof(eepromVersion));
  Serial.print(F("EEPROM version="));
  Serial.print(eepromVersion[1]);
  Serial.print(".");
  Serial.println(eepromVersion[0]);

  Serial.println(F("----------------------------------"));
  Serial.println(F("Enable RF field..."));
  nfc.setupRF();
}

uint32_t loopCnt = 0;
bool errorFlag = false;

void loop() {
  Serial.println(F("----------------------------------"));
  Serial.print(F("Loop #"));
  Serial.println(loopCnt++);
  #if defined(ARDUINO_ARCH_ESP32)  
    Serial.println("Free heap: " + String(ESP.getFreeHeap())); 
  #endif
  uint8_t uid[20];
  // check for FeliCa card
  nfc.reset();
  nfc.setupRF();
  uint8_t uidLength = nfc.readCardSerial(uid);
  if (uidLength > 0) {
    Serial.print(F("FeliCa card found, UID="));
    for (int i=0; i<uidLength; i++) {
      Serial.print(uid[i] < 0x10 ? " 0" : " ");
      Serial.print(uid[i], HEX);
    }
    Serial.println();
    Serial.println(F("----------------------------------"));
    delay(1000); 
    return;
  }
  
  // no card detected
  Serial.println(F("*** No card detected!"));
}

Nothing in the code you uploaded to the Nano, or any other code, could cause the serial monitor to crash.

What version of the IDE did you install? If you installed v2.x, I would recommend completely uninstalling it and try v1.8.19.

1 Like

I would recommend not using that. This type are intended for use with I2C bus and may not be fast enough for the SPI bus that you are using. This is because this type of voltage level shifter is designed to be bi-directional, which is unnecessary with SPI bus, and it has a very simple design which does not cope with the higher frequencies used by SPI.

So I recommend using voltage dividers (e.g. 10K + 22K) on all the Nano output pins that are connected to the RFID module. Connect the Nano input pins to the RFID module directly. Hopefully, the lower voltage will still be readable by the Nano.

I initially had the latest version installed but then downloaded and used v1.8.10 per suggestions I found in my research on the crashing serial monitor. Apparently, that issue isn't uncommon and while I found plenty of complaints on the subject, I never found a concrete answer on the solution. I'll try .19 and see if that's any better.

Oh bummer! So the one I'm currently won't work at all or will just be slow?

Also, can I use D13 as a pin or do I need to figure out how to reassign a different pin within the code?

Finally, can I just copy paste the blink example coding into the if statement where a card is recognized to see if the code is working without the use of the serial monitor function?

SPI bus on Uno runs at 8MHz by default, I think. I suspect that will be too high for these level shifters. They are designed for use at around 100KHz, which is 80x slower. I have attempted to use similar level shifters at 800KHz, and they worked, but not reliably.

The SPI bus can be slowed down, when used directly. But you are using the SPI bus through the PN5180 library, and the library is setting the frequency, or leaving it to the default. Hopefully the library allows a way to reduce the SPI frequency.

But I would try using the voltage dividers in place of the level shifter.

Alright, out of frustration, I purchased an Arduino Uno and different level shifter (I2C-LOGIC-MD-5PC-SCZW) (https://www.amazon.com/KIRO-SEEU-Converter-Bi-Directional-Compatible/dp/B09BM1JRBV/ref=sr_1_2_sspa?keywords=4+channel+level+shifter&qid=1700270767&sr=8-2-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1).

I assembled everything identical to the instructions but only get jibberish on the serial monitor (see below). Any ideas?

Was never able to get the serial monitor functional on the mac but had success on borrowing an ancient but functional laptop with windows. Also, the jibberish output was likely due to having the incorrect BAUD rate selected. Further advancements documented in this thread: PN5180 Example Woes - #12 by iwentflying

Will continue pursuing solutions in that thread so this one can be closed.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.