1

I used the following code from this post

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

but still get the same problem as the original poster where the initial tag scan reads and any subsequent tries are unsuccessful

output is as follows with error:

Read card 04193DCBD7
Sleeping in 2 seconds
Read card                      # notice second read empty
Sleeping in 2 seconds
Traceback (most recent call last):
  File "/home/pi/Desktop/Test/TestRFID2.py", line 8, in <module>
   print("Read card {0}" . format(read_result.decode(encoding='utf-8')))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3: invalid start byte

Errors fall in different positions (i.e. 1, 2, or 3)

Have tried different scripts as well with same outcome. I have also disabled the serial console as described here.

My schematic with all connections

  • Is this a Pi 3 by any chance? – goldilocks Jun 13 '16 at 14:08
  • Yes it is, can you help? – Carl03 Jun 14 '16 at 6:21
  • Yep -- although physically the UART serial pins are in the same place as on every other model of Pi, on the 3 /dev/ttyAMA0 doesn't refer to them. See the answers on the duplicate question. Everything else should be the same. – goldilocks Jun 14 '16 at 10:37
  • @goldilocks I've changed the port to /dev/ttyS0 but now the UnicodeDecodeError appears immediately, how do I check the /boot/cmdline.txt file to make sure the console output is properly disabled for that node. Sorry but I am new to python and raspberry pi – Carl03 Jun 14 '16 at 11:58
  • If you aren't using the serial console (most people don't, IMO this is a strange choice made by Raspbian and/or the Pi Foundation), the easiest way to disable it is probably via raspi-config. The two components are the reference in cmdline.txt (the only mention of a console there should be console=tty1, make sure afterward) and the spawning of a terminal line by the init system, which on jessie systemctl disable serial-getty@ttyS0.service should get rid of... – goldilocks Jun 14 '16 at 12:06
0

Besides changing changing the port from /dev/ttyAMA0 to /dev/ttyS0 because the default device node for the Pi 3 is different.

I figured out what my problem was and it lies within the config.txt file, I added the line enable_uart=1, this will enable the device itself. Tested it and it works 100% for me.

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.