Skip to content

Using two RFID readers (PN532) on esp32. #9072

@thaianramalho

Description

@thaianramalho

Board

ESP32 DOIT DEVKIT V1

Device Description

My esp32 is connected to a relay, an Ethernet adapter, Buzzer and PN532 RFID Reader.

Hardware Configuration

The Pn532 reader is connected to the HSU.

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

40mhz

PSRAM enabled

yes

Upload speed

9600

Description

I need to connect two RFID readers to my esp32. Currently one reader is using the HSU input. When trying to configure a second reader to I2C, the readers conflict and only one works. Generally, I2C. I would like to know how I can make this work.

Sketch

#include <Wire.h>
#include <Adafruit_PN532.h>

#define SDA_PIN 21
#define SCL_PIN 22

#define SDA_HSU_PIN 17
#define SCL_HSU_PIN 16

Adafruit_PN532 nfcI2C(SDA_PIN, SCL_PIN);

Adafruit_PN532 nfcHSU(SDA_HSU_PIN, SCL_HSU_PIN);

void setup(void) {
  Serial.begin(115200);
  delay(1000);

  Serial.println("Configurando leitor I2C...");
  nfcI2C.begin();
  nfcI2C.SAMConfig();

  Serial.println("Configurando leitor HSU...");
  nfcHSU.begin();
  nfcHSU.SAMConfig();
}

void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  uint8_t uidLength;

  success = nfcI2C.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {
    Serial.println("Tag found at I2C!");
    printUID(uid, uidLength);
  }

  success = nfcHSU.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {
    Serial.println("Tag found at HSU!");
    printUID(uid, uidLength);
  }

  delay(1000);
}

void printUID(uint8_t *uid, uint8_t uidLength) {
  Serial.print("UID: ");
  for (uint8_t i = 0; i < uidLength; i++) {
    Serial.print(" 0x");
    if (uid[i] < 0x10) {
      Serial.print("0");
    }
    Serial.print(uid[i], HEX);
  }
  Serial.println("");
}

Debug Message

Dont have.

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions