I have a RPi2 (Python 2.7) with two RFID readers. One reader is an USB SERIAL hex Gigatek MF7 (connected to a serial port) and the other is the RFID-RC522 (connected to GPIO pins). The RC522 is wired correctly following the instructions found on pimylifeup.com/raspberry-pi-rfid-rc522. Both readers work and read tags but their output strings are different for the same tag.
I know the data structure (Serial ASCII) and baud Rate: 9600,N,8,1, to read from the Gigatek - link. My script reads the 12 char string from a serial port and extracts the UID reply_rfid_1[1:9]
from it:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Convenient python function to read RFID tags with GIGATEK MF7
"""
############################
#from collections import defaultdict
#import csv
import sys
import serial
import time
from datetime import datetime
# define variables
global value_rfid, reply_rfid, refTime
# assign values
refTime = datetime.now()
# open the serial port /dev/ttyUSB1 and check if the port is really open
rfid_port_1 = serial.Serial("/dev/ttyUSB1", 9600) # omit if not in use
print 'rfid_read.py -> rfid reader on port', rfid_port_1.name
rfid_port_1.isOpen()
def Read_Tag():
# define variables
global value_rfid_1, reply_rfid_1, tag
# read port
while int((datetime.now()-refTime).seconds) < 5:
if (rfid_port_1.inWaiting() > 0):
reply_rfid_1 = rfid_port_1.read(12)
value_rfid_1 = str(reply_rfid_1[1:9])
tag = str(value_rfid_1)
print 'rfid_read.py -> tag hex', tag
tag = int(tag, 16)
print 'rfid_read.py -> tag dec ', tag
break
else:
tag = None
return tag
def Output_Tag():
if tag == None:
print 'rfid_read.py -> no tag'
def Flush_Port():
rfid_port_1.flushInput() # Clear input buffer
time.sleep(0.1)
Read_Tag()
Output_Tag()
Flush_Port()
exit()
To read from the RC522 i use the code below:
reader = SimpleMFRC522()
print("Hold a tag near the reader")
try:
id, text = reader.read()
print(id)
print(text)
finally:
GPIO.cleanup()
I can determine the length and numeric format of the string coming out of the SERIAL reader but I can not do it for RC522. I found some info about the libraries on these pages github.com/mxgxw/MFRC522-python, github.com/pimylifeup/MFRC522-python but could not decipher the data structure of the output block and I would really appreciate some help on this matter.
UPDATE 1. 7. 2019
As suggested below are the two outputs and the SPI status.
The output of the USB reader is in HEX and DEC numerical format:
rfid_read.py -> rfid reader on port /dev/ttyUSB1
rfid_read.py -> tag hex AC8C5E0A
rfid_read.py -> tag dec 2894880266
The output of the RC522 reader for the same TAG is:
Hold a tag near the reader
44535950452
The SPI status:
pi@raspberrypi:~ $ lsmod | grep spi
spidev 20480 0
spi_bcm2835 20480 0
value_rfid = str(reply_rfid[1:8])
, right now you're adding a\r
to the tag number, I don't know if that's having an effect because you don't show the HEX to INT conversion on your code... – Marcos G.[1:8]
. – parovelb