尝试将两个 MFRC522 阅读器与一个 Raspberry Pi 3 一起使用 [英] Trying to use two MFRC522 readers with one Raspberry Pi 3

查看:96
本文介绍了尝试将两个 MFRC522 阅读器与一个 Raspberry Pi 3 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让两个 MFRC522 读卡器与 Raspberry Pi 3 B 型读卡器一起使用.我开始使用 pi my life up 教程来让一个读卡器工作,并且效果很好.为了获得第二个,我尝试了在 github 中找到的几个不同的 repos,但没有一个起作用.我有点能够让两者都阅读,但它的行为很奇怪.状态始终为 MI_ERR,但它会读取卡.我看到的其他问题是它随机显示不同的 uid,当我将标签放在卡 1 上时,它会指示已读取卡 2.下面是引脚配置和我的代码.请注意,每个 MFRC522.py 已更新以指示 NRSTPD 的引脚 15 或 22.任何帮助将不胜感激.

I'm trying to get two MFRC522 readers to work with a Raspberry Pi 3 Model B. I started off using the pi my life up tutorial to get one working and it worked brilliantly. To get the second one going I tried a couple of different repos I found in github but none of them worked. I was sort of able to get both to read but it behaves oddly. The status is always MI_ERR but it will read the card. The other issues I'm seeing are it randomly displays a different uid and it will indicate card 2 is read when I'm putting the tag on card 1. Below is the pin configuration along with my code. Please note that each MFRC522.py was updated to indicate pin 15 or 22 for the NRSTPD. Any help would be greatly appreciated.

阅读器 13.3v = 引脚 1 RST = 引脚 15 GND = 引脚 9 MISO = 引脚 21 MOSI = 引脚 19 SCK = 引脚 23 SDA = 引脚 24

Reader 1 3.3v = Pin 1 RST = Pin 15 GND = Pin 9 MISO = Pin 21 MOSI = Pin 19 SCK = Pin 23 SDA = Pin 24

阅读器 23.3v = 引脚 1 RST = 引脚 22 GND = 引脚 9 MISO = 引脚 21 MOSI = 引脚 19 SCK = 引脚 23 SDA = 引脚 24

Reader 2 3.3v = Pin 1 RST = Pin 22 GND = Pin 9 MISO = Pin 21 MOSI = Pin 19 SCK = Pin 23 SDA = Pin 24

import RPi.GPIO as GPIO
import MFRC522_Chip2
import MFRC522
import signal

plate1 = [222, 86, 127, 87, 246]
plate2 = [86, 126, 214, 255, 87]

indicator1 = 0
indicator2 = 0

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

continue_reading = True

# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
    global continue_reading
    print "Ctrl+C captured, ending read."
    continue_reading = False
    GPIO.cleanup()

# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)

# Create an object of the class MFRC522
MIFAREReader_Chip2 = MFRC522_Chip2.MFRC522()

# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()

# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."

# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:

    # Scan for chip 1   
    (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

    #print (status)

    # If a card is found
    if status == MIFAREReader.MI_OK:
        print ("Card 1 detected")
        # Get the UID of the card
        (status,uid) = MIFAREReader.MFRC522_Anticoll()

        if indicator1 == 1:
            GPIO.setup(12, GPIO.OUT)
            GPIO.output(12, GPIO.LOW)
            print ("!")
        else:
            GPIO.setup(12, GPIO.OUT)
            GPIO.output(12, GPIO.HIGH)

        indicator1 = 0

        print (uid)

        # If we have the UID, continue
        if status == MIFAREReader.MI_OK:
            if uid[:5] == plate1:
                print ("Plate 1 in position")
                indicator1 = 1
            else:
                ("Find plate 1")
                indiator1 = 0

    # Scan for chip 2   
    (status,TagType) = MIFAREReader_Chip2.MFRC522_Request(MIFAREReader_Chip2.PICC_REQIDL)

    #print (status)

    # If a card is found
    if status == MIFAREReader_Chip2.MI_OK:
        print ("Card 2 detected")
        # Get the UID of the card
        (status,uid) = MIFAREReader_Chip2.MFRC522_Anticoll()

        if indicator2 == 1:
            GPIO.setup(16, GPIO.OUT)
            GPIO.output(16, GPIO.LOW)
            print ("?")
        else:
            GPIO.setup(16, GPIO.OUT)
            GPIO.output(16, GPIO.HIGH)

        indicator2 = 0

        print (uid)

        #If we have the UID, continue
        if status == MIFAREReader_Chip2.MI_OK:

            if status == MIFAREReader.MI_ERR:
                if uid[:5] == plate2:
                    print ("Plate 2 in position")
                    indicator2 = 1
                else:
                    print("Find plate 2")
                    indiator2 = 0

推荐答案

请按照以下步骤操作:

1.首先,每个 RFID 阅读器的 SDA 引脚必须不同(使用引脚 24 和 12);

2. 在 Raspbiancmd"中输入:sudo nano/boot/config.txt 并添加此信息 dtoverlay = spi1-3cs(此行激活 Raspberry pin 12);

3. 使用 github MFRC522 库:https://github.com/YongxinLIAO/SmartFactoryRFID.git

4.为每个阅读器创建2个文件夹,每个文件夹必须有单独的库MFRC522;

5.在每个文件夹的库中,将RESET引脚更改为15,在另一个库中将RESET引脚更改为22;

6. 在MFRC522库中的spidev 0.0"行,留下一个reader,在另一个库中更改为spidev 1.0";

  1. First, the SDA pin must be different for each RFID reader (use pin 24 and 12);

  2. In Raspbian "cmd" type: sudo nano /boot/config.txt and add this information dtoverlay = spi1-3cs (this line activates Raspberry pin 12);

  3. Use the github MFRC522 library: https://github.com/YongxinLIAO/SmartFactoryRFID.git

  4. Create 2 folders for each reader, each folder must have a separate library MFRC522;

  5. In the library of each folder, change the RESET pin to 15 and in the other library change the RESET pin to 22;

  6. On the "spidev 0.0" line in the MFRC522 library, leave a reader like this and in the other library change to "spidev 1.0";  

我建议一次测试每个阅读器以避免出现重叠错误.

这篇关于尝试将两个 MFRC522 阅读器与一个 Raspberry Pi 3 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆