Reputation: 240
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()
Upvotes: 0
Views: 941