无法使用Raspberry PI从RDM6300读取RFID数据

2024-06-28 11:39:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我遵循这两个类似的指南,使用我的模块/pi读取RFID数据

当我试图从串口读取数据时,我的代码被卡住了。具体而言:

PortRF = serial.Serial('/dev/serial0',9600)
read_byte = PortRF.read()

我想这是因为我接线完全错了

他们建议的接线

在这两个站点之间,他们建议采用以下两种布线设置。我没有找平机

enter image description hereenter image description here

我试图接线

我不完全确定我是否做得对,但这是我当前的接线: enter image description here

Python代码

import serial
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

Tag1 = str('0000000C000C')
Tag2 = str('0000000C080C')
Tag3 = str('0000000C010C')
Tag4 = str('0000000C090C')
Tag5 = str('0000000C0A0C')
Tag6 = str('0000000C0D0C')
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.output(23,False)
GPIO.output(24,False)
PortRF = serial.Serial('/dev/serial0',9600)
PortRF.reset_input_buffer()
while True:
    ID = ""
    read_byte = PortRF.read()
    if read_byte=="\x02":
        for Counter in range(12):
            read_byte=PortRF.read()
            ID = ID + str(read_byte)
            print hex(ord( read_byte))
        print ID
        if ID == Tag1:
            print "White - Ashoka"
            GPIO.output(23,True)
            GPIO.output(24,False)
            PortRF.reset_input_buffer()
            time.sleep(5)
            GPIO.output(23,False)
        elif ID == Tag2:
            print "White - Chirutt"
            GPIO.output(23,True)
            GPIO.output(24,False)
            PortRF.reset_input_buffer()
            time.sleep(5)
            GPIO.output(23,False)
        elif ID == Tag3:
            print "Red - Vader"
            GPIO.output(23,True)
            GPIO.output(24,False)
            PortRF.reset_input_buffer()
            time.sleep(5)
            GPIO.output(23,False)
        else:
            GPIO.output(23,False)
            print "Access Denied"
            GPIO.output(24,True)
            PortRF.reset_input_buffer()
            time.sleep(5)
            GPIO.output(24,False)

Tags: idfalsetruereadinputoutputgpiotime