Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

CircuitPython & RFID w/PN532
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CircuitPython & RFID w/PN532

by zKyd on Sun Apr 18, 2021 10:24 pm

I could use some guidance on understanding the limits of the PN532 RFID controller.

I'm experimenting with:
- PN532 NFC/RFID controller breakout board - v1.6 https://www.adafruit.com/product/364
- connected via SPI to a Qt Py https://www.adafruit.com/product/4600
- with some 13.56MHz RFID/NFC Clear Tag - Classic 1K https://www.adafruit.com/product/361
- and 13.56MHz RFID/NFC Card - Classic 1K https://www.adafruit.com/product/359

My understanding is that the larger the antenna on the tag, the further the distance you can read it. In my tests, the Card can be read with an unobstructed path close to 95 mm, while the Coin tags can only reach about 55mm.

I'm attempting to read multiple tags when they're within range. It seems the PN532 can easily detect 2 Coin tags using the sample code:
Code: Select all | TOGGLE FULL SIZE
import board
import busio
from digitalio import DigitalInOut
from adafruit_pn532.spi import PN532_SPI
import neopixel

# SPI connection:
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs_pin = DigitalInOut(board.D5)
pn532 = PN532_SPI(spi, cs_pin, debug=False)

ic, ver, rev, support = pn532.firmware_version
print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))

# Configure PN532 to communicate with MiFare cards
pn532.SAM_configuration()

pixels = neopixel.NeoPixel(board.A1, 1, brightness=0.3, auto_write=True)

print("Waiting for RFID/NFC card...")
while True:
    # Check if a card is available to read
    uid = pn532.read_passive_target(timeout=0.5)
    print(".", end="")
    # Try again if no card is available.
    if uid is None:
        pixels.fill((0,0,0))
        continue
    if uid == bytearray(b'...'):
        print('red')
        pixels.fill((255,0,0))
    elif uid == bytearray(b'...'):
        print('green')
        pixels.fill((0,255,0))
    elif uid == bytearray(b'...'):
        print('blue')
        pixels.fill((0,0,255))
    elif uid == bytearray(b'...'):
        print('white')
        pixels.fill((128,128,128))
    else:
        print("Found card with UID:", [hex(i) for i in uid], uid)


With the NeoPixel connected, it rapidly switches color between the two tags. However, if I add a third Coin tag within range, it seems the PN532 has trouble detecting all three.

At the max range (55mm), sometimes it will just continue detecting the first two Coin tags that were within range, other times it will not be able to detect **any** tags within range.

Lowering the range down to 35mm will resolve the problem of not detecting **any** Coin tags when there are >2 within range, but it still seems to only bounce between two of them, ignoring the last one to come within range.

My understanding of RFID is that the antenna on the controller is providing current to the tags, such that they can be "activated" and read. I'm assuming that because there are >2 tags, this antenna may not have enough current to "activate" more than 2 in a short span of time. If that's a limitation, is there anyway to increase the power from this antenna? I'm currently powering it via 3.3V, but I noticed a 5V pin on the PN532 controller. Is it reasonable to think attaching a 5V power supply to the PN532 would increase the number of tags the antenna could read within its range?

Or does anyone have suggestions on how to detect multiple tags that are within range of the antenna? I don't need to read all of them at once, but it'd be nice to have some deterministic way to iterate through all tags within range through subsequent read attempts.

zKyd
 
Posts: 4
Joined: Sat Aug 08, 2020 6:59 pm

Re: CircuitPython & RFID w/PN532

by mikeysklar on Tue Apr 20, 2021 1:53 pm

Two cards at once is a limit of the ISO standard for the tags.

viewtopic.php?f=31&t=35050&hilit=MULTIPLE+tags
viewtopic.php?f=31&t=53058

Using 5v won't help with the power situation or the third tag.

There are some tricks in the library you can explore for dealing with pre-registerd or recognized tags that might help.

viewtopic.php?f=19&t=78464

mikeysklar
 
Posts: 4207
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.