Uncategorized

mfrc522 notes

Asked 
Active today
Viewed 252 times
2

Trying to read my RFID MFRC522 using a Mifare blue tag and it is not working. Wondering if i could get any help on this as when i put the tag to read it doesn’t show up as quick?

using:

https://pimylifeup.com/raspberry-pi-rfid-rc522/

https://medium.com/coinmonks/for-beginners-how-to-set-up-a-raspberry-pi-rfid-rc522-reader-and-record-data-on-iota-865f67843a2d

Python coding based on the websites I've used in order to try to get my tag to read

1

Question

How can Rpi python read a SPI MFRC255 RFID/NFC tag?


Short Answer

Part 1 – Introduction to I2C and SPI NFC/RFID Chips and Modules

wiring dia 1


Part 2 – Setting up SPI MFRC522 Module

dual mfrc522 module


Part 3 – Troubleshooting SPI Software and Hardware using Loopback

loopback test


Part 4 – Using Rpi4B buster Python 3 and Mfrc522 library to read NFC Tag

I have successfully installed mfrc522 using pip3. I created a reader, wrote something to a tag, and then read back, without any problem.

Notes

  1. I am using Rpi4B buster release 2020feb13, preinstalled python 3.7.3.
  2. pip3 installs mfrc522 0.0.7 in /usr/local/lib/python3.7/dist-packages …
  3. pip3 installs spidev 3.4 and GPIO 0.7 in /usr/lib/python3/dist-packages …
  4. If the reader freezes/hangs when try to read or write, then it is necessary to do the SPI loopback test, to make sure the SPI software setup and hardware wiring is correct (See Appendix E below for details on using the SPI loop back tools.

mfrc522 test


Part 5 – Using Rpi4B Python 2 and Mfrc522 library to read Maire Blue Tag

The python3 mfrc522 library installed by pip3 is backward compatible to python2. So the path is set so that either python3 or python2 would import the same library installed by pip3. The following screen shows that python2 can also use the same library to read/write a tag.

python 2.7 test


Part 6 – Studying Mario Gomez’s read.py and write.py code

I found Mario Gomez’ library has a function for MIFAIRE Classic 1K tag. I know very little about it. So I am googling to understand it better. I found Ref 43 by the Last Minute Enginners good. I found there are many more things I don’t know about, eg UID, PICC, SAK etc.

Notes

  1. Mario Gomez’s mfrc522.py read.py and write.py code is very well commented and therefore most newbie friendly. (See Ref 27)
  2. Mario Gomez’s code, as he said, is thoroughly commented, but I still found it difficult to understand or guess what this and that means. Then I realized that I actually do not have the prerequisite knowledge to understand event the basic idea of NFC. So I googled for a NFC glossary to clear my mind (Ref 43). Skimming the glossary, I now know precisely what is NFC, PCD, PICC, and most importantly what is MIFAIRE (A product of NXP Semiconductors. It is a smart card based on ISO14443A providing up to 4KB of memory on the card.)

mifare class 1k


/ to continue, …


Long Answer

  1. The OP used Rpi3 NOOB python 2.7, and installed himself SpiPy, SpiDev for testing.
  2. I think python 2.7 is a bit out of date. So I am repeating the OP’s situation but instead using Rpi4B buster 2020feb13 (full version image), with the following buster preinstalled software:

    (a) python 3.7.3

    (b) thonny IDE

    (c) spiDev

    (d) pip3

  3. I am using pip3 to install the MFRC522 python library, which includes the following two python3 programs:

    (a) mfrc522.py (about 400 lines)

    (b) simpleMFRC.py (about 100 lines)

  4. I am using the RFID/NFC module already tested OK using libnfc-1.7.1 in I2C configuration (Appendix A).
  5. I am using pip3 to install mrfc522, RPi.GPIO, and spidev in the following directory (Appendix B). I am not sure if the above GPIO and spidev modules are the same or different from the buster’s corresponding preinstalled programs.

    /usr/local/lib/python3.7/dist-packages

  6. I am using the built-in SPI interface /dev/spidev0.0 and /dev/spidev0.1 (Appendix C)
  7. I used python3 shell to import SimpleMFRC522 from mfrc522, and found creating a reader object OK. (Appendix D).

    from mfrc522 import SimpleMFRC522

    reader = SimpleMFRC522()

  8. I read MFRC522-python/mfrc522/SimpleMFRC522.py/ – GitHu 2019mar26 saying the following:

    @death-droid Improve compatibility with Python 3 – 2019mar26

    So I guess the earlier versions of SimpleMFRC522 were not very compatible to python3. I was wondering if my pip3 installed stuff is more or less updated than the OP’s corresponding software using Git Clone. I guess I better download the most updated versions of mfrc522, SimpleMFRC522, and the demo/test red/write tag programs and freeze them for later testing.

  9. Now have tidied up the different version of the four main programs mfrc522.py, samplemfrc522py, read.py, and write.py, and put them in a penzu reading log file. Next step is to skim the two big files to get a rough picture of what is going on.

    https://penzu.com/public/08d4fdf2

  10. Now I have skimmed the two main programs mrfc522.py and simpleMFRC522.py. I surprisingly found the program structure is very simple. So it should not not that difficult to debug and expand. The penzu reading log is here:

    https://penzu.com/p/08d4fdf2

  11. Now I have tried the SPI loopback test and found it OK. (Appendix E)
  12. I tried to repeat the OP is problem, ie, raed a tag. Still no luck, the program hanged. Because I already double checked that the NFC module can read OK the same tag using libbnfc-1.7.1 I2C mode, and SPI loopback at 50kHz is OK. So the problem is likely at the SimpleMFRC522 side. Next step is to debug Read.py, SimpleMFRC522.py and the MFRC522.py library. (Appendix J)
  13. Now I am checking the schematic of [another similar] nfc module to make sure that my guess of the IRQ and RST wiring is correct, ie, no need to connect these two pins to Rpi. This is verified by the success of libnfc-1.7.1 I2C read card without connect the RST and IRQ pins. Perhaps I can ping the module to make sure SPI Clk, Mosi, and Miso are working OK (the previous SPI loopback only tests 50kHz and only MOSI and Miso, CS is not tested. (Appendix J)
  14. I read the pn532 datasheet that the max SPI speed is 5MHz, so it should be OK to set SPI speed to 1MHz, 500kHz, or 100kHz. (Appendix J)

    / to continue, …


References

(1) PN532 NFC/RFID Catalog – AdaFruit US$40

(2) PN532 NFC/RFID controller breakout board v1.6 – AdaFruit US$40

(3) RFID/NFC Guides – AdaFruit

(4) Build a Babel Fish Language Toy – AdaFruit

(5) YouTube Build a Babel Fish Language Toy with Adafruit RFID and Wave Shields for Arduino – AdaFruit 2012aug02

(6) AdaFruit PN532 Breakout Module V1.6 Documentation (I2C/SPI GitHub, datasheet, schematic, tutorials, downloads)

(7) Using with LibNFC – AdaFruit (Mainly for Arduino, a bit out of date)

(8) libfnc Main Page (Last modified 2013) – nfc-tools.org

(9) RFID and NFC Tutorial – SparkFun

(10) SparkFun RFID Starter Kit Hookup Guide

(11) PN532 NFC Module for Raspberry Pi – SunFounder US$28

(12) PN532 NFC Module for Raspberry Pi Tutorial (libnfc, C language) – SunFounder

(13) AliExpress PN532 NFC Module Catalog US$3~5

(14) How to setup a Raspberry Pi RFID RC522 Chip (SPI, python) – PiMyLifeUp

(15) pimylifeup/MFRC522 – SPI python – PiMyLifeUp

(16) Grove NFC Module (With Arduino UART, I2C Demo Programs) V1.1 – Seeed Studio 2016aug31

(17) Setting up a PN532 NFC module (V3) on a Raspberry Pi using I2C – blog of stigok 2017oct12

(18)PN532/C1 Near Field Communication (NFC) controller Rev3.6 – NXP 2017nov28

(19) PN532 User Manual (UM0701-02 Rev02) – NXP2007

(20) MIFARE – Wikipedia

(21) Amazon AZDelivery RC522 RFID Kit x 3 for Arduino and Rpi – £9.5

(22) AZDelivery RFID Kit RC522 Reviews

(23) TaoBao Risym MFRC-522 RC522 RFID Reader – ¥12

(24) MFRC522 MIFARE NTAG FrontEnd R3.9 Datasheet — NXP 2016apr27

(25) Mario Gómez MFRC522-python 2018mar26 Main Page

(26) Mario Gómez MFRC522-python 2018mar26 Read Me

(27) Mario Gómez MFRC522-python 2018mar26 Zip Download

(28) Spidev 3.4 User Guide – PyPi 2020feb19

(29) RPi.GPIO 0.7.0 pip install RPi.GPIO

(30) Pat-odoo TwoRC522_RPi2-3 – GitHub

(31) Pat-odoo TwoRC522_RPi2-3 – PDF

(32) SPI-Py GitHub – Louis Thiery

(33) MFRC522-python GitHub – Mario Gomez

(34) How to use three RC522 RFID readers at the same time? – Rpi Forum Q&A 2019jun08

(35) MFRC522 Library and External GPIO Program Conflicting Problem, Rpi Forum Q&A

(36) RFID Tags for Library System – Rpi Forum Q&A

(37) Build your own RPi RFID Attendance System (LCD 16×2, MySQL, NGNIX, PHP) – Emmet, PiMyLifeUp 2019aug08/nov17

(38) The Beginner’s Guide to RFID Systems – AtlasRFID

(39) A practical guide to writing technical specs

(40) How to check if SPI is enabled and functional on Raspi 3b+? – Rpi.StackExchange Forum 2019Apr24 Viewed 1k times

(41) Mario Gomez’s read.py, write.py, and mfrc522.py listing

(42) Linux Path Definition

(43) How RFID Works (IFARE Classic 1K) – Last Minute Engineers

(44) Control an I2C HD44780 20×4 LCD display with Rpi

(45) How to setup an I2C 16 x 2 LCD on Rpi – Circuit Basics 2016Apr

(46) Rpi SPI and I2C Tutorial – SparkFun

(47) Near Field Communication Glossary (MIFARE, PICC, PCD etc) – NFCResearch Lab Hagenberg

(48) Ondryaso/pi-rc522 Rpi python library for SPI RFID RC522 module (Add support for interrupt driven tag detection) Latest commit

(49) Ondryaso rc-522 library listing

(50) MIFARE Classic 1K Smart card IC MF1S50YYX_V1 Datasheet R3.2 — NXP 2018may23

(51) MFRC522 Antenna Design Application Note144512 – NXP

(52) Mario Gomez MFRC522 Lirary python3 Incompatibility Problem Forum Discussion

(53) barni2000/MFRC522-python3 Module MFRC522 modified for python 3, (seems not complete)


to continue, …


Appendices

Appendix A – The PN532 NFC/RFID Module V3 being tested

Reference: nfclib v1.1.7 PN532 NFC Module Testing

pn532 1


Appendix B – Mfrc522 software (including SPIdev and GPIO) setup record

mfrc install


Appendix C – Minimal configuration of SPI and I2C channels for testing the PN532 module

boot/config.txt


Appendix D – PiMyLifeUp Gus SimpleMFRC522 Library

simplemfrc522 lib


Appendix E – SPI Loopback Test

Update 2020apr30hkt1826

Many thank for the OP pointing out a typo. If MOSI is not connected to MISO, then the out would be all zeros!

loopback test


Appendix F – MFRC522 Directory Listing

mfrc522 directories listing


Appendix G – AZDelivery RFID Kit Reviews

AZDelivery 3 x RFID Kit RC522 with Reader, Chip and Card for Arduino and Raspberry Pi including E-Book! – £9.5

AZDelivery 3 x RFID Kit RC522 Reviews

Erich Eichinger – Reviewed 12 September 2019

German Quality with significantly wider sensor range than Chinese clones I had some cheap Chinese RC522 clones with a very limited range (only 1-2 mm). Thought I’d try German Quality and was not disappointed. Those RC522 are still cheap enough but detect a tag up to 1.5cm distance which was enough for my purpose.


Jürgen L. Universal and affordable 23 February 2020

With the software you have to trick a little, the instructions available on the net are somewhat outdated or refer to a particular Raspi. But if you have a little programming knowledge, you can quickly customize the Python program yourself.


Rene Winkler – Works fine, but you should use SPI 3 March 2020

The module supports SPI (preconfigured), UART and I2C. The interface must be selected via configuration pins. However, there is no pull up/down for this module. According to the data sheet you would have to pull from high to low for the UART Pin EA. In this case, however, it would mean separating a trace through and pulling a wire bridge to GND.

I’m using the module via SPI on a Raspberry Pi Zero with Python for a kids music box.

The Python library, which I first found for the module, was unfortunately out of date and did not fit the SPI library. Since something had changed in the parameters for SPI read and Write. But the module can’t do anything for that.


Appendix F – PiMyLifeUp SimpleMFRC522.py and Read.py by Simon Monk

# PiMyLifeUp MFRC522 Python Library, Setup, and Example
# https://github.com/pimylifeup/MFRC522-python

# pimylifeup/MFRC522-python
# https://github.com/pimylifeup/MFRC522-
python/blob/master/mfrc522/SimpleMFRC522.py

# Code by Simon Monk https://github.com/simonmonk/

from . import MFRC522
import RPi.GPIO as GPIO

class SimpleMFRC522:

  READER = None

  KEY = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
  BLOCK_ADDRS = [8, 9, 10]

  def __init__(self):
    self.READER = MFRC522()

  def read(self):
      id, text = self.read_no_block()
      while not id:
          id, text = self.read_no_block()
      return id, text

  def read_id(self):
    id = self.read_id_no_block()
    while not id:
      id = self.read_id_no_block()
    return id

  def read_id_no_block(self):
      (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL)
      if status != self.READER.MI_OK:
          return None
      (status, uid) = self.READER.MFRC522_Anticoll()
      if status != self.READER.MI_OK:
          return None
      return self.uid_to_num(uid)

  def read_no_block(self):
    (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL)
    if status != self.READER.MI_OK:
        return None, None
    (status, uid) = self.READER.MFRC522_Anticoll()
    if status != self.READER.MI_OK:
        return None, None
    id = self.uid_to_num(uid)
    self.READER.MFRC522_SelectTag(uid)
    status = self.READER.MFRC522_Auth(self.READER.PICC_AUTHENT1A, 11, self.KEY, uid)
    data = []
    text_read = ''
    if status == self.READER.MI_OK:
        for block_num in self.BLOCK_ADDRS:
            block = self.READER.MFRC522_Read(block_num) 
            if block:
                    data += block
        if data:
             text_read = ''.join(chr(i) for i in data)
    self.READER.MFRC522_StopCrypto1()
    return id, text_read

  def write(self, text):
      id, text_in = self.write_no_block(text)
      while not id:
          id, text_in = self.write_no_block(text)
      return id, text_in

  def write_no_block(self, text):
      (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL)
      if status != self.READER.MI_OK:
          return None, None
      (status, uid) = self.READER.MFRC522_Anticoll()
      if status != self.READER.MI_OK:
          return None, None
      id = self.uid_to_num(uid)
      self.READER.MFRC522_SelectTag(uid)
      status = self.READER.MFRC522_Auth(self.READER.PICC_AUTHENT1A, 11, self.KEY, uid)
      self.READER.MFRC522_Read(11)
      if status == self.READER.MI_OK:
          data = bytearray()
          data.extend(bytearray(text.ljust(len(self.BLOCK_ADDRS) * 16).encode('ascii')))
          i = 0
          for block_num in self.BLOCK_ADDRS:
            self.READER.MFRC522_Write(block_num, data[(i*16):(i+1)*16])
            i += 1
      self.READER.MFRC522_StopCrypto1()
      return id, text[0:(len(self.BLOCK_ADDRS) * 16)]

  def uid_to_num(self, uid):
      n = 0
      for i in range(0, 5):
          n = n * 256 + uid[i]
      return n

# *** mfrc522 Installation and Example Code ****************************************************
# https://github.com/pimylifeup/MFRC522-python

A python library to read/write RFID tags via the budget MFRC522 RFID module.

This code was published in relation to a blog post and you can find out more about how to hook up your MFRC reader to a Raspberry Pi there.

Installation
Until the package is on PyPi, clone this repository and run python setup.py install in the top level directory.

Example Code
The following code will read a tag from the MFRC522

from time import sleep
import sys
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()

try:
    while True:
        print("Hold a tag near the reader")
        id, text = reader.read()
        print("ID: %s\nText: %s" % (id,text))
        sleep(5)
except KeyboardInterrupt:
    GPIO.cleanup()
    raise

.END

Appendix G – Spidev 3.4 User Guide – PyPi

Spidev 3.4 pip install spidev – Python bindings for Linux SPI access through spidev – PyPi 2020feb19

[a] xfer(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.

[b] xfer2(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be held active between blocks.

[c] xfer3(list of values[, speed_hz, delay_usec, bits_per_word])

Similar to xfer2 but accepts arbitrary large lists. If list size exceeds buffer size (which is read from /sys/module/spidev/parameters/bufsiz), data will be split into smaller chunks and sent in multiple operations.


Appendix H – MRFC532 SpiDev LoopBack Test and Wiring Length Limit

spi loopback 01

Appendix I – Mario Gomez MRFC522 Wiring Diagram and Software Requirements 2014

mario Gomez readme.md


Appendix J -Long Answer Points 12, 13, 14

simpleMFRC522 test

pn532 schematic

pn532 interface max speed


Appendix K – Single MFRC522 Mdoule Wiring Diagram

wiring dia 1

wiring dia 2

wiring dia 3

Appendix L – Multiple MFRC522 Module Wiring Diagram

quad mfrc522 wiring


Appendix M – Dual MFRC522 Module (One for SPI 0.0, another for SPI 1.0)

dual mfrc522 module


Appendix N – Python program to ping two modules

So I have written a python program to ping two modules. There are two versions. The “read-only” version is to read the software version register at 0x37 whose contents is 0x92 or 0x12. The “read-after-write” version is to first write the interrupt config register at 0x02 and then read it back. The ping program is scalable, from one module to some 16 or more modules. The main test function is sample output is listed below:

def main():
    initSpiBusNameListMode00Speed100kHz('SpiFiveBusNameList')
    testReadMfrc522RegByName('SpiBus10', 'VersionReg')
    testReadMfrc522RegByName('SpiBus11', 'VersionReg')
    return

Sample Output
Run fnfc310.py    
     Begin Execute Function testReadMfrc522RegByName  2020-04-07 21:08               
       Function Name                           = testReadMfrc522RegByName
       Spi Bus Name                            = SpiBus10
       Dev Reg Name                            = VersionReg
       Dev Reg Addr                            = 0x37
       Dev Reg Contents                        = 0x92
     End   Execute Function testReadMfrc522RegByName  2020-04-07 21:08
     Begin Execute Function testReadMfrc522RegByName  2020-04-07 21:08
       Function Name                           = testReadMfrc522RegByName
       Spi Bus Name                            = SpiBus11
       Dev Reg Name                            = VersionReg
       Dev Reg Addr                            = 0x37
       Dev Reg Contents                        = 0x12
     End   Execute Function testReadMfrc522RegByName  2020-04-07 21:08  

Appendix O – Tri MFRC522 Module Board

A practical guide to writing technical specs

tri module board


Appendix P – Multiple MFRC522 Board For Pair/Swap Troubleshooting

penta module


Appendix Q – Reviews on the Mario Gomez’ MFRC522-Python Library

(1) (a) 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. (b) Requirements: This code requires you to have SPI-Py installed from the following repository: https://github.com/lthiery/SPI-Py – Mario Gomez, README.MD, MFRC522-python, GitHub, 2014.

(2) With the software you have to trick a little, the instructions available on the net are somewhat outdated or refer to a particular Raspi. But if you have a little programming knowledge, you can quickly customize the Python program yourself. – Jürgen L 2020feb23 Appendix G – AZDelivery RFID Kit Reviews

(3) (a) There is no pull up/down for this module. According to the data sheet you would have to pull from high to low, … it would mean separating a trace through and pulling a wire bridge to GND. (b) The Python library, which I first found for the module, was unfortunately out of date and did not fit the SPI library. Since something had changed in the parameters for SPI read and Write. But the module can’t do anything for that. – Rene Winkler 2020mar03 Appendix G – AZDelivery RFID Kit Reviews


mario Gomez MFRC522 Library Warning


Appendix H – Mfrc522 Self Test Function

Now I am write test functions to make sure my module is more or test working OK.

self test function


Appendix I – Writing MFRC522 Commands in python3

Now I am reading the datasheet to learn how to write MFRC522 commands in python 3. I have written a python execMfrc522Command function and can now do ‘SoftReset” and ‘Idle’ with the two statements below:

execMfrc522Command('CommandReg', 'Reset')
execMfrc522Command('CommandReg', 'Idle')

command execution


Appendix J – Adding Python 3 Timer and Interrupt functions to Mario Gomez’s MFRC522 Python 2 Library

timer 10ms


End of Answer

——————————-

Chat Record

Discussion on question by 627117717.pr: Trying to code a RFID tag to a MFRC522 chip using raspberry pi but it is not allowing me to read it

Imported from a comment discussion on raspberrypi.stackexchange.com/questions/109773/…

Q: Trying to code a RFID tag to a MFRC522 chip using raspberry pi but it is not allowing me to read it

627117717.prTrying to read my RFID MFRC522 using a Mifare blue tag and it is not working. Wondering if i could get any help on this as when i put the tag to read it doesn’t show up as quick? using: pimylifeup.com/… medium.com/coinmonks/…

tlfong01

tlfong01
2898
I tried libnfc1.1.7 the other day and found it OK. I followed the instructions, setup in 15 minutes, and read a tag successfully. (1) “Problem with detecting badge with PN532 and Raspberry Pi“: stackoverflow.com/questions/60819793/… Perhaps you can try libnfc and let me know if you have any problems. I might also try the PiMyLifeUp and compared with your installation record.
By the way, you gave two tutorial references. The first one is OK. I think I would try that later. But the second tutorial seems a bit out of date, because it uses python 2.7. I worry that the drivers might not be compatible to your hardware/software configuration. Can you let us know your Rpi and OS version?
627117717.pr

627117717.pr
Hi mate my RPI is 3 and the os is rasbpian noobs using linux
Still not working unfortunately not sure why it is not working in the first place when i have followed each step and the modules all turn on and work!
tlfong01

tlfong01
2898
I didn’t catch you. Did you mean that an hour ago when you asked your question, you had no luck. Both tutorials didn’t work. But in this hour you tried your luck again and every step now work smoothly, and so NOW YOU CAN READ the tag? Can you please confirm which one of the two tutorials works, or both work. It would be nice if you can very briefly answer your question here, so that other newbies would be grateful to know how to setup the RFID reader? If every step work, but still cannot read the tag, I can repeat your steps and see why you still cannot read the tag. Cheers.
627117717.pr
627117717.pr
SO did each step by step the link you said i should try still NO LUCK still can not read or write the tags
tlfong01
tlfong01
Thank you for your clarification. So perhaps I can try your first tutorial. If no luck, then I can try the second tutorial. Wish me luck. Cheers.
627117717.pr
627117717.pr
Mar 29, 22:47
Ok that sounds good if your ok with that and if the tutorials work for you then must be something software or maybe hardware that is going wrong on my side!
tlfong01

tlfong01
2898
Well, I just finished reading the tutorial by Gus of PiMyLifeup, also skimmed the 70+ comments. I understand 90% what is going on, except the SPI library which seems not exactly the same library I am using. This might be one thing I might get stuck. Anyway, I am now starting to follow the tutorial, not step by step, but skipping steps and using not exactly the same tools. Eg, I will use Rpi4B buster Thonny IDE to edit and run the programs. (One reader commented using IDLE python 3, but IDLE is not longer available), / to continue, …
627117717.pr
627117717.pr
Thats fine i was using the Terminal to do everything in and the code coming from the pi up my life website just to see if it worked or not and as of yet still not working
tlfong01

tlfong01
2898
No problem. I can also use CLI bash, pip, nano etc for the preliminary setsup, and perhaps more GUI later. I am getting started with the PN532 module which I tested OK with I2C some time ago. Now I am switching from LibNfc library to PyMyLifeUp library.
Yesterday evening I already used “pip3” to install “mfrc522”. As I said earlier, I don’t know nothing about SPI-Py, so I did not use the newbie scary “git-clone” and “python setup” to install the SPI-Py module. I noticed that what you built is a python 2.7 SPI-Py module. But I started learning python already with Rpi IDLE python 3.5.3. So I am not going back to the old python 2.7. Just now I checked out that pip3 seems happy with pip3 installed GPIO, SpiDev, and mfrc522 requirements. So I am hopping that I don’t need SPI-Py and go straight to python programming.
627117717.pr

627117717.pr
11
HI have you had anymore luck in trying to use the mfrc522 module to see if it reads any tags by any chance as thats the one im more focussed on?
if the same outcome for the mfrc522 can be achieved like testing the tag pn532 nfc module that would be great as i still can get anything to read what so ever!
tlfong01

tlfong01
2898
No luck! Now I am googling to debug. I need to make sure a couple of things, including: (1) Must I use python 2? (2) Must I use SPI-Py and not buster preinstalled SPI? You might like to check out the following discussion: raspberrypi.org/forums/viewtopic.php?t=207328#p1282986. Ah, supper time, see you tomorrow.
I just found out that I have forgotten to make the reset pin connection. So my module is not reset to start working. There might be other careless mistakes.
I also found out that there are at least two mfrc522 gitHub library. Perhaps I ppip install the wrong library: github.com/mxgxw/MFRC522-python. Of there are other reasons, say the library is only for Rpi 2, 3, not for Rpi4 buster. I also check the source code that SPI speed is set to 10MHz, which is too high for my long wiring. I need to set SPI speed lower, perhaps 400kHz. In short, too many possible bugs. libnfc 1.1.7 is very smooth, it took me only less than 30 minutes. Perhaps I tried the SPI librnfc version to verify that SPI speed can be set to 10MHz.
I also read that PN532 old versions 1.x are not reliable. So everybody is using V3. Are you on V3?
The following also says must lower SPI frequency from 5MHz to 50kHz. That means PN532 cannot do high frequency: wiki.sunfounder.cc/….
Now I am thinking of going back to libnfc and test the spi version, to make sure both libnfc v1.1.7 I2C and SPI version are OK, then I will come back to do PyMyLifeUp SPI version. I am also configuring minimal number of SPI, I2C, and UART channels/ports.
627117717.pr
627117717.pr
Mar 29, 22:47
Sounds good the libnfc version is looking good so far hopefully the same will work for the mfrc522 chip and tags
13 hours later…
tlfong01

tlfong01
2898
Mar 30, 11:42
I am still debugging. About SPI Py, my quick and dirty conclusion is that it is an old thing, developed 7 years ago, in the Rpi2, python 2.7 days. Gus’s tutorial started 2017, so he might use SPI Py which is universal for the general Rpi users.
Please let me know if you know a reason that we must use PI Py and python 2.7. Otherwise I will still try pip3 mfrc522 and python 3. I am also using Version 3 module. I will also try the Blue PCB Version 1, just to make sure yours V1 module is not working.
Your question says: “read RFID MFRC522 Mifare blue tag not working. … when i put the tag to read it doesn’t show up as quick?” (1) To read quick, you need to use the module interrupt output signal to interrupt Rpi, otherwise loop scanning might be slow,
(2) But your problem is not quick or slow, because the module might be reset/ setup ready to read, or your tag is bad. I forgot to wire the module reset wire to Rpi, so this might be a bug, among other more possible bugs. So I am going to wire “interrupt” and “reset” between Rpi and the NFC module. See you later.
tlfong01

tlfong01
2898
Mar 30, 12:21
Now I am reading the following tutorial to learn how to connect the Reset pin. I found that the signal Low power downs the modules, and Rising Edge resets the module. In other words, I can just connect a jumper wire to manually reset the module. It is a bit confusing if I can leave the Reset pin floating. I need to check the schematic to see if this pin is pulled high.
user image
Sorry, I forgot to include the web link in the above comment. Here it is: “What is RFID? How It Works? Interface RC522 RFID Module with Arduino”:
lastminuteengineers.com/….
The LatMinuteEngineers’s colourful MiFare Classic 1k memory map is also very good to refresh my memory.
user image
4 hours later…
tlfong01

tlfong01
2898
Mar 30, 16:27
Now I am going to look at the SimpleMFRC522.py library module, add debug print statements for debugging.
user image
627117717.pr

627117717.pr
11
Mar 30, 17:18
@tlfong01 Hi would preferably want to use python 3 instead of 2.7, just really want to see if it works on your side so if it does i can see where i am going wrong and to basically use this a basis and manipulate the code for the mini project i am doing.
for me personally i just want to know the reason why it isnt working becasue even purchasing a brand new module and tags the same output is coming up you see
The mfrc522 modules are on and working i think, the tags dont read or even write when being placed near the chip and the code and wiring is copied exactly from the website and struggling to find where the error could be unless like you said i coul have missed parts out or the blue tags dont work.
quite new to this thing python and the raspberry pi just want to get to the bottom of this!! appreciate you helping out by the way !!
tlfong01

tlfong01
2898
Mar 30, 17:57
@627117717.pr Just quick random comments. (1) python 2.7 supported is ending this year 2020. So there is no point trying to debug python 2.7 programs. (2) You seem to have installed python 2.7 compatible SpiDev and SPIPy and perhaps also pip2/git/clone python 2.7 version of mfrc522. That is why I skipped Your or Gus first instructions to install SPI Py and SpiDev. I only use pip3 to install mfrc522.
Since lsmod spi says spidev and spi_bcm2835 are installed, so SPI part should be OK. pip3 install update also says the other installed modules are OK. So I guess I can do everything in python 3. Actually use bash to open python 3 shell and can import mfrc522 without problem, so I think there is 90% chance I can move on to look at the mfrc522 library to see how to debug.
I found the main library/module is only 400 lines of python statements, and seems well documented, so it should be easy to do minor fixes, such as lowering SPI speed from 1MHz to 50kHz and so on. I am not going to move the main library mfrc500.py and the SimplePI speed from 1MHz to 50kHz and so on. I am not going to make a copy of the main library mfrc500.py and the smaller, 100 lines SimpleMFRC522 in a penzu reading log file and make more newbie comments.
If you don’t have much experience in Rpi and python, then perhaps you can just sit back and watch what I am messing around. But you are welcome to make suggestions, such as preferring python 3 and not python 2.7.
tlfong01

tlfong01
2898
Mar 30, 18:18
@627117717.pr This penzu programming log file has the mfrc522 library (actually just a 400 line python program) and the SimpleMfrc522 (about 100 lines) . You can easily find the SPI speed setting in the main class. So it is easy to hack. Penzu programming log: penzu.com/p/08d4fdf2. Ah supper time! So see you late this evening or tomorrow.
1 hour later…
627117717.pr
627117717.pr
Mar 30, 19:43
thats great sounds like a plan hopefully can get this working asap
2 hours later…
tlfong01

tlfong01
2898
Mar 30, 21:44
@627117717.pr Ah, I am just a nfc newbie, scrapping the surface. So far I only have luck with libnfc-1.7.1 in I2C config. I am trying the other config, SPI. and UART, but I found things about SPI I don’t understand, so it might take me days to google to learn more about SPI. For SimpleMFRC522, I am googling to learn more, before I really starts. By the way, I read the following Q&A and saw a guy using SimpleMFRC, but I don’t know he ahs any problem with the SPI speed.
Anyway, if you have a tight deadline, then try libnfc I2C mode, because I have given the answer in the stackOverflow forum. Or google around harder.
This is the guy who had luck using SimpleMRFC: raspberrypi.stackexchange.com/….
tlfong01
tlfong01
Mar 30, 22:12
I searched this forum for SimpleMRFC and found 11 results. Other forums might have many more we can read and learn something.
2 hours later…
627117717.pr
627117717.pr
Mar 30, 23:48
nice one will look for sure
10 hours later…
tlfong01

tlfong01
2898
Mar 31, 9:19
I read your question a second time. It appears that you were following two tutorials at the same time, the first one using python 3, second one python 2.7. One tutorial uses SpiPy, and compiled SpiDev, the other does not. I am not sure if you are also using pip/pip2/pip3 at the same time.
If you use pip2 first, the buster might set default to python 2 envrionment. Then if you use pip3 later, the piped drivers might go to the python 2 rooms, causing big mess, or a small dark hole, where garbage goes in will stuck and never come out. So I would suggest the following. Get two unwanted uSD cards, flash new buster, one for buster all preinstalled python 3, pip 3, spidev, only installed is pip 3 install mfrc522.
The above is what I did and summarized in this chat. Now you are in sync with my current configuration. And if you get stuck again, like a reading problem, then I can repeat your situation and program. The SimpleMFRC522 tutorial seem to write first and then read later. But you seem to skip the write part and jump to read part. I need to make sure if the write part does init something that is assumed in the following read part, …
In the mean time, I would study the 400 line MFRC522 library and the 100 line SimpleMFRC program, to see what print statements can be inserted to help debugging.
7 hours later…
627117717.pr
627117717.pr
Mar 31, 16:43
When looking at the simplemfrc522 and mfrc522 code both dont seem to print the output after trying to read the tag but does before i.e “place tag to scan” and ‘new data’ where youd type it in
tlfong01
tlfong01
Mar 31, 17:15
Ah, I have not yet started looking at the code. I need to catch up now.
627117717.pr
627117717.pr
OK thats good hopefully if we get this done asap can find where maybe i am going wrong maybe even a simple error on my part but grateful for the help!!!
tlfong01

tlfong01
2898
Mar 31, 18:04
Ah, take it easy. I am a slow guy, walking slowly in a locking down city. I just finished a quick reading of the two big program and found it simple. The reading log is here:
Ah, supper time! See you late this evening or tomorrow. Cheers.
627117717.pr
627117717.pr
No problem
4 hours later…
tlfong01

tlfong01
2898
Mar 31, 21:39
Now I am zooming in to the critical functions to see where to insert the print statements for debugging. Perhaps we can start with the Write.py program, trace it to as you said, around “where place tag to scan … and new data where you type it in …” I have now made a short listing to show where to insert the print statements:
This is the short listing: penzu.com/p/585c2995. You might trace the simpleMRFC522()’s read function back to the m\mrfc522’s read function which use the low level SPI functions. If the read steps get stuck at the SPI functions, then perhaps (1) Your SPI hardware wiring is bad, or (2) SpiDev is not compaitble to the MRFC module. I think (2) is unlikely. (3) You mixed up python 2 spidev tools with python 3 mrfc modules.
627117717.pr
627117717.pr
ok great where would that be because all im doing is copying a pasting the code from “PI UP MY LIFE” and adding it in to the sudo nano read.py or write.py
tlfong01

tlfong01
2898
I suggest you and me doing the following to debuig: (1) BACKUP a couple of micro SD card copies for messing up testing (Note 1). (2) run the Read.py again, inserting print statements when tracing back to where it hangs. (3) If anytime you suspect the spi hardware and software setup is bad, you need to do the SPI LOOP BACK test (I already did it to make sure it is the cause of trouble. Note 1- You know how to use Rpi GUI accessories > SD copier to make back up copies, don’t you?
Ah the simpleMFRC532 and the mrfc532 programs are located in the following directory:/usr/local/lib/python3.7 …, but is you used git/clone, or pip 2, then it might be in /usr/local/lib/python2.7, not very sure. Let me show you the picture again.
user image
This picture is sort of “cheat sheet”. The top dark/black part helps to make sure the right tools are in the right places. The bottom white part shows where are the two most important programs you are going to insert the debug print statement. Of course you the newbie will mess up things:( That is why I said you must make backup SD cards. Of course you also can back up the programs inside the directory.
Actually for initial testing, you can still use your current python 2.7 tools. Since you can do the last two statements “import simple…” reader = … , that means your python 2.7 setup is also OK, perhaps it is only your SPI wiring is bad, …
Ah bed time! I call it a day. Good luck and see you tomorrow.
tlfong01

tlfong01
2898
Mar 31, 22:17
Two more things: (1) If you are weak in Rpi and python, AND your schedule is tight, you might like to consider (a) libnfc-1.71. I2C mode, which I found OK, (b) Arduino library, which is very mature and easy to find support, (c) Buy more boards to stand by and/or cross check. Reference: Arduino library for MFRC522
github.com/miguelbalboa/rfid

Before buy:

Please notice that there are many sellers (ebay, aliexpress, ..) who sell mfrc522 boards. The quality of these boards are extremely different. Some are soldered with wrong/low quality capacitors or fake/defect mfrc522.

(see full text)

Good luck and cheers.
13 hours later…
tlfong01

tlfong01
2898
Apr 1, 11:44
@627117717.pr So we can debug the Read.py on both sides, you python2.7, me python 3.7. The trick is just insert print and pause statements at breakpoints of sampleMfrc532 and mfrc532 and see if the program is stuck and hangs/freezes at the low level SPI read functions.
If it is indeed the case, then we need to debug SPI by first using the LOOPBACK method, just to make sure if (a) spiDev and python are compatible, (b) if hardware wiring are correct (Note: MOSI and MISO must crossover). You can search “SPI Loopback” in this and other forums for more details. Below are some posts you might like to start with.
SPI Loopback references: (1) SPI Loopback Test – rpi.org 2019
raspberrypi.org/documentation/…

(2) SPI Loopback Test using Python (See Appendix C for the python program) – rpi.stackexchange 2019
raspberrypi.stackexchange.com/…

(3) SPI Loopback Test (struct spi_ioc_transfer level) – rpi.org forum 2019
raspberrypi.org/forums/…

(see full text)

3 hours later…
tlfong01

tlfong01
2898
Apr 1, 14:33
So I have done the SPI loop back test OK.
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
2898
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.
627117717.pr

627117717.pr
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
2898
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
2898
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
2898
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
2898
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
2898
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
2898
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
2898
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
2898
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
2898
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
2898
Apr 4, 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
2898
Apr 4, 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
2898
Apr 4, 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
Apr 5, 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
2898
Apr 5, 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
2898
Apr 5, 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
2898
Apr 5, 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
Apr 5, 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
Apr 7, 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
2898
Apr 7, 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
2898
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
Thu 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
2898
Thu 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
Thu 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
Thu 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
2898
Thu 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
2898
Fri 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
2898
Fri 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
Fri 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
Fri 19:00
(removed)
3 hours later…
tlfong01

tlfong01
2898
Fri 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. Cheers.
19 hours later…
627117717.pr
627117717.pr
Sat 17:31
ok mate no worries as i have a deadline soon may have to explore new routes on this
but i really apprieate all your work and 100% have learnt more with your help
tlfong01

tlfong01
2898
Sat 17:59
@627117717.pr Ah, sorry to hear that you might be missing your deadline. On the other hand, I did have a pleasant surprise that, as a newbie in Rpi, and python, you are learning fast, in this a bit over ambitious project. As I said, I am a slow guys, still going slowly. I think there is 50% chance that I would digest Mario Gomez’s difficult to understand code, and rewrite my own newbie friendly version.
So you might come back perhaps 3 months from now to see if I have written a newbie friendly version for future visitors. Best wishes to your new projects. Cheers.
The last message was posted 3 days ago.
tlfong01  2020apr14hkt0948
.END

 

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.

%d bloggers like this: