Skip to content

Commit e9dbe2d

Browse files
committed
Add low power example
1 parent b756ef2 commit e9dbe2d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

examples/pn532_low_power.py

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

0 commit comments

Comments
 (0)