1

Here are the three components that I have, in addition to Pi rev. A.

Parallax RFID Reader: http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/rfid/List/1/ProductID/114/Default.aspx?SortField=ProductName%2CProductName

Adafruit logic level converter: http://www.adafruit.com/products/757

Adafruit breakout board: http://www.adafruit.com/products/1105

And is wired up with 5V on the parallax side and 3.3 on the Pi side, with power being supplied by the breakout board.

The following python (3.3) code is used:

    import serial

    try:
            ser = serial.Serial('/dev/ttyAMA0', 2400, timeout=0.1)
            print("opened {0}" . format(ser.name))
            while True:
                    try:
                            sr = ser.read(12)
                            s = sr.decode('utf8')
                            if len(s) == 0:
                                    continue
                            else:
                                    sl = s[1:11] #exclude start x0A and stop x0D bytes
                                    print(sl)

                    except Exception as e:
                            print("error: {0}" . format(e))
            print("closing...")
            ser.close()
    except Exception as e:
            print("error: {0}" . format(e))

When I run the script, it reads the first tag just fine. And then it stops there, any subsequent tries are not read, and the script just loops on.

I set up the OS (Arch) according to this http://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/freeing-uart-on-the-pi section of that tutorial, obviously setting no restart in the systemd config and not the inittab.

Any thoughts?

Andrew Sledge
  • 131
  • 1
  • 5

1 Answers1

2

This is what worked. Check for an in wait status and then flush the input buffers.

import serial
import time

serial = serial.Serial("/dev/ttyAMA0", baudrate=2400)
while True:
    if serial.inWaiting() > 0:
        read_result = serial.read(12)
        print("Read card {0}" . format(read_result.decode(encoding='utf-8')))
        print("Sleeping 2 seconds")
        time.sleep(2)
        serial.flushInput() # ignore errors, no data
Andrew Sledge
  • 131
  • 1
  • 5