adafruit_pn532

This module will let you communicate with a PN532 RFID/NFC shield or breakout using I2C, SPI or UART.

  • Author(s): Original Raspberry Pi code by Tony DiCola, CircuitPython by ladyada

Implementation Notes

Hardware:

Software and Dependencies:

exception adafruit_pn532.adafruit_pn532.BusyError

Base class for exceptions in this module.

class adafruit_pn532.adafruit_pn532.PN532(*, debug=False, reset=None)

PN532 driver base, must be extended for I2C/SPI/UART interfacing

SAM_configuration()

Configure the PN532 to read MiFare cards.

call_function(command, response_length=0, params=[], timeout=1)

Send specified command to the PN532 and expect up to response_length bytes back in a response. Note that less than the expected bytes might be returned! Params can optionally specify an array of bytes to send as parameters to the function call. Will wait up to timeout seconds for a response and return a bytearray of response bytes, or None if no response is available within the timeout.

get_firmware_version()

Call PN532 GetFirmwareVersion function and return a tuple with the IC, Ver, Rev, and Support values.

mifare_classic_authenticate_block(uid, block_number, key_number, key)

Authenticate specified block number for a MiFare classic card. Uid should be a byte array with the UID of the card, block number should be the block to authenticate, key number should be the key type (like MIFARE_CMD_AUTH_A or MIFARE_CMD_AUTH_B), and key should be a byte array with the key data. Returns True if the block was authenticated, or False if not authenticated.

mifare_classic_read_block(block_number)

Read a block of data from the card. Block number should be the block to read. If the block is successfully read a bytearray of length 16 with data starting at the specified block will be returned. If the block is not read then None will be returned.

mifare_classic_write_block(block_number, data)

Write a block of data to the card. Block number should be the block to write and data should be a byte array of length 16 with the data to write. If the data is successfully written then True is returned, otherwise False is returned.

ntag2xx_read_block(block_number)

Read a block of data from the card. Block number should be the block to read. If the block is successfully read a bytearray of length 16 with data starting at the specified block will be returned. If the block is not read then None will be returned.

ntag2xx_write_block(block_number, data)

Write a block of data to the card. Block number should be the block to write and data should be a byte array of length 4 with the data to write. If the data is successfully written then True is returned, otherwise False is returned.

read_passive_target(card_baud=<sphinx.ext.autodoc.importer._MockObject object>, timeout=1)

Wait for a MiFare card to be available and return its UID when found. Will wait up to timeout seconds and return None if no card is found, otherwise a bytearray with the UID of the found card is returned.

adafruit_pn532.i2c

This module will let you communicate with a PN532 RFID/NFC shield or breakout using I2C.

  • Author(s): Original Raspberry Pi code by Tony DiCola, CircuitPython by ladyada,
    refactor by Carter Nelson
class adafruit_pn532.i2c.PN532_I2C(i2c, *, irq=None, reset=None, req=None, debug=False)

Driver for the PN532 connected over I2C.

adafruit_pn532.spi

This module will let you communicate with a PN532 RFID/NFC shield or breakout using SPI.

  • Author(s): Original Raspberry Pi code by Tony DiCola, CircuitPython by ladyada,
    refactor by Carter Nelson
class adafruit_pn532.spi.PN532_SPI(spi, cs_pin, *, irq=None, reset=None, debug=False)

Driver for the PN532 connected over SPI. Pass in a hardware or bitbang SPI device & chip select digitalInOut pin. Optional IRQ pin (not used), reset pin and debugging output.

adafruit_pn532.spi.reverse_bit(num)

Turn an LSB byte to an MSB byte, and vice versa. Used for SPI as it is LSB for the PN532, but 99% of SPI implementations are MSB only!

adafruit_pn532.uart

This module will let you communicate with a PN532 RFID/NFC shield or breakout using UART.

  • Author(s): Original Raspberry Pi code by Tony DiCola, CircuitPython by ladyada,
    refactor by Carter Nelson
class adafruit_pn532.uart.PN532_UART(uart, *, irq=None, reset=None, debug=False)

Driver for the PN532 connected over Serial UART