Hey guys,
Ideally, I'd post this in a RasPi sub-forum but we don't have one here. I'm trying to write a simple script that reads NFC tags using the Adafruit PN532 breakout board using Python.
Currently, I can get libnfc working but it's examples are in C and I'm not about to learn that. I'm also in a bit of a timecrunch.
Thanks in advance, guys.
-Clutch
There is a python specific module for that ( nfcpy) and libnfc isn't listed as a requirement.
The documentation there is also nice and thorough.
Would probably be easier than attempting to use libnfc via python.
I am not really a fan myself for those RasPi's but here is what a little bit of googling pointed me to:
https://nfcpy.readthedocs.org/en/latest/...write-tags
It is near field communication however it is not described exactly like you wanted.
(Oct 1, 2015 12:48 PM)theDIVISION Wrote: I am not really a fan myself for those RasPi's but here is what a little bit of googling pointed me to:
https://nfcpy.readthedocs.org/en/latest/...write-tags
It is near field communication however it is not described exactly like you wanted.
(Oct 1, 2015 10:45 AM)SavageBoys Wrote: There is a python specific module for that (nfcpy) and libnfc isn't listed as a requirement.
The documentation there is also nice and thorough.
Would probably be easier than attempting to use libnfc via python.
I tried to use nfcpy but I can't get it to talk to the reader. I tried running this:
Code ./tagtool.py --device tty:AMA0:pn532_uart
but it fails and says it can't find the reader. I ran nfc-scan-device and it ouputs this:
Code nfc-scan-device uses libnfc 1.7.1
1 NFC device(s) found:
- pn532_uart:/dev/ttyAMA0:
pn532_uart:/dev/ttyAMA0
I have the reader connected via UART which the docs say should work, but I might try connecting via SPI if I can find a guide on how to do it. If anyone has suggestions on how to troubleshoot that, I'd probably send you some BTC.
OR
If you can help me use this library, it looks very promising: https://github.com/xantares/nfc-bindings but I can't seem to get the example working.
Oct 2, 2015 08:04 AM
(This post was last modified: Oct 2, 2015 08:08 AM by theDIVISION.)
What I've learned in my time of coding is that if the path that the computer spits out is not satisfied, it always gets butthurt.
I will be looking into that however have you tried
PHP Code
<?php ./tagtool.py --device pn532_uart:/dev/ttyAMA0:
.
Or just...
PHP Code
<?php ./tagtool.py --device pn532_uart
(Oct 2, 2015 08:04 AM)theDIVISION Wrote: What I've learned in my time of coding is that if the path that the computer spits out is not satisfied, it always gets butthurt.
I will be looking into that however have you tried
PHP Code
<?php ./tagtool.py --device pn532_uart:/dev/ttyAMA0:
.
Or just...
PHP Code
<?php ./tagtool.py --device pn532_uart
Both result in this:
Code [nfc.clf] searching for reader on path pn532_uart:/dev/ttyAMA0
[nfc.clf] no reader available on path pn532_uart:/dev/ttyAMA0
[main] no contactless reader found on pn532_uart:/dev/ttyAMA0
[main] no contactless reader available
Running ./tagtool.py --help shows the following for usage:
Code --device PATH use contactless reader at: 'usb[:vid[:pid]]' (with
vendor and product id), 'usb[:bus[:dev]]' (with bus
and device number), 'tty:port:driver' (with
/dev/tty<port> and <driver>), 'com:port:driver' (with
COM<port> and <driver>), 'udp[:host[:port]]' (with
<host> name/addr and <port> number)
Rather than being specific have you tried doing:
Code $ python
>> import nfc
>> clfusb = nfc.ContactlessFrontend('usb')
>> clftty = nfc.ContactlessFrontend('tty')
>> clfcom = nfc.ContactlessFrontend('com')
>> clfudp = nfc.ContactlessFrontend('udp')
>> findnfc = ("{}\n{}\n{}\n{}".format(clfusb, clftty, clfcom, clfudp))
>> print(findnfc)
To see if it can connect automatically?
If that doesn't find it.. I'm not sure what is wrong.
(Oct 2, 2015 12:08 PM)SavageBoys Wrote: Rather than being specific have you tried doing:
Code $ python
>> import nfc
>> clfusb = nfc.ContactlessFrontend('usb')
>> clftty = nfc.ContactlessFrontend('tty')
>> clfcom = nfc.ContactlessFrontend('com')
>> clfudp = nfc.ContactlessFrontend('udp')
>> findnfc = ("{}\n{}\n{}\n{}".format(clfusb, clftty, clfcom, clfudp))
>> print(findnfc)
To see if it can connect automatically?
If that doesn't find it.. I'm not sure what is wrong.
The "clf" lines failed except for clftty. I skipped the findnfc line and did "print clftty" which output:
That's great news right? Where is the nfc library that I'm importing? I'm trying to find documentation on what methods I can use, but it doesn't look like it's from the actual python language.
(Oct 2, 2015 06:45 PM)Clutch Wrote: The "clf" lines failed except for clftty. I skipped the findnfc line and did "print clftty" which output:
That's great news right? Where is the nfc library that I'm importing? I'm trying to find documentation on what methods I can use, but it doesn't look like it's from the actual python language.
Its probably located in site-packages in the python/Lib directory.
When you installed nfcpy it became importable, just need to add: import nfc to the top of any scripts you write using it and you're golden.
And yeah you would need to look up nfcpy's specific functions and such. You can find those here: http://nfcpy.org/latest/topics/get-start...n-a-reader
(Oct 2, 2015 07:01 PM)SavageBoys Wrote: Its probably located in site-packages in the python/Lib directory.
When you installed nfcpy it became importable, just need to add: import nfc to the top of any scripts you write using it and you're golden.
And yeah you would need to look up nfcpy's specific functions and such. You can find those here: http://nfcpy.org/latest/topics/get-start...n-a-reader
Thank you so much for your help. I've got it working and am furiously working on my tag id reading script. The only thing I'm nervous about is ever moving this code from the Pi to another or to another OS. I'm not really sure how I got nfcpy working, but I think it had to do with a redirect-type file I made in /usr/share.
Anyway, thank so much for help man. Threw some rep your way.
Redirect? So it couldn't find a certain file/directory and you needed to create a symlink? Strange.
As far as I know nfcpy is installed the same way in windows and OSX, its just a python module after all so: pip install nfcpy will do the trick
You could make a simple shell script for linux/OSX to create the symlink if it turns out to be needed every time and grab the python module at the same time.
Heck you could even get your id reading script setup and have an alias made for it ready to go so you can just do: scriptname args rather than need to type: python fullscriptname args every time.
Windows would of course require python to be installed manually.. and maybe OSX (not something I mess with)
|