I am a complete newbie with Raspberry Pi and any type of hardware prototyping. I have been trying to get a Parallax RFID working with my Pi 3.
I currently have it wired to the GPIO using BCM and the following pins
VCC -> 5V
/Enable -> Pin 4
SOUT -> Pin 15
GND -> GND
I then use a python script:
import RPi.GPIO as GPIO
import serial
ENABLE_PIN = 4 # The BCM pin number corresponding to GPIO1
SERIAL_PORT = '/dev/ttyAMA0' # The location of our serial port. This may
# vary depending on OS version.
def validate_rfid(code):
# A valid code will be 12 characters long with the first char being
# a line feed and the last c har being a carriage return.
s = code.decode("ascii")
print(s)
if (len(s) == 12) and (s[0] == "\n") and (s[11] == "\r"):
# We matched a valid code. Strip off the "\n" and "\r" and just
# return the RFID code.
return s[1:-1]
else:
# We didn't match a valid code, so return False.
return False
def main():
# Initialize the Raspberry Pi by quashing any warnings and telling it
# we're going to use the BCM pin numbering scheme.
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
# This pin corresponds to GPIO1, which we'll use to turn the RFID
# reader on and off with.
GPIO.setup(ENABLE_PIN, GPIO.OUT)
# Setting the pin to LOW will turn the reader on. You should notice
# the green LED light on the reader turn red if successfully enabled.
print("Enabling RFID reader...\n")
GPIO.output(ENABLE_PIN, GPIO.LOW)
# Set up the serial port as per the Parallax reader's datasheet.
ser = serial.Serial(baudrate = 2400,
bytesize = serial.EIGHTBITS,
parity = serial.PARITY_NONE,
port = SERIAL_PORT,
stopbits = serial.STOPBITS_ONE,
timeout = 1)
# Wrap everything in a try block to catch any exceptions.
try:
# Loop forever, or until CTRL-C is pressed.
while 1:
# Read in 12 bytes from the serial port.
data = ser.read(12)
# Attempt to validate the data we just read.
code = validate_rfid(data)
# If validate_rfid() returned a code, display it.
if code:
print("Read RFID code: " + code);
except Exception:
# If we caught an exception, then disable the reader by setting
# the pin to HIGH, then exit.
print ("Couldn't do it: %s" % e)
print("Disabling RFID reader...")
GPIO.output(ENABLE_PIN, GPIO.HIGH)
if __name__ == "__main__":
main()
The script runs and shows "Enabling RFID reader..." and then nothing when I pass chips in front of the reader.
I have ensured that Serial is enabled in config and I have tried both /dev/ttyAMA0 and /dev/ttyS0 (as I have read that ttyS0 is for Pi 3s)
I have tried multiple RFID cards that I got from Parallax for testing, and a couple cards from around the office that I know work with other readers.
I am at a loss on where to go from here. Any help or pointers would be greatly appreciated.
UPDATE: I found information about changing the /boot/cmdline.txt to remove "console=serial0,115200" so I did. This did not change the results.