Simple test

Ensure your device works with this simple test.

examples/pn532_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example shows connecting to the PN532 with I2C (requires clock
 6stretching support), SPI, or UART. SPI is best, it uses the most pins but
 7is the most reliable and universally supported.
 8After initialization, try waving various 13.56MHz RFID cards over it!
 9"""
10
11import board
12import busio
13from digitalio import DigitalInOut
14
15#
16# NOTE: pick the import that matches the interface being used
17#
18from adafruit_pn532.i2c import PN532_I2C
19
20# from adafruit_pn532.spi import PN532_SPI
21# from adafruit_pn532.uart import PN532_UART
22
23# I2C connection:
24i2c = busio.I2C(board.SCL, board.SDA)
25
26# Non-hardware
27# pn532 = PN532_I2C(i2c, debug=False)
28
29# With I2C, we recommend connecting RSTPD_N (reset) to a digital pin for manual
30# harware reset
31reset_pin = DigitalInOut(board.D6)
32# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
33# wakeup! this means we don't need to do the I2C clock-stretch thing
34req_pin = DigitalInOut(board.D12)
35pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)
36
37# SPI connection:
38# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
39# cs_pin = DigitalInOut(board.D5)
40# pn532 = PN532_SPI(spi, cs_pin, debug=False)
41
42# UART connection
43# uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.1)
44# pn532 = PN532_UART(uart, debug=False)
45
46ic, ver, rev, support = pn532.firmware_version
47print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
48
49# Configure PN532 to communicate with MiFare cards
50pn532.SAM_configuration()
51
52print("Waiting for RFID/NFC card...")
53while True:
54    # Check if a card is available to read
55    uid = pn532.read_passive_target(timeout=0.5)
56    print(".", end="")
57    # Try again if no card is available.
58    if uid is None:
59        continue
60    print("Found card with UID:", [hex(i) for i in uid])