0

I am using a raspberry pi with NFC reader module PN532 by Waveshare.

I have ntag215 which I would like to read the text data that was written to it using NFC Tools app downloaded from Google Playstore. The data written was hello_world. When I run the following python script and print out the written data, output printed: bytearray(b'nhel') instead of hello_world. Where did I go wrong? How do I output the full string hello_world?

My code:

"""
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 RPi.GPIO as GPIO
import codecs
from pn532 import *


if __name__ == '__main__':
    try:
        pn532 = PN532_SPI(debug=False, reset=20, cs=4)
        #pn532 = PN532_I2C(debug=False, reset=20, req=16)
        #pn532 = PN532_UART(debug=False, reset=20)

        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=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])
             ntag2xx_block = pn532.ntag2xx_read_block(6)
            print(ntag2xx_block)
            
            for i in uid:
                print(hex(i))
    except Exception as e:
        print(e)
    finally:
        GPIO.cleanup()
snow
  • 217
  • 1
  • 8
  • Does this answer your question? [Why Android NFC reader add's "en" before the message?](https://stackoverflow.com/questions/59515271/why-android-nfc-reader-adds-en-before-the-message) – Andrew Oct 25 '22 at 18:06
  • As well as the standard text record language header, you don't seem to read enough data may be use a better library like https://nfcpy.readthedocs.io/en/latest/modules/tag.html to read Ndef – Andrew Oct 25 '22 at 18:11
  • Could u give a working example to read the text data hello_world with nfcpy? – snow Oct 26 '22 at 02:54
  • Check out the examples programs of nfcpy https://nfcpy.readthedocs.io/en/latest/examples/tagtool.html – Andrew Oct 26 '22 at 07:44
  • i am using PN532 NFC reader with SPI comm protocol. Seems that nfcpy only works with USB readers? – snow Nov 03 '22 at 09:34

0 Answers0