ELECHOUSE · PN7160 MINI V1

PN7160 MINI V1 -- I2C

API reference summary

The core calls for connecting the module and detecting NFC tags, with links to the official library's detailed reference.

The full library API reference covers multiple controller and transport configurations. The settings below apply to PN7160 MINI V1 over I2C and the library 3.1.3 source ZIP, revision a9c0f71. For the standard repository example, start with Quick Start.

Contents
  1. Constructor and transport
  2. Initialization
  3. Tag detection
  4. Identifiers
  5. Basic sketch
  6. Further APIs

1. Constructor and transport

#include <Wire.h>
#include <Electroniccats_PN7150.h>

Electroniccats_PN7150 nfc(4, 5, 0x28, PN7160);
//                      IRQ, VEN, address, device

The library's class name is Electroniccats_PN7150, including when used with PN7160. Pass the explicit PN7160 selector; do not omit the fourth constructor argument.

nfc.setI2CPins(8, 9) selects SDA8 and SCL9 on ESP32-S3. Call it before connectNCI(). The address is 7-bit; the factory-open ADR0 and ADR1 pads select 0x28.

2. Initialization

CallPurpose and orderReturn behavior in 3.1.3
setPn7160FixedVbat3V3(bool)Select the module supply preset before applying settings: true for 3.3 V, false for 5.0 V.No return value.
connectNCI()Initialize the bus, reset the controller and establish NCI communication.0 = success; 1 = failure.
configureSettings()Apply settings after connecting and selecting the supply preset.0 = success; 1 = failure.
configMode()Configure the selected operating mode; reader/writer is the normal starting mode.0 = success; 1 = failure.
startDiscovery()Begin NFC discovery after mode configuration.0 = success; 1 = failure.
begin()Shortcut that calls the four initialization stages above. Set the supply preset before using it.0 = success; 1 = failure.

Set Wire.setClock(400000UL) after connectNCI() or begin() succeeds. These methods initialize the I2C bus. Set the clock again if your recovery code closes and restarts the bus.

Library 3.1.3: use the no-argument settings callUse configureSettings(). Do not use the custom-UID overload configureSettings(uid, length) with this version: it has a known buffer-handling issue that can read beyond the provided UID data. The normal initialization path shown here uses the no-argument call.

The software power preset does not detect the applied voltage. VCC supports 3.3–5.5 V, while the module's host signals use 3.3 V logic. See supply configuration before changing power sources.

3. Tag detection and recovery

Call or objectUseImportant behavior
isTagDetected(timeoutMs)Wait for tag activation, for example isTagDetected(250).true means a tag was detected; false does not itself distinguish timeout from a communication error.
remoteDeviceRead the detected technology, protocol and identifier.Access only after successful detection; use the correct accessor for that technology.
waitForTagRemoval()Perform presence checks until the tag is no longer present.Blocking operation; no return value.
reset()Reconfigure and restart the discovery flow.true = success; false = failure. This differs from the initialization return convention.
stopDiscovery()Request that discovery stops.Version 3.1.3 returns 0 without reporting controller acknowledgement; do not treat this return as proof of a completed state change.
getFirmwareVersion()Read the firmware information retained from initialization.Useful for application logs and support requests.
closeCommunication()Close the communication path before shutdown or reconfiguration.Reinitialize the bus and controller before resuming NFC operations.

If discovery recovery fails, stop tag operations, verify the supply and bus, and perform a controller reset through VEN before reconnecting. Use bounded retries rather than an uncontrolled reset loop.

4. Read the correct identifier length

Detected technologyData accessorLength
NFC-AremoteDevice.getNFCID()remoteDevice.getNFCIDLen()
NFC-V / ISO15693remoteDevice.getID()8 bytes, after checking that the activated technology is NFC-V.

These accessors return pointers. Do not use sizeof(pointer) as the identifier length. In library 3.1.3, the NFC-V display branch in DetectTags uses this pattern, so its printed identifier may be incomplete. For a working copy of that example, print all eight NFC-V identifier bytes and keep the byte order consistent with your application.

if (nfc.remoteDevice.getModeTech() == nfc.tech.PASSIVE_NFCV) {
  const unsigned char* id = nfc.remoteDevice.getID();
  for (uint8_t i = 0; i < 8; ++i) {
    if (id[i] < 0x10) Serial.print('0');
    Serial.print(id[i], HEX);
    if (i < 7) Serial.print(':');
  }
  Serial.println();
}

The snippet prints the identifier in the order returned by the library. A displayed identifier is not an authentication result or a complete read of the card's protected data.

5. Basic ESP32-S3 sketch

This basic NFC-A identifier example uses SDA8, SCL9, IRQ4, VEN5, address 0x28 and a 3.3 V module supply. For 5.0 V VCC, change the preset argument to false; the GPIOs remain 3.3 V logic.

#include <Wire.h>
#include <Electroniccats_PN7150.h>

Electroniccats_PN7150 nfc(4, 5, 0x28, PN7160);
bool readerReady = false;

void setup() {
  Serial.begin(115200);
  delay(1000);
  nfc.setI2CPins(8, 9);
  nfc.setPn7160FixedVbat3V3(true);  // Module VCC = 3.3 V

  if (nfc.connectNCI()) {
    Serial.println("NCI connection failed");
    return;
  }
  Wire.setClock(400000UL);

  if (nfc.configureSettings() || nfc.configMode() || nfc.startDiscovery()) {
    Serial.println("NFC initialization failed");
    return;
  }
  readerReady = true;
  Serial.println("Present an NFC-A tag");
}

void loop() {
  if (!readerReady) {
    delay(100);
    return;
  }
  if (!nfc.isTagDetected(250)) return;

  if (nfc.remoteDevice.getModeTech() == nfc.tech.PASSIVE_NFCA) {
    const unsigned char* id = nfc.remoteDevice.getNFCID();
    const uint8_t length = nfc.remoteDevice.getNFCIDLen();
    Serial.print("NFC-A ID: ");
    for (uint8_t i = 0; i < length; ++i) {
      if (id[i] < 0x10) Serial.print('0');
      Serial.print(id[i], HEX);
      if (i + 1 < length) Serial.print(':');
    }
    Serial.println();
  }

  nfc.waitForTagRemoval();
  readerReady = nfc.reset();
  if (!readerReady) Serial.println("Discovery restart failed");
}

If initialization or discovery restart fails, this sketch stops NFC activity. Correct the wiring or supply issue and restart the host; add application-specific recovery and user feedback before deployment.

6. Further APIs

For NDEF and card memory operations, follow the corresponding repository example and the full API reference. Use writable test cards for write operations, and check authentication, memory bounds and card-specific commands.

Low-level readerTagCmd() does not take a reply-buffer capacity argument. Allocate and validate buffers for the intended command and response; do not pass unchecked application data to the low-level interface.