Giter VIP home page Giter VIP logo

adafruit_circuitpython_pn532's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

CircuitPython driver for the PN532 NFC/RFID Breakout and PN532 NFC/RFID Shield

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-pn532

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-pn532

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-pn532

Usage Example

Check examples/pn532_simpletest.py for usage example

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_pn532's People

Contributors

basil-huber avatar brennen avatar caternuson avatar dhalbert avatar dunkmann00 avatar evaherrada avatar fcrisafulli-dev avatar foamyguy avatar jepler avatar jerryneedell avatar jposada202020 avatar kattni avatar keiththeee avatar ladyada avatar makermelissa avatar sommersoft avatar symm avatar tannewt avatar tcfranks avatar tekktrik avatar tgikal avatar the-infinity avatar thekitty avatar xon235 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_pn532's Issues

SPI read_passive_target timeout not working correctly

Hi,

When in SPI mode calling read_passive_target with a timeout, a NFC tag is only detect at the very beginning of the poll. This is not the case with i2c which detects tags through all the duration of the timeout.

NTAG 424

Hi,

are there any plans to add support for ntag 424?
would be really nice!

Thanks!

'module' object has no attribute implementation

trying to run the pn532-simpletest.py file and getting the error

  File "pn532_simpletest.py", line 8, in <module>
    import board
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_Blinka-1.2.8-py2.7.egg/board.py", line 32, in <module>
    from adafruit_blinka.agnostic import board_id, detector
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_Blinka-1.2.8-py2.7.egg/adafruit_blinka/agnostic/__init__.py", line 21, in <module>
    implementation = sys.implementation.name
AttributeError: 'module' object has no attribute 'implementation'```

any ideas?

Could the driver be changed to support passing I2C address as a parameter?

Often more than one PN532 needs to be connected to one I2C bus. The chip can be set to different address than the default x24, but at present this driver does not support it, rather it is set as a constant in the code.
I can make my own version, but I believe this change would benefit others too. E.g.
NFC = PN532_I2C(SCL, SDA, ADDR)
ADDR could be an optional parameter, and if left out the default x24 will be set.

using uart raspi "unicode strings are not supported"

i am trying to read nfc using a raspi 4b i have pn532 connected through uart

"""
This example shows connecting to the PN532 with I2C (requires clock
stretching support), SPI, or UART. SPI is best, it uses the most pins but
is the most reliable and universally supported.
After initialization, try waving various 13.56MHz RFID cards over it!
"""

import board
import busio
from digitalio import DigitalInOut
import serial
#
# NOTE: pick the import that matches the interface being used
#
#from adafruit_pn532.i2c import PN532_I2C

# from adafruit_pn532.spi import PN532_SPI
from adafruit_pn532.uart import PN532_UART

# I2C connection:
#i2c = busio.I2C(board.SCL, board.SDA)

# Non-hardware
# pn532 = PN532_I2C(i2c, debug=False)

# With I2C, we recommend connecting RSTPD_N (reset) to a digital pin for manual
# harware reset
#reset_pin = DigitalInOut(board.D6)
# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
# wakeup! this means we don't need to do the I2C clock-stretch thing
#req_pin = DigitalInOut(board.D12)
#pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)

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

# UART connection
# uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=100)

uart = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=10)
pn532 = PN532_UART(uart, 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()

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:
        continue
    print("Found card with UID:", [hex(i) for i in uid])

i keep getting this error
TypeError: unicode strings are not supported, please encode to bytes: 'UU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

bytearray error in example readwrite_ntag2xx.py

the example readwrite_ntag2xx.py fails with:

Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-beta.0-15-g6be4b07e1 on 2019-01-24; Adafruit Feather nRF52840 Express with nRF52840
>>> 
>>> import readwrite_ntag2xx
Found PN532 with firmware version: 1.6
Waiting for RFID/NFC card to write to!
.
.
.

Found card with UID: ['0x53', '0x15', '0x8a', '0xb2', '0x0', '0x1a', '0x80']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "readwrite_ntag2xx.py", line 82, in <module>
NotImplementedError: array/bytes required on right side
>>> 

replacing line 82 with

jerryneedell@Ubuntu-Macmini:~/projects/feather_nrf52840$ diff ntag203.py readwrite_ntag2xx.py 
82c82
< data[0:4] = b'\xFE\xED\xBE\xEF'
---
> data[0:4] = [0xFE, 0xED, 0xBE, 0xEF]

works as expected

Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-beta.0-15-g6be4b07e1 on 2019-01-24; Adafruit Feather nRF52840 Express with nRF52840
>>> 
>>> import ntag203
Found PN532 with firmware version: 1.6
Waiting for RFID/NFC card to write to!
.
.
.

Found card with UID: ['0x53', '0x15', '0x8a', '0xb2', '0x0', '0x1a', '0x80']
Wrote to block 6, now trying to read that data: ['0xfe', '0xed', '0xbe', '0xef']
>>> 

Response checksum did not match expected value

Hello!
I am trying to use pn532_simpletest.py for the pn532 module with raspberry pi 3 B+. I am using python 3.5.3 and when you run the sample code and reads some cards, it would raise an RuntimeError like this

File "pn532_simpletest.py", line 50, in <module>
uid = pn532.read_passive_target(timeout=0.5)
File "/usr/local/lib/python3.5/dist-packages/adafruit_circuitpython_pn532-2.0.4.dev0+g915b2e2.d20190119-py3.5.egg/adafruit_pn532/adafruit_pn532.py", line 349, in read_passive_target
File "/usr/local/lib/python3.5/dist-packages/adafruit_circuitpython_pn532-2.0.4.dev0+g915b2e2.d20190119-py3.5.egg/adafruit_pn532/adafruit_pn532.py", line 313, in call_function
File "/usr/local/lib/python3.5/dist-packages/adafruit_circuitpython_pn532-2.0.4.dev0+g915b2e2.d20190119-py3.5.egg/adafruit_pn532/adafruit_pn532.py", line 281, in _read_frame
RuntimeError: ('Response checksum did not match expected value: ', 219)

I read the issues from the Adafruid_Python_PN532(The one that is archived now) and found out that another guy was having the same issue. But the comment says that the issue is solved in this new repo Adafruit_CircuitPython_PN532.

Right now I am working on MiFare Plus cards with the PN532, and some cards do work but some don't and will raise the error above. I am not sure why... Can anyone tell me what's wrong?

Additional RTD documentation needed

This library is missing Sphinx docstring documentation for ReadTheDocs for the functions contained within! See other libraries for examples. Here's a basic example of what is needed in the docstring for each function:

...

def some_function(a: float, b: int) -> Tuple[str, str, str]:
    """This is an explanation of the function

    :param float a: An explanation of parameter a
    :param int b: An explanation of parameter b
    """

...

Authenticate with card key

I want to copy other tag which uses key protection.
I receive this error while trying to authenticate

Traceback (most recent call last):
  File "/home/pi/nfc/rpi-nfc/write.py", line 67, in <module>
    o = pn532.mifare_classic_authenticate_block(uid, 14, MIFARE_CMD_AUTH_B, key)
  File "/home/pi/.local/lib/python3.5/site-packages/adafruit_pn532/adafruit_pn532.py", line 383, in mifare_classic_authenticate_block
    response_length=1)
  File "/home/pi/.local/lib/python3.5/site-packages/adafruit_pn532/adafruit_pn532.py", line 316, in call_function
    raise RuntimeError('Received unexpected command response!')
RuntimeError: Received unexpected command response!

Main goal is to first read whole tag that is encrypted using that key and then copy its data onto another and block it with same key. I did it on the mobile app and now want to recreate it in python script.

Using serial with the FTDI cable causes the library to hang when a card is read

Hello! While im sure there must be a way to do this, I bought the PN532 breakout and an FTDI cable thinking setup would be a breeze. Two days of tinkering later, im pulling my hair (in part due to my inexperience).

The LibNFC part of the official guide is outdated, and I understand why it is. But it seems like this may be the only way to "easily" use the FTDI cable (looking at that project's issue log, im not the only one with issues, and LibNFC seems like it has been abandoned). I was not able to configure it on my raspberry pi to use ttyUSB0, and it no longer supports autoscan. The version used in the guide seems to no longer be compatible with newer OS versions.

To my untrained eye, I think it may not be all too difficult to adapt the simpletest example to talk over the FTDI serial port. My hope is that this would be relatively easy and thus added as an official example without burden, as well as in documentation so that people buying this reader would find it easier than I did.

Failed to detect the PN532 - Rasp Pi Zero with PN532 Shield v1.3

I'm using the following:

Shield PN532 - v1.3
Rasp Pi Zero - v1.3

I want to use SPI.

PI Pin# 4 (5v) to 532 5V
PI Pin# 25 (Gnd) to 532 Gnd (There are 2? Does it matter?)
PI Pin# 19 (MOSI) to 532 MOSI
PI Pin# 21 (MISO) to 532 MISO
PI Pin# 23 (SCLK) to 532 SCK
PI Pin# 24 (CE0) to 532 SS

I also soldered the SEL0 and SEL1 "closed"? I assume that means connect them together? Or does that mean open? I couldn't tell as the nomenclature used doesn't distinguish and I dont have enough knowledge.

These is what I gathered from all the wire diagrams and tutorials, although, its quite confusing with each different type of board and version

The error I get is "Failed to detect the PN532"

Reading Encrypted card error

Hi,

Having a bit of a problem reading the encrypted data on a MiFare card, wondering if anyone can help. Using a Raspberry Pi with the PN532 Breakout, and the Adafruit 359 Classic 1K card that came with it.

I'm just attempting to use the sample pn532_readwrite_mifare.py. It's able to read the UID of the card just fine, but returns a error with a "Received Unexpected Command Response!" error every time it runs once it gets to the mifare_classic_authenticate_block() function. Tried a few different blocks, but still no luck.

I've attached a screenshot with the error, and would be grateful for any help with it.
Thanks!

2023-01-23-160509

More than one card detected! with no cards on reader

With an itead pn532 reader connected to a Raspberry Pi via SPI and the default example script from https://learn.adafruit.com/adafruit-pn532-rfid-nfc/python-circuitpython configured for SPI, running the example would result in the error More than one card detected! being thrown.

Turning on debug, I see that reading from this device w/ no cards results in:
Read frame: ['0x0', '0x0', '0xff', '0x3', '0xfd', '0xd5', '0x4b', '0x0', '0xe0', '0x0', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa']

In adafruit_pn532.py, the error is triggered by:

        if response is None:
            return None
        # Check only 1 card with up to a 7 byte UID is present.
        if response[0] != 0x01:
            raise RuntimeError("More than one card detected!")

Changing the first if to:

        if response is None or response[0] == 0x00:

appears to resolve the issue - adafruit_pn532.py no longer erroneously detects a response of '0' as > 1 card present.

incorrect import path for examples

Looks like examples are still using development environment setup?

https://github.com/adafruit/Adafruit_CircuitPython_PN532/blob/master/examples/pn532_simpletest.py#L11
https://github.com/adafruit/Adafruit_CircuitPython_PN532/blob/master/examples/readwrite_ntag2xx.py#L31

Adafruit CircuitPython 3.0.1 on 2018-08-21; Adafruit Metro M4 Express with samd51j19
>>> from Adafruit_Circuitpython_PN532 import adafruit_pn532
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'Adafruit_Circuitpython_PN532'
>>> 

I2C delays slowing down code

I noticed while trying to read tags using I2C that it seemed to be taking longer than it used to. After a fair bit of testing trying to track it down, I think it has to do with some of the delays that are present in the library.

Specifically here (Line 74):

self._req.value = False
time.sleep(0.1)
self._req.value = True
time.sleep(0.5)

and while this isn't as much of a problem, here as well (Line 105):

if self.debug:
print("Reading: ", [hex(i) for i in frame[1:]])
else:
time.sleep(0.1)

Module not found

After

pip install adafruit-circuitpython-pn532

installing version 2 I get a Module not found error with the example file.

Example using interrupt

I'm trying to use this lib with interrupts but so far I've struggled to figure it out and I haven't found any examples. I see various other issues mentioning the need for the interrupt method vs. polling, but still no solution is shown.

Could you please add an example of how to use the PN532 with interrupts, such that a function is executed when a card is detected, not detected anymore (not sure if this case is supported).

I'm especially curious how to implement this in best practice Circuitpython (use countio/keypad for interrupt?).

Thx!

pn532_simpletest.py - UART - busio.UART not supported on this platform. Please use pyserial instead.

Hi

I´ve intalled the libs and setup all devices but when I debug the code I get an error

ssh://pi@sitelog-raspberrypi-1:22/usr/bin/python3 -u /home/pi/.pycharm_helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 0.0.0.0 --port 42697 --file /home/pi/python/slac-client/tests_sitelog/rfidreader_new/rfid_uart.py
pydev debugger: process 1226 is connecting

Connected to pydev debugger (build 183.5153.39)
Traceback (most recent call last):
  File "/home/pi/.pycharm_helpers/pydev/pydevd.py", line 1741, in <module>
    main()
  File "/home/pi/.pycharm_helpers/pydev/pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/pi/.pycharm_helpers/pydev/pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/pi/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/pi/python/slac-client/tests_sitelog/rfidreader_new/rfid_uart.py", line 38, in <module>
    uart = busio.UART(board.TXD, board.RXD, baudrate=115200, timeout=100)
  File "/home/pi/.local/lib/python3.5/site-packages/busio.py", line 158, in __init__
    from machine import UART as _UART
ImportError: No module named 'machine'

Process finished with exit code 1

The code is from the file examples/pn532_simpletest.py

"""
This example shows connecting to the PN532 with I2C (requires clock
stretching support), SPI, or UART. SPI is best, it uses the most pins but
is the most reliable and universally supported.
After initialization, try waving various 13.56MHz RFID cards over it!
"""

import board
import busio
from digitalio import DigitalInOut
#
# NOTE: pick the import that matches the interface being used
#
# from adafruit_pn532.i2c import PN532_I2C
# from adafruit_pn532.spi import PN532_SPI
from adafruit_pn532.uart import PN532_UART

# I2C connection:
# i2c = busio.I2C(board.SCL, board.SDA)

# Non-hardware
# pn532 = PN532_I2C(i2c, debug=False)

# With I2C, we recommend connecting RSTPD_N (reset) to a digital pin for manual
# harware reset
# reset_pin = DigitalInOut(board.D6)
# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
# wakeup! this means we don't need to do the I2C clock-stretch thing
# req_pin = DigitalInOut(board.D12)
# pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)

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

# UART connection
uart = busio.UART(board.TXD, board.RXD, baudrate=115200, timeout=100)
pn532 = PN532_UART(uart, debug=False)

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

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

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="", flush=True)
    # Try again if no card is available.
    if uid is None:
        continue
    print('Found card with UID:', [hex(i) for i in uid])

The jumpers were set correctly. (No jumpers for UART)

My setup:

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_pn532/adafruit_pn532.py:154
  • adafruit_pn532/adafruit_pn532.py:163
  • adafruit_pn532/adafruit_pn532.py:168
  • adafruit_pn532/adafruit_pn532.py:173
  • adafruit_pn532/adafruit_pn532.py:194
  • adafruit_pn532/adafruit_pn532.py:224
  • adafruit_pn532/adafruit_pn532.py:259
  • adafruit_pn532/adafruit_pn532.py:275
  • adafruit_pn532/adafruit_pn532.py:303
  • adafruit_pn532/adafruit_pn532.py:355
  • adafruit_pn532/adafruit_pn532.py:367
  • adafruit_pn532/adafruit_pn532.py:383
  • adafruit_pn532/adafruit_pn532.py:407
  • adafruit_pn532/adafruit_pn532.py:432
  • adafruit_pn532/adafruit_pn532.py:450
  • adafruit_pn532/adafruit_pn532.py:471
  • adafruit_pn532/adafruit_pn532.py:490
  • adafruit_pn532/uart.py:28
  • adafruit_pn532/uart.py:47
  • adafruit_pn532/uart.py:57
  • adafruit_pn532/uart.py:66
  • adafruit_pn532/spi.py:31
  • adafruit_pn532/spi.py:47
  • adafruit_pn532/spi.py:64
  • adafruit_pn532/spi.py:80
  • adafruit_pn532/spi.py:95
  • adafruit_pn532/i2c.py:32
  • adafruit_pn532/i2c.py:56
  • adafruit_pn532/i2c.py:72
  • adafruit_pn532/i2c.py:85

ntag2xx_read_block() should return None on failure

A Discord user reported this error: https://discord.com/channels/327254708534116352/537365702651150357/942511372028223538

    cardReadValues = (pn532.ntag2xx_read_block(6))
    cardRead = int.from_bytes((cardReadValues), "big")
    print("Reading! This is Card", (cardRead), "!")
    audio.play(sounds[cardRead])
    
    while audio.playing:
        pass
    print("stopped")

Here's the bit of code, and here's the error

Traceback (most recent call last):
  File "code.py", line 73, in <module>
  File "/lib/adafruit_pn532/adafruit_pn532.py", line 497, in ntag2xx_read_block
TypeError: 'NoneType' object isn't subscriptable

The problem was the card was being removed too quickly, but the function should return none rather than throw an error according to the doctoring:

    def ntag2xx_read_block(self, 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.
``` at 
https://github.com/adafruit/Adafruit_CircuitPython_PN532/blob/main/adafruit_pn532/adafruit_pn532.py#L490

If it returned None, the user could test for None before using the result.

Faster way to detect when a card disconnects

Is ther a faster way to detect when a card disconnects other than continuously calling pn532.read_passive_target() until it times out?
_COMMAND_INLISTPASSIVETARGET can be rather slow to respond (sometimes >100ms).

I tried this:
pn532.call_function(_COMMAND_GETGENERALSTATUS, 8)

It reports the number of targets connected, but it doesn't update until I run some other target command.
Does someone know if there's a different command for this?

Cannot found mifare card using UART

I'm running the example code on Windows 10 (python 3.8, pyserial 3.5), my PN532 can be found, but it's stuck while waiting for a card, my PN532 and card work fine by using other mifare tools

Add support to 'listen' for tags

I found that when using the library as it is, it is not possible to avoid a slight delay while trying to read tags, due to read_passive_target needing to have a timeout. This is problematic if you are also trying to simultaneously perform another task, like updating neopixels. This delay prevents the neopixels from looking as smooth as they otherwise could.

I worked on tweaking the library slightly to allow, if needed, the ability to separate sending the listen command to the PN532, from reading a tag. None of the other functions are affected and the read_passive_target function is also still available and would still be the 'normal' way to read a tag. This additional functionality could be an option if you wanted a way to listen for a tag, while also avoiding any delay.

The idea would be:

  1. Start listening
  2. Check if a tag is present (by checking IRQ for instance)
  3. If no tag is found, perform other tasks
  4. Repeat 2 & 3 until a tag is found
  5. Read the UID of the tag

It would be similar to how it is currently done, but since checking IRQ is quite quick, you avoid any delay. This would allow other tasks to be run, basically uninterrupted while you wait for a tag.

Any questions or suggestions are welcome! Let me know what you think!

get_passive_target is asking for more data from the UART than is provided, so we are blocking

greetings everyone!

I am presenting a card and the following line in the _read_data function (line #82 in uart.py):
frame = self._uart.read(count)
is never returning as we've [presumably] told it to expect more data than is available (being returned from PN532).

After some digging, I found the following in line #419 of adafruit_pn532.py:
response = self.process_response( _COMMAND_INLISTPASSIVETARGET, response_length=19, timeout=timeout )

So we hard-code to 19 bytes? I have adjusted the "response_length" parameter down to 10, and it appears to work properly, for the specific card I am using here.

Can someone explain how we derived this length, and more importantly - why is this not dynamic based on what the chip is sending back to us? I'm reading through the datasheet, which is how I got to where I am now - but it's honestly making my head hurt.

Hoping to get fresh eyes on this that are far more intimately familiar with the device and protocol already.

Thanks for talking this out with me! - Joel

MemoryError: memory allocation failed

main.py output:
Traceback (most recent call last):
File "main.py", line 15, in
File "adafruit_pn532.py", line 53, in
MemoryError: memory allocation failed, allocating 80 bytes

Is this library very memory heavy? I can't seem to get it running on my Trinket M0 along with the Adafruit.hid Keyboard library. The simple sample code does seem to work just fine.

IRQ not used?

I just started using the PN532 CircuitPython library and think it is great! But I was curious why IRQ isn't used at all and can't even be optionally used? I have used the c++ library in the past and in that, the IRQ line is used (just for i2c).

I think it could be useful if the IRQ line's readiness (meaning if it is pulled low) was exposed as a property. I was experimenting with this and could issue a pull request if it is something that would be of interest to the maintainers?

i.e.:

@property
def irq_ready(self):
    if self._irq is None:
        raise RuntimeError("IRQ pin not defined!")
    return self._irq.value == 0

PN532_SPI._wait_ready cannot recover if failing

PN532_SPI._wait_ready polls the status until ready. However, the command to be sent is overwritten by the response received. Hence, if the device is not ready at the first request, we might send the wrong command for subsequent polling:

while (time.monotonic() - timestamp) < timeout:
                time.sleep(0.02)   # required
                spi.write_readinto(status, status) #pylint: disable=no-member
                if reverse_bit(status[1]) == 0x01:  # LSB data is read in MSB
                    return True      # Not busy anymore!
                else:
                    time.sleep(0.01)  # pause a bit till we ask again

the command in status is overwritten.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.