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?

Jakov
  • 183
  • 2
  • 5
  • 14

1 Answers1

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

Jakov
  • 183
  • 2
  • 5
  • 14