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

Carl03
  • 11
  • 5
  • 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 06: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
  • ...But try raspi-config first, it will probably work. I am not sure exactly where the option is but I think on the front menu. There is no so much stuff there to look through anyway ;) – goldilocks Jun 14 '16 at 12:09
  • Whoops, sorry Carl -- that should probably have been systemctl disable serial-getty@ttyS0.service (edited above). I've also edited my answer in the duplicate question to include these details. The raspi-config option is Advanced Options -> Enable/Disable shell and kernel messages on the serial connection. – goldilocks Jun 14 '16 at 12:25
  • So I've disabled the serial console, as well as rebooting the device...Once booted up I check /boot/cmdline.txt and notice that the only console shown is console=tty1 but when I try to run my code I get [errno2] could not open port /dev/ttyS0: [Errno2] No such file or directory: /dev/ttyS0 – Carl03 Jun 14 '16 at 12:42
  • Okay. I've reopened this and edited in a line to make it clear you have the serial console disabled so you do not have to go through this again -- but do double check that ;) You might also want to include a photo of the physical connections; although it seems very straighforward it is not unusual for people to have let a small mistake there go unnoticed (such as not crossing the RX and TX lines). – goldilocks Jun 14 '16 at 12:46

1 Answers1

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.

Carl03
  • 11
  • 5