devmattm
Posts: 7
Joined: Wed Jun 12, 2019 12:39 pm

Running 3 RC522 side by side continuously

Wed Jun 12, 2019 11:59 pm

So, here's a synopsis of what I am trying to do. I want to put 3 RC522 RFID readers side by side inside of a book facing the cover that will be constantly on. When an RFID chip gets waved over the book, I want any module to read it, send the RFID tag number over to the code, and then I will perform whatever task I want (mostly playing a short audio clip, and the RFID reading will be paused while the code executes). Then, the next RFID tag will be waved over, rinse and repeat. I am building this for the average user and want to make it super easy for the chip to be detected wherever on the book cover it is placed, hence three modules. I am not worried about multiple RFID tags being in the sensor at the same time, so collision isn't a huge concern.

So far, I have one RFID module running just fine via SPI1 and the MFRC522.py library. It scans, returns the number and everything is good.
I then connected two/ three modules using the spi1-3cs overlay. I sort of understand that the chip select pin will enable/disable as I go, if I want to do that.

I tried running two RC522 on one chip select CE0, and it worked-ish. It through more errors than solo, but overall worked. When I connected a third to the same CE0 pin, none of them worked, which I suspect might be a power issue. I am in the process of wiring the 5v output and converting it to 3.3v.
But, I'm not sure this is the right way to do this. Am I doing this at all right?

User avatar
topguy
Posts: 5780
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 9:01 am

I would normally not advice to put NFC readers that close to each other, because their RF fields will interfere with each other. Even if the reading distance is 3-4 cm the actual antenna field is much larger.

But if you only need the UID of each card ( and not read or write data ) there is a better chance you will have a success.

devmattm
Posts: 7
Joined: Wed Jun 12, 2019 12:39 pm

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 11:58 am

Thank you for your reply. Yes, I will have written to them already, it's really just to read the UID. In the code, I am going to use that ID as a key in a dictionary and lookup a sound file path ie: {'12345678': '/user/me/files/sound.wav'}. This is a small project for a prop I am making for my upcoming wedding, so I'm not looking for long term or even necessarily efficient, but mostly just functional.

Does having all the RC522 modules on the same select pin work for my idea? But, now that you have explicitly separated reading the chip vs getting the UID - those are different functions? I assumed a read was a read whether or not I wanted the extra text.

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 1:54 pm

Use a chip select different for each RC522 readers. You will need to check each device on the same application or run three different application by selecting different CHIP select or SPI modules.

The raspberry Pi has multiple SPI modules. Check the /boot/overlays/README for more information.

User avatar
topguy
Posts: 5780
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 1:55 pm

I know nothing about SPI so I cant comment on that.

The UID is something you get from the card as part of "anti-collision" when initializing communication with the card. You usually dont need to send any higher level "commands" to the card to receive it.

devmattm
Posts: 7
Joined: Wed Jun 12, 2019 12:39 pm

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 3:20 pm

@Dan, thank you for the idea to run three separate applications. And I am using the SPI1-3CS overlay to open the 3 SPI selects. I suppose I can write a script to run 3 subprocesses and watch for output and continually loop. When a tag is picked up, do I need to do any sort of reset or will it just keep reading forever?
If I wanted to check each device on the same application, I guess I would have to just loop through each chip select every 50 ms or so (based on research that it takes about 50 ms to read). Does that sound right?

@topguy ok, thanks for that. I will look into the anticollision code that's part of the library I am using and see if I can just get the ID without fussing with other stuff. That'll probably improve a few things.

User avatar
topguy
Posts: 5780
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 4:18 pm

devmattm wrote:
Thu Jun 13, 2019 3:20 pm
@topguy ok, thanks for that. I will look into the anticollision code that's part of the library I am using and see if I can just get the ID without fussing with other stuff.
And which library is that ?

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 4:35 pm

If I wanted to check each device on the same application, I guess I would have to just loop through each chip select every 50 ms or so (based on research that it takes about 50 ms to read). Does that sound right?
Just check the read function if the serial ID change. if it does then act on it. You don't need to reset just keep reading!

I made a change on the MFRC522-python to be compatible with python3 and be able to read the 7 and 10 bytes mifare cards.

Also I got rid of the GPIO module and replace the spi by the spidev module.

https://github.com/danjperron/MFRC522-python

devmattm
Posts: 7
Joined: Wed Jun 12, 2019 12:39 pm

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 5:14 pm

@topguy sorry, should've clarified - the MFRC522-python library.

@dan awesome, I will clone your code tonight and see what I can do with it, thanks for sharing. I'll have to add the SPI1 chip select stuff, but I've already done most of that once, so that's pretty easy. I'll then create 3 instances of the MFRC522 class, each with their specific chip select, and run them in the same fashion as you have.

User avatar
mikronauts
Posts: 2722
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Running 3 RC522 side by side continuously

Thu Jun 13, 2019 5:20 pm

Easiest:

- get three usb ttl adapters (or 2 plus pi gpio serial)
- mod rc522 for serial instead of spi
- use a separate thread per port

See

https://forum.arduino.cc/index.php?topic=442750.0

On modding

devmattm wrote:
Wed Jun 12, 2019 11:59 pm
So, here's a synopsis of what I am trying to do. I want to put 3 RC522 RFID readers side by side inside of a book facing the cover that will be constantly on. When an RFID chip gets waved over the book, I want any module to read it, send the RFID tag number over to the code, and then I will perform whatever task I want (mostly playing a short audio clip, and the RFID reading will be paused while the code executes). Then, the next RFID tag will be waved over, rinse and repeat. I am building this for the average user and want to make it super easy for the chip to be detected wherever on the book cover it is placed, hence three modules. I am not worried about multiple RFID tags being in the sensor at the same time, so collision isn't a huge concern.

So far, I have one RFID module running just fine via SPI1 and the MFRC522.py library. It scans, returns the number and everything is good.
I then connected two/ three modules using the spi1-3cs overlay. I sort of understand that the chip select pin will enable/disable as I go, if I want to do that.

I tried running two RC522 on one chip select CE0, and it worked-ish. It through more errors than solo, but overall worked. When I connected a third to the same CE0 pin, none of them worked, which I suspect might be a power issue. I am in the process of wiring the 5v output and converting it to 3.3v.
But, I'm not sure this is the right way to do this. Am I doing this at all right?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

devmattm
Posts: 7
Joined: Wed Jun 12, 2019 12:39 pm

Re: Running 3 RC522 side by side continuously

Sun Jun 16, 2019 3:57 pm

Well I posted this as a new thread in troubleshooting, but it got removed and I'm not sure why.

Anyways, I got the code to work, and I can run any two of my RC522 together. However, the moment I even just wire the third one in, everything stops working - the two working RFID modules no longer read or do anything besides light up.
I've tried wiring up the third on a separate power source which didn't help. I've rewired the whole thing, and still nothing. I'm not sure what's causing this.

Any ideas?

User avatar
mikronauts
Posts: 2722
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Running 3 RC522 side by side continuously

Sun Jun 16, 2019 4:53 pm

Best guess: insufficient power
devmattm wrote:
Sun Jun 16, 2019 3:57 pm
Well I posted this as a new thread in troubleshooting, but it got removed and I'm not sure why.

Anyways, I got the code to work, and I can run any two of my RC522 together. However, the moment I even just wire the third one in, everything stops working - the two working RFID modules no longer read or do anything besides light up.
I've tried wiring up the third on a separate power source which didn't help. I've rewired the whole thing, and still nothing. I'm not sure what's causing this.

Any ideas?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
rpdom
Posts: 15212
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Running 3 RC522 side by side continuously

Sun Jun 16, 2019 5:57 pm

devmattm wrote:
Sun Jun 16, 2019 3:57 pm
Well I posted this as a new thread in troubleshooting, but it got removed and I'm not sure why.
Because duplicate threads are against forum rules.

If you think your post is in the wrong forum you can report your own post to the moderators and ask for it to be moved. They would much prefer to do that than have to keep deleting duplicates all over the place. Also, it makes sense to keep it all in one thread.

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Running 3 RC522 side by side continuously

Sun Jun 16, 2019 6:17 pm

I'm with mikronauts,

Use a LE33cz or any low drop 3.3v regulator connected to the 5V to power your RC-522 device.

devmattm
Posts: 7
Joined: Wed Jun 12, 2019 12:39 pm

Re: Running 3 RC522 side by side continuously

Sun Jun 16, 2019 7:32 pm

I've made some progress. I don't think it was power after I connected one module to a whole other power supply, I still had issues.
I came across this post: https://forum.arduino.cc/index.php?topic=477085.0 which pretty much says that there may be too much noise on the line. What I did to get it to work is put one of the readers on SPI0 and two on SPI1. Now all three work at the same time. I then wrote code to thread each of their read processes so all three are just sitting there reading the ID of each chip that gets close. I think I'm in the home stretch now.

Return to “General discussion”