Uncategorized

nfc project notes

sage full transcript highlights

tlfong01

tlfong01
2888
Apr 1, 14:33
user image
Next step is to use a multi-meter to check the open/short wiring of SPI connection of MRFC522 module to Rpi.
2 hours later…
627117717.pr
627117717.pr
Apr 1, 16:58
Ok thats good everything else ok?
5 hours later…
tlfong01

tlfong01
2888
Apr 1, 21:44
Well, going slow. (1) Appendix E shows where mfrc522.py and SimpleMFRC522.py are hiding. (2) I don’t want to run the programs in their hiding place, worrying that I might mess up things. Instead made a copy of the two programs in a newly created directory “/home/testMfrc”. Now I am testing my version of Write.py which import mfrc522 and try to write something to the tag.
Now a question: Do you have any experience in OOP (Object Oriented Programming), such as Arduino C++? If you are not experienced in nay OOP language, then I can forget the mrfc Class thing and directly do everything using functions, ie FP (Functional Programming).
Question 2 – Do you have a web link to the NFC module your are playing? Is it a cheapy eBay Version 1? I remember when I bought my Version 3 NFC module, the shop says they are Version 3, and that other shops’ Version 1 are bad.
2 hours later…
627117717.pr

627117717.pr
Apr 1, 23:25
Hi again, i do have experience in OOP C++ but its been a long time since and forgot most of it tbh, and the link i bought it from amamzon is amazon.co.uk/…
Hopefully this helps
18 hours later…
627117717.pr
627117717.pr
Apr 2, 17:00
Any luck with the MFRC522 module tutorial and debugging?
1 hour later…
tlfong01

tlfong01
2888
Apr 2, 18:22
Ah, still walking slowly. A couple of random comments: (1) Your module from Amazon UK looks good quality. I skimmed the comments and found some of them useful – such as that the SimpleMFRC522 is not updated.
I visited the MFRC522 GitHub and found the following IMPORTANT NOTICE: “This library has not being actively updated in almost four years. It might not work as intended on more recent Raspberry Pi devices. You might want to take a look to the open pull-requests and forks to see other implementations and bug-fixes.”
I also found Mario Gómez’s original MFRC522 GitHub version very good. Eg, his read/write program has good documentation, comparing to SimpleMFRC522 which is too brief.

So as I said earlier, I will forget SimpleMFRC522 and directly use Mario Gómez’s original version to learn what he is doing. He also explains about the requirements of SPI-Py and GPIO, both of which I suspect is not standard, and might not be compatible to Rpi4B buster. But I am only 50% sure.

Now I am thinking of writing a very small version of MarioGomez’s MRFC522 class, but not an OO class, instead a couple of python functions. The objective is checking out if a module is basically working. The checking out method is to “ping”, or write something to a MRFC522 register and read back later.
627117717.pr

627117717.pr
11
Apr 2, 18:41
HI that’s what i was orginally doing! using SMIPLEMFRC522 ill try using the more direct version and see how thats goes hopefully works !!
the objective of all of this is to see if the tag can read/write properly ill try the marios code and see if that is any better !!
tlfong01

tlfong01
2888
Apr 2, 19:28
Ha, yes, so I am back to Square 1 – What you were originally doing. Now I have listed the programs I unzipped into a penzu entry for easy reference: penzu.com/p/dff77f0d
But have you already done the SPI loopback check? The reason that you could not read the tag might be because your SPI hardware wiring is broken. If that is the case, you just fix the broken SPI wiring, then your problem should disappear! 🙂 Anyway, late supper time. See you very late this evening or tomorrow. Good luck, cheers.
627117717.pr

627117717.pr
ok nice one mate ill try the loopback right now and update you after!
tried the loopback test
how can i attach a picture to show you?
1 hour later…
tlfong01

tlfong01
Apr 2, 20:54
Ah, to display an image, I usually do this: (1) Use any camera to shoot a 2MB or smaller jpeg image, and copy to a PC Windows directory, (2) click the upload button, browse to the directory and click the image name. I sometimes use imgur.com to upload the images and then paste to the answer in this forum.
627117717.pr
627117717.pr
ok no problem will do so
how would i do this on rasperry pi im new to this thing not sure how to!
tlfong01

tlfong01
2888
Apr 2, 21:20
I did’t catch you. Did you mean how to test Mario Gomez’s program in Rpi. What I am going to do is the following. (1) Download the zipped programs from GitHub to Win10 PC, (2) Unzip to find the three important programs: (a) mfrc522.py, (b) read.py, (c) write.py. In Rpi, create a new directory under Rpi home directory, say “test_mrfc522”. Copy the above three programs in this new directory, (c) I will use Rpi Desktop GUI Thonny IDE to run read01.py.
You might use terminal command something like this. “$ python read01.py” to run it. My modified read.py program is in this penzu: “mfrc programming log V0.7”: penzu.com/p/df27d289.
627117717.pr
627117717.pr
OK great stuff could i download and unzip the file to my pi? from github
tlfong01

tlfong01
2888
Apr 2, 21:49
Ah yes, you can download the zip file (Ref 27 of my answer) to either Windows PC or Rpi. I am a GUI guy and I can do it in GUI Win10 many times faster than in CLI Rpi buster, perhaps vice versa for you. I sometimes use Windows PureFTP or Samba to transfer files between PC and Rpi. But often I just use a USB finger as a courier. I also have a 500GB SSD in Rpi and also in Win10 to back up things, just in case I mess up things. Good luck.
627117717.pr
627117717.pr
Apr 2, 22:33
Thank you ill try !
tlfong01

tlfong01
2888
Ah bed time! I call it a day. Good luck and see you tomorrow.
And before I go –
user image
4 hours later…
627117717.pr
627117717.pr
Apr 3, 2:14
nice one see you tommorow ill try to find a way to sent the code pictures!!!
12 hours later…
tlfong01

tlfong01
2888
Apr 3, 14:20
@627117717.pr Looking forward to your pictures. Two more things. (1) You SPI wiring should not be longer than 1 meter, (2) The rpi.org “Official” loop back program warns that only CLK, MOSI and MISO wiring, but CE0/1 are NOT tested.
To test all 4 signals, you should do a “read after write” test to make sure what is written can be read back. My penzu file includes such a program. The test program I am writing tries to write something to the MRFC device and read back, to make “100%” that the MRFC chips is working OK.
user image
4 hours later…
627117717.pr
627117717.pr
Apr 3, 17:56
Morning
ill try to send the pictiures across today to give you a better idea of where im at!!
627117717.pr

627117717.pr
11
Apr 3, 18:08
the test i did for the spi
came out like this as i cant figure out how to send you the picture it looks like this
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
tlfong01

tlfong01
2888
Good. Looking forward to your pictures. Now I am trying to simplify Mario Gomez’s MFRC522.py, cutting everything except using SPI read write one MFRC522 register. This is to show that the Rpi4B buster SpiDev can read write MFRC522 registers. The I don’t need to compile a special version of SpiDev for this project. I guess it is only the old Rpi 2/3 with old OS like wheezy/jessi/stretch which has outdated SpiDev need a compiled version.
627117717.pr

627117717.pr
11
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00
all 0 for some reason do you know why that is by any chance?
tlfong01
tlfong01
Same for GPIO. I read the requirement is GPIO version 0.6.5 which ahd a major upgrade. The old OS with older than V0.6.5 need to compile a standard GPIO.
627117717.pr
627117717.pr
how would i test or upgrade the GPIO?
in order to get the same outcome as you?
tlfong01

tlfong01
2888
Ah, let me see. Appendix E says that if loopback test results good, then second line should begin with 0x40 and end with 0x95. So the poor soul failed the exam 🙂
By the way, do you have a multi-meter to test the resistance between connecting/jumper wires of the SPI interface from Rpi to MFRC522? Remember that MOSI, MISO one side connect to MISO, MOSI other side, ie, Crossing over, NOT direct point to point. Ah supper time, see you later.
tlfong01

tlfong01
2888
Apr 3, 18:34
Ah, I looked at my results in Appendix E and found I made a typo mistake. The ALL ZEROS output means MISO is not connected to MOSI. So you need a multi-meter to check it out. And as the wise guy Warren Buffett says “There is never only one cockroach in the kitchen”. I guess the careless newbie very likely made more mistakes.
By the way, you see my wiring is colour coded, ORANGE for MOSI, YELLOW for MSIO. That means Orange connect to Yellow, etc. Other lines CLK and CS direct connect though.
See you later. Cheers.
627117717.pr
627117717.pr
Apr 3, 18:46
cheer thanks!
3 hours later…
tlfong01

tlfong01
Apr 3, 21:33
@627117717.pr You might like to try my references 28, 29. But I have not tried that. I pip 3 all the time, so should be have all tools python 3 compatible. But if you git clone old tutorials, you might installed python 2 stuff and mess up things.
tlfong01

tlfong01
Apr 3, 21:44
@627117717.pr I forgot to mention that I use my camera for photos. To capture screen, I use the terminal command “scrot”. You can “scrot –help” for details. I also use Win10 PhotoShop to crop and edit images and photos.
17 hours later…
tlfong01

tlfong01
2888
Sat 14:16
@627117717.pr Now I am reading Mario Gomez’s READ.MD one more time, to make sure I did not miss anything important. He says we need to use SPI-Py, which is I am note sure if it is still needed for Rpi4B buster.
user image
6 hours later…
tlfong01

tlfong01
2888
Sat 20:44
I hope you have debugged your SPI wiring and tested SPI loopback OK. After that I think you can go back to square 1 and tried either your first or second tutorial. There is 50% chance that both of them works, though one using python 2 and there other python 3. I am making little progress in try to replace Rpi4B buster’s SpiDev to replace Mario GoMez’s SpiDev and GPIO. So I suspend this part and go back to goggle more to learn. I found many more GitHub versions, but I know too little to tell the difference. Here is one I found interesting pat-odoo/TwoRC522_RPi2-3

(see full text)

1 hour later…
tlfong01

tlfong01
2888
Sat 22:03
If you have finally solved the loop back problem, I suggest you to pip3 install and then python3 to run SimpleMFRC522. It took me less than 10 minutes to install and run a short test program. Please read my updated answer fro more details. Good luck. Cheers.
user image
Please feel me to ask me to explain anything or do more tests.
20 hours later…
627117717.pr
627117717.pr
Sun 17:55
@tlfong01 Hi mate sorry been away for the last day!
NIce one mate ill give that a go and uodate you in the mean time
3 hours later…
tlfong01

tlfong01
2888
Sun 20:39
@627117717.pr No problem and no hurry. So take your time. It is very likely a long project. longer than the corona virus. Just in case you still could not do the SPI Channel 0.0 loopback, because pins broken, or circuit fried, I am testing more CS channel, 0.1, 1.0, 1.1, 1.2 and many more, for you to mess around (See Appendix L).
One reason I am setting up more SPI channels, is because I see many ninja guys are playing with two or more readers at the same time, So I am feeling facing losingly jealous. 🙂
tlfong01

tlfong01
2888
Sun 21:04
@627117717.pr I am trying to remove the SPI and GPIO functions from MG (Mario Gomez)’s MFRC522 Class for the following reasons: (1) MG’s Class is hardcoded to use SPI 0,0, but I want to use at least SPI 0.0, 0.1, 1.0, 1.1, 1.2, five channels for flexibly use 2 or more readers, and for easy pair/swap troubleshooting. (2) MG’s class also hard codes the GPIO pin assignment, start up and clean up times, and I found it annoying to take care of my other external GPIO functions. (See Refs 34, 35)
1 hour later…
tlfong01

tlfong01
2888
Sun 22:05
@627117717.pr Earlier I said my RFID project is very long, because I am thinking of building an attendance system (Ref 37), using MySQL, PHP etc, which I have no experience at all. By the way, do you have any follow up project like me?
Ah bed time, see you tomorrow. Cheers.
1 hour later…
627117717.pr
627117717.pr
Sun 23:21
Nice one cheers pi up my life have a really good guide on how to do the attendeance system btw !
2 days later…
627117717.pr
627117717.pr
Tue 18:01
@tlfong01 thats good stuff maybe if possible you could go through each of the steps once figured out with me so i can get the same result on my side if possible
4 hours later…
tlfong01

tlfong01
2888
Tue 21:44
@627117717.pr Well, so I have described the first step of using SPI loop back as a way to check out the SPI hardware wiring and software initialization are more or less working OK. The second step is to use python shell commands to import SimpleMFRC522, create an object reader and then write something a read back.
As I suggest in the very beginning, it would be nice if you can compile an answer yourself for your own question, alongside my answer. My answer is Rpi4B buster, yours is Rpi3B+ stretch NOOBS etc etc.
Question: Have you any experience in using the data structure “list”? And do you have any vague idea of “scalable” or “SCALA”? I am now going to do scalable python3 list processing of up to 8 MFRC522 modules (Yes, I have 12 in hand.). In case you could not catch up, I think I would just skip the program documentation, and show you how to use it.
Ah almost bed time! So see you tomorrow. PS – my last appendix gives an idea of how I am “pinging” two modules. (If you have never heard of the term “ping”, then you would need a long long time to catch up.
20 hours later…
627117717.pr

627117717.pr
11
Wed 17:31
hi have no experience in data structure “list” i did the first steps as from the pictures you sent installing the pip3 for mfrc522 and the python3 however a message displays up
ImportError: No module named mfrc522
>>> RFIDModule = SimpleMFRC522()
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
NameError: name ‘SimpleMFRC522’ is not defined
>>> XZ
pi@raspberrypi:~ $ sudo pip3 install mfrc522
Looking in indexes: pypi.org/simplepiwheels.org/simple
Requirement already satisfied: mfrc522 in /usr/local/lib/python3.7/dist-packages (0.0.7)
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from mfrc522) (0.7.0)
Requirement already satisfied: spidev in /usr/lib/python3/dist-packages (from mfrc522) (3.4)
pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

(see full text)

code above ^^^
3 hours later…
tlfong01

tlfong01
2888
Wed 20:48
@627117717.pr Ah, let me see. So your reader can write ‘parcel 1’ and read back. That means read and write are OK. Next step is to use python 3 to execute read.py and write.py. BTW did you use a multi-meter to solve your last problem?
@627117717.pr And please tell me more about your programming background. Eg did you have any experience to us Rpi python to blink a LED and read a button? Or have you played with Arduino before? Do you have a multi-meter and know how to measure the resistance?. And have you heard of “Ohm’s Law”. “Pull up” etc?
20 hours later…
627117717.pr

627117717.pr
11
yst 17:03
hey have no experience in rpi python,
also because i copied what you wrote and put into the terminal obviously changing the nfc ro rfid module, for some reason it seams not to work even with python
pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from mfrc522 import SimpleMFRC522
>>> reader = SimpleMFRC522()
/usr/local/lib/python3.7/dist-packages/mfrc522/MFRC522.py:151: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(pin_rst, GPIO.OUT)
>>> reader.write (‘parcel1’)
(1223443245, ‘parcel1’)
>>> reader.read()

(see full text)

python 3 i think thats correct
pi@raspberrypi:~ $ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from mfrc522 import SimpleMFRC522
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ImportError: No module named mfrc522
>>> RFIDModule = SimpleMFRC522()
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
NameError: name ‘SimpleMFRC522’ is not defined
>>> XZ
[3]+ Stopped python

(see full text)

python ^ not correct not sure where i went wrong
2 hours later…
tlfong01

tlfong01
2888
yst 18:50
@627117717.pr I have no experience in python 2. So I am not able to debug. I would suggest you to use python 3 only, like this: (1) Use a new SD card, (2) pip 3 mfrc522, then play with python 3 only. Do not install any python 2 software. And his: (1) Use a new SD card, suing full version , NOT NOOBS, (2) pip 3 mfrc522, then play with python 3 only. Do not install any python 2 software, or rpi buster will be confused.
You have not told everyboy if you are using pi3, 3+, or 3B+, and wheezy or jessie. Use “$ date” and “$ unname – a” so everybody notes your configuration, without guessing. Also compile your answer in steps, so everybody can follow your steps.
tlfong01
tlfong01
yst 19:04
@627117717.pr If you insist to use python 2, you need to set the “path” variable to your python 2 software directories. See Ref 42 for more details.
627117717.pr

627117717.pr
yst 19:53
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.19.97-v7+ #1294 SMP Thu Jan 30 13:15:58 GMT 2020 armv7l GNU/Linux
hi mate this is what came up
tlfong01

tlfong01
2888
yst 20:31
@627117717.pr It would be nice if you can provide this info by editing your question, or in your own answer. So you are still using NOOBS. If you browse around, you might find guys recommending NOT to use NOOBS, unless you wish to try other linux versions, say Ubuntu 19. But are you? I am just using uname as an example. Actually I am using a couple more grep commands so that other friends can help.
My other commands include checking chip version 4B 4GB v1.2, free memory, buster release 2020feb13. If you give me the rpi 4.19, I need to cross check what release it it, and sometimes that matters, and wasted my hours to found out finally.
15 hours later…
tlfong01

tlfong01
2888
12:00
@627117717.pr I read the reviews of the Mario Gomez’s library and confirmed that (1) The software in general is out of date, and need to be modified, (2) SPI-py required, (3) Some modules do not have pullup at Reset and Interrupt pin, and therefore might need external ones. (4) MOSI and MISO wired should be “direct feed through connect”, NOT “crossing over”.
Errata and Appolgy – Earlier I wrongly warned that the MOSI and MSIO wires should be crossing over, which is normally used in other SPI/UART devices. Unfortunately I can NO LONGER edit/correct the old chat record. So be warned that a couple of other things I mentioned in this chat room are simply wrong, if not just misleading. As a remedy, I am trying my best to update my “interactive” and “live” answer and penzu reading/experimenting log.
2 hours later…
tlfong01

tlfong01
2888
14:32
I found Mario Gomez seems using modified version of SpiDev and GPIO, hiding in special usr/local directories. These software seem not the same as the buster built in versions. So I am looking for other libraries which should be easier to use. Now I am looking at these: (1) ondryaso/pi-rc522 Rpi python library for SPI RFID RC522 module (Add support for interrupt driven tag detection) Latest commit
da9928a on Sep 12, 2019
github.com/ondryaso/pi-rc522

(2) Ondryaso rc-522 library listing

(see full text)

The Ondryaso library has other goodies, including (1) Using Rpi Interrupt (for my 5 reader board, saving time looping for a card to detect), (2) Explanation of blocks and also a block number calculation utility. Now I am starting to try them. Cheers.
3 hours later…
627117717.pr
627117717.pr
17:07
ok great sounds good
kind of new to all of this so not the best at explaining things
2 hours later…
627117717.pr
627117717.pr
19:00
(removed)
3 hours later…
tlfong01

tlfong01
2888
22:16
@627117717.pr Yes, I now think that this NFC/RFID subject much more complicated that I thought. As I said, I am just scratching the surface. Many things I mentioned in this chat room and also in my tentative answers, especially the appendices are misleading or plain wrong. It is fortunate that I can edit my answers to correct the mistakes I made.
I need much more time, perhaps a week or so, to study harder the Mario Gomez, Gus PiMyLifeUp SimpleMFRC, and Ondryaso libraries, before I can make up my mind to stall my project, or go another direction. In the mean time I don’t recommend you to do anything, except sit back and watch me messing around. Ah, bed time, see you later.

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.