0

I am trying to read RFID code from RFID reader by using RPI.

This is my code:

import serial
from time import sleep
import  RPi.GPIO as GPIO

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

GPIO.setup(11,GPIO.OUT)

ser = serial.Serial("/dev/serial0",9600,timeout=None)

while True:
    received_data = ser.read()
    sleep(0.1)
    data_left = ser.inWaiting()
    received_data += ser.read(data_left)
    print (received_data)

Expected result after I put RFID tag on INSIDE or OUTSIDE reader is "INSIDE: 23,192,251,159,179" or "OUTSIDE: 23,192,251,159,179".

After I run this code, and put tag on reader, firstly I get some strange signs and afterwards sometimes I get desired result and sometimes I get empty line. After I put tag for several times, I get error.

Here is my output:

    ������������������������������������������������������������������������������������
���x��x��x<�x�x�x����������x�x��x������x����x��x���x�x��x��x���x�x�����x��x���x�
x��x��x��x<�x�x�x����������x�x��x������x����x��x���x�x��x��x���x�x�����x��x���x�
9M%�'�bʒb&��b��b��jR�




INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179






INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179






INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179






INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179


INSIDE:23,192,251,159,179






Traceback (most recent call last):
  File "ACv1.0.py", line 13, in <module>
    received_data = ser.read()
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 501, in read
    'device reports readiness to read but returned no data '
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

Can someone tell me how to fix this?

  • 2
    Do you get output when using a serial terminal program (minicom, picocom, etc) instead of your python script? And did you disable the serial console in raspi-config? – Dirk Apr 27 at 14:45
  • 1
    Ah let me see. Usually you need to use a SPI/I2C/UART driver to control the NFC/RFID reader. Are you using MFRC522 or PN532? If yes, you can read my answers on how I use the drivers: (1) raspberrypi.stackexchange.com/questions/109773/…, (2) stackoverflow.com/questions/60819793/…, (3) stackoverflow.com/questions/61165652/…. I vaguely remember that AdaFruit is using one of those drivers, but not very sure. – tlfong01 Apr 27 at 15:06
  • I enabled SPI, btw I installed Buster instead of Jessie and tried the same script, but got different results. You can see it in edited post. – Jakov Kusić Apr 27 at 16:28
  • Please let us know which RFID device (eg MFRC522 or PN532 etc) and which "script" you are using, and the link to the tutorial you are following. You might like to read Appendix E of my answer to the following question, to find WaveShare's demo UART code to check if the RFID device is basically working. (1) "How can Rpi read a PN532 NFC Module?" stackoverflow.com/questions/61165652/…. Cheers. – tlfong01 Apr 28 at 2:24
  • Well, my MFRC522 RFID experiment referred above also uses SPI Rpi4B buster. I found the following tutorial also good: raspberrypi.stackexchange.com/questions/23939/… – tlfong01 Apr 28 at 5:36
0

Here is the solution.

"To manually change the settings, edit the kernel command line with sudo nano /boot/cmdline.txt. Find the console entry that refers to the serial0 device, and remove it, including the baud rate setting. It will look something like console=serial0,115200. Make sure the rest of the line remains the same, as errors in this configuration can stop the Raspberry Pi from booting."

Just this line needed to be edited.

Here is link https://www.raspberrypi.org/documentation/configuration/uart.md

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.