GmanArnold
Posts: 5
Joined: Mon Mar 22, 2021 3:54 am

Serial Port.

Sun Apr 18, 2021 4:42 pm

Hi, I'm hoping to get some assistance with serial communications from a raspberry pi 4 to a Sparkfun RFID reader. I feel I have done everything there is to do and have spent multiple hours/days of googling and I still get time out when trying to read from TTYAMA0, I have gotten it to work and out of nowhere it just stopped working without making any changes, I have checked the cables. I have triple check everything. I also have another device wired up the same way and the same setup and is working for now. but I did have the issue at first. I ended up reinstalling the OS on the pi to get it to work again. so don't know why it stopped working and would like to find a solution instead of restoring the pi.

Things I've tried
Disabled the serial console, using "sudo raspi-config"
Disabled Bluetooth with: dtoverlay=disable-bt
Added enable_uart=1 to /boot/Config.txt

sudo systemctl stop serial-getty@ttyAMA0.service
sudo systemctl disable serial-getty@ttyAMA0.service


sudo nano /boot/cmdline.txt shows:

Code: Select all

console=tty1 root=PARTUUID=89970a75-02 rootfstype=ext4 elevator=deadline fsck.r$
This is the code I'm trying to run

Code: Select all

import mercury
reader = mercury.Reader("tmr:///dev/ttyAMA0")

reader.set_region("NA3")
reader.set_read_plan([1], "GEN2")
print(reader.read())
The error I get

Code: Select all

Traceback (most recent call last): 
File "/home/pi/Desktop/test.py", line 2, in <module>
 reader = mercury.Reader("tmr:///dev/ttyAMA0") 
 TypeError: Timeout
>>> 
ls -l /dev shows the following

Code: Select all

crw-r--r--  1 root root     10, 235 Apr 18 12:18 autofs
drwxr-xr-x  2 root root         580 Apr 18 12:18 block
crw-------  1 root root     10, 234 Apr 18 12:18 btrfs-control
drwxr-xr-x  3 root root          60 Dec 31  1969 bus
crw-------  1 root root     10,  62 Apr 18 12:18 cachefiles
drwxr-xr-x  2 root root        3060 Apr 18 12:18 char
crw-------  1 root root      5,   1 Apr 18 12:19 console
crw-------  1 root root     10, 203 Apr 18 12:18 cuse
drwxr-xr-x  7 root root         140 Apr 18 12:18 disk
drwxr-xr-x  2 root root          80 Dec 31  1969 dma_heap
drwxr-xr-x  3 root root         120 Apr 18 12:18 dri
crw-rw----  1 root video    29,   0 Apr 18 12:18 fb0
lrwxrwxrwx  1 root root          13 Feb 14  2019 fd -> /proc/self/fd
crw-rw-rw-  1 root root      1,   7 Apr 18 12:18 full
crw-rw-rw-  1 root root     10, 229 Apr 18 12:18 fuse
crw-rw----  1 root gpio    254,   0 Apr 18 12:18 gpiochip0
crw-rw----  1 root gpio    254,   1 Apr 18 12:18 gpiochip1
crw-rw----  1 root gpio    246,   0 Apr 18 12:18 gpiomem
crw-------  1 root root     10, 183 Apr 18 12:18 hwrng
crw-rw----  1 root i2c      89,   1 Apr 18 12:18 i2c-1
lrwxrwxrwx  1 root root          12 Apr 18 12:18 initctl -> /run/initctl
drwxr-xr-x  2 root root          60 Dec 31  1969 input
crw-r--r--  1 root root      1,  11 Apr 18 12:18 kmsg
lrwxrwxrwx  1 root root          28 Feb 14  2019 log -> /run/systemd/journal/dev-log
brw-rw----  1 root disk      7,   0 Apr 18 12:18 loop0
brw-rw----  1 root disk      7,   1 Apr 18 12:18 loop1
brw-rw----  1 root disk      7,   2 Apr 18 12:18 loop2
brw-rw----  1 root disk      7,   3 Apr 18 12:18 loop3
brw-rw----  1 root disk      7,   4 Apr 18 12:18 loop4
brw-rw----  1 root disk      7,   5 Apr 18 12:18 loop5
brw-rw----  1 root disk      7,   6 Apr 18 12:18 loop6
brw-rw----  1 root disk      7,   7 Apr 18 12:18 loop7
crw-rw----  1 root disk     10, 237 Apr 18 12:18 loop-control
drwxr-xr-x  2 root root          60 Apr 18 12:18 mapper
crw-rw----  1 root video   241,   0 Apr 18 12:18 media0
crw-rw----  1 root video   241,   1 Apr 18 12:18 media1
crw-r-----  1 root kmem      1,   1 Apr 18 12:18 mem
brw-rw----  1 root disk    179,   0 Apr 18 12:18 mmcblk0
brw-rw----  1 root disk    179,   1 Apr 18 12:18 mmcblk0p1
brw-rw----  1 root disk    179,   2 Apr 18 12:18 mmcblk0p2
drwxrwxrwt  2 root root          40 Dec 31  1969 mqueue
drwxr-xr-x  2 root root          60 Apr 18 12:18 net
crw-rw-rw-  1 root root      1,   3 Apr 18 12:18 null
crw-r-----  1 root kmem      1,   4 Apr 18 12:18 port
crw-------  1 root root    108,   0 Apr 18 12:18 ppp
crw-rw-rw-  1 root tty       5,   2 Apr 18 12:33 ptmx
drwxr-xr-x  2 root root           0 Feb 14  2019 pts
brw-rw----  1 root disk      1,   0 Apr 18 12:18 ram0
brw-rw----  1 root disk      1,   1 Apr 18 12:18 ram1
brw-rw----  1 root disk      1,  10 Apr 18 12:18 ram10
brw-rw----  1 root disk      1,  11 Apr 18 12:18 ram11
brw-rw----  1 root disk      1,  12 Apr 18 12:18 ram12
brw-rw----  1 root disk      1,  13 Apr 18 12:18 ram13
brw-rw----  1 root disk      1,  14 Apr 18 12:18 ram14
brw-rw----  1 root disk      1,  15 Apr 18 12:18 ram15
brw-rw----  1 root disk      1,   2 Apr 18 12:18 ram2
brw-rw----  1 root disk      1,   3 Apr 18 12:18 ram3
brw-rw----  1 root disk      1,   4 Apr 18 12:18 ram4
brw-rw----  1 root disk      1,   5 Apr 18 12:18 ram5
brw-rw----  1 root disk      1,   6 Apr 18 12:18 ram6
brw-rw----  1 root disk      1,   7 Apr 18 12:18 ram7
brw-rw----  1 root disk      1,   8 Apr 18 12:18 ram8
brw-rw----  1 root disk      1,   9 Apr 18 12:18 ram9
crw-rw-rw-  1 root root      1,   8 Apr 18 12:18 random
drwxr-xr-x  2 root root          60 Dec 31  1969 raw
crw-rw-r--  1 root netdev   10, 242 Apr 18 12:18 rfkill
crw-rw----  1 root video   238,   0 Apr 18 12:18 rpivid-h264mem
crw-rw----  1 root video   240,   0 Apr 18 12:18 rpivid-hevcmem
crw-rw----  1 root video   239,   0 Apr 18 12:18 rpivid-intcmem
crw-rw----  1 root video   237,   0 Apr 18 12:18 rpivid-vp9mem
lrwxrwxrwx  1 root root           7 Apr 18 12:18 serial0 -> ttyAMA0
lrwxrwxrwx  1 root root           5 Apr 18 12:18 serial1 -> ttyS0
drwxrwxrwt  2 root root          40 Feb 14  2019 shm
drwxr-xr-x  3 root root         180 Apr 18 12:18 snd
crw-rw----  1 root spi     153,   0 Apr 18 12:18 spidev0.0
crw-rw----  1 root spi     153,   1 Apr 18 12:18 spidev0.1
lrwxrwxrwx  1 root root          15 Feb 14  2019 stderr -> /proc/self/fd/2
lrwxrwxrwx  1 root root          15 Feb 14  2019 stdin -> /proc/self/fd/0
lrwxrwxrwx  1 root root          15 Feb 14  2019 stdout -> /proc/self/fd/1
crw-rw-rw-  1 root tty       5,   0 Apr 18 12:18 tty
crw--w----  1 root tty       4,   0 Apr 18 12:18 tty0
crw-------  1 pi   tty       4,   1 Apr 18 12:18 tty1
crw--w----  1 root tty       4,  10 Apr 18 12:18 tty10
crw--w----  1 root tty       4,  11 Apr 18 12:18 tty11
crw--w----  1 root tty       4,  12 Apr 18 12:18 tty12
crw--w----  1 root tty       4,  13 Apr 18 12:18 tty13
crw--w----  1 root tty       4,  14 Apr 18 12:18 tty14
crw--w----  1 root tty       4,  15 Apr 18 12:18 tty15
crw--w----  1 root tty       4,  16 Apr 18 12:18 tty16
crw--w----  1 root tty       4,  17 Apr 18 12:18 tty17
crw--w----  1 root tty       4,  18 Apr 18 12:18 tty18
crw--w----  1 root tty       4,  19 Apr 18 12:18 tty19
crw--w----  1 root tty       4,   2 Apr 18 12:18 tty2
crw--w----  1 root tty       4,  20 Apr 18 12:18 tty20
crw--w----  1 root tty       4,  21 Apr 18 12:18 tty21
crw--w----  1 root tty       4,  22 Apr 18 12:18 tty22
crw--w----  1 root tty       4,  23 Apr 18 12:18 tty23
crw--w----  1 root tty       4,  24 Apr 18 12:18 tty24
crw--w----  1 root tty       4,  25 Apr 18 12:18 tty25
crw--w----  1 root tty       4,  26 Apr 18 12:18 tty26
crw--w----  1 root tty       4,  27 Apr 18 12:18 tty27
crw--w----  1 root tty       4,  28 Apr 18 12:18 tty28
crw--w----  1 root tty       4,  29 Apr 18 12:18 tty29
crw--w----  1 root tty       4,   3 Apr 18 12:18 tty3
crw--w----  1 root tty       4,  30 Apr 18 12:18 tty30
crw--w----  1 root tty       4,  31 Apr 18 12:18 tty31
crw--w----  1 root tty       4,  32 Apr 18 12:18 tty32
crw--w----  1 root tty       4,  33 Apr 18 12:18 tty33
crw--w----  1 root tty       4,  34 Apr 18 12:18 tty34
crw--w----  1 root tty       4,  35 Apr 18 12:18 tty35
crw--w----  1 root tty       4,  36 Apr 18 12:18 tty36
crw--w----  1 root tty       4,  37 Apr 18 12:18 tty37
crw--w----  1 root tty       4,  38 Apr 18 12:18 tty38
crw--w----  1 root tty       4,  39 Apr 18 12:18 tty39
crw--w----  1 root tty       4,   4 Apr 18 12:18 tty4
crw--w----  1 root tty       4,  40 Apr 18 12:18 tty40
crw--w----  1 root tty       4,  41 Apr 18 12:18 tty41
crw--w----  1 root tty       4,  42 Apr 18 12:18 tty42
crw--w----  1 root tty       4,  43 Apr 18 12:18 tty43
crw--w----  1 root tty       4,  44 Apr 18 12:18 tty44
crw--w----  1 root tty       4,  45 Apr 18 12:18 tty45
crw--w----  1 root tty       4,  46 Apr 18 12:18 tty46
crw--w----  1 root tty       4,  47 Apr 18 12:18 tty47
crw--w----  1 root tty       4,  48 Apr 18 12:18 tty48
crw--w----  1 root tty       4,  49 Apr 18 12:18 tty49
crw--w----  1 root tty       4,   5 Apr 18 12:18 tty5
crw--w----  1 root tty       4,  50 Apr 18 12:18 tty50
crw--w----  1 root tty       4,  51 Apr 18 12:18 tty51
crw--w----  1 root tty       4,  52 Apr 18 12:18 tty52
crw--w----  1 root tty       4,  53 Apr 18 12:18 tty53
crw--w----  1 root tty       4,  54 Apr 18 12:18 tty54
crw--w----  1 root tty       4,  55 Apr 18 12:18 tty55
crw--w----  1 root tty       4,  56 Apr 18 12:18 tty56
crw--w----  1 root tty       4,  57 Apr 18 12:18 tty57
crw--w----  1 root tty       4,  58 Apr 18 12:18 tty58
crw--w----  1 root tty       4,  59 Apr 18 12:18 tty59
crw--w----  1 root tty       4,   6 Apr 18 12:18 tty6
crw--w----  1 root tty       4,  60 Apr 18 12:18 tty60
crw--w----  1 root tty       4,  61 Apr 18 12:18 tty61
crw--w----  1 root tty       4,  62 Apr 18 12:18 tty62
crw--w----  1 root tty       4,  63 Apr 18 12:18 tty63
crw--w----  1 root tty       4,   7 Apr 18 12:18 tty7
crw--w----  1 root tty       4,   8 Apr 18 12:18 tty8
crw--w----  1 root tty       4,   9 Apr 18 12:18 tty9
crw-rw----  1 root dialout 204,  64 Apr 18 12:20 ttyAMA0
crw-rw----  1 root dialout 204,  65 Apr 18 12:18 ttyAMA1
crw-------  1 root root      5,   3 Apr 18 12:18 ttyprintk
crw-rw----  1 root dialout   4,  64 Apr 18 12:18 ttyS0
crw-------  1 root root     10, 239 Apr 18 12:18 uhid
crw-------  1 root root     10, 223 Apr 18 12:18 uinput
crw-rw-rw-  1 root root      1,   9 Apr 18 12:18 urandom
drwxr-xr-x  3 root root          60 Apr 18 12:18 v4l
crw-rw----  1 root video   243,   0 Apr 18 12:18 vchiq
crw-rw----  1 root video   247,   0 Apr 18 12:18 vcio
crw-------  1 root root    248,   0 Apr 18 12:18 vc-mem
crw-rw----  1 root tty       7,   0 Apr 18 12:18 vcs
crw-rw----  1 root tty       7,   1 Apr 18 12:18 vcs1
crw-rw----  1 root tty       7,   2 Apr 18 12:18 vcs2
crw-rw----  1 root tty       7,   3 Apr 18 12:18 vcs3
crw-rw----  1 root tty       7,   4 Apr 18 12:18 vcs4
crw-rw----  1 root tty       7,   5 Apr 18 12:18 vcs5
crw-rw----  1 root tty       7,   6 Apr 18 12:18 vcs6
crw-rw----  1 root tty       7,   7 Apr 18 12:18 vcs7
crw-rw----  1 root tty       7, 128 Apr 18 12:18 vcsa
crw-rw----  1 root tty       7, 129 Apr 18 12:18 vcsa1
crw-rw----  1 root tty       7, 130 Apr 18 12:18 vcsa2
crw-rw----  1 root tty       7, 131 Apr 18 12:18 vcsa3
crw-rw----  1 root tty       7, 132 Apr 18 12:18 vcsa4
crw-rw----  1 root tty       7, 133 Apr 18 12:18 vcsa5
crw-rw----  1 root tty       7, 134 Apr 18 12:18 vcsa6
crw-rw----  1 root tty       7, 135 Apr 18 12:18 vcsa7
crw-rw----  1 root video    10,  61 Apr 18 12:18 vcsm-cma
crw-rw----  1 root tty       7,  64 Apr 18 12:18 vcsu
crw-rw----  1 root tty       7,  65 Apr 18 12:18 vcsu1
crw-rw----  1 root tty       7,  66 Apr 18 12:18 vcsu2
crw-rw----  1 root tty       7,  67 Apr 18 12:18 vcsu3
crw-rw----  1 root tty       7,  68 Apr 18 12:18 vcsu4
crw-rw----  1 root tty       7,  69 Apr 18 12:18 vcsu5
crw-rw----  1 root tty       7,  70 Apr 18 12:18 vcsu6
crw-rw----  1 root tty       7,  71 Apr 18 12:18 vcsu7
crw-------  1 root root     10,  63 Apr 18 12:18 vga_arbiter
crw-------  1 root root     10, 137 Apr 18 12:18 vhci
crw-rw----+ 1 root video    81,   4 Apr 18 12:18 video10
crw-rw----+ 1 root video    81,   5 Apr 18 12:18 video11
crw-rw----+ 1 root video    81,   6 Apr 18 12:18 video12
crw-rw----+ 1 root video    81,   0 Apr 18 12:18 video13
crw-rw----+ 1 root video    81,   1 Apr 18 12:18 video14
crw-rw----+ 1 root video    81,   2 Apr 18 12:18 video15
crw-rw----+ 1 root video    81,   3 Apr 18 12:18 video16
crw-------  1 root root     10, 130 Apr 18 12:18 watchdog
crw-------  1 root root    250,   0 Apr 18 12:18 watchdog0
crw-rw-rw-  1 root root      1,   5 Apr 18 12:18 zero

GmanArnold
Posts: 5
Joined: Mon Mar 22, 2021 3:54 am

Re: Serial Port.

Mon Apr 19, 2021 3:12 am

at times it will read at others it won't. Like it started reading and the pi or the reader have not been touched. everything is being done through the VNC. Any ideas? I feel it's unstable. but don't know what would be causing this. The bad thing about this I that cant replicate it.

ronter
Posts: 29
Joined: Thu Nov 12, 2015 3:11 am
Location: Ottawa, Canada

Re: Serial Port.

Tue Apr 20, 2021 3:25 pm

I fell into a similar trap! After a failed attempt to use Bluetooth speakers with a non-desktop "lite" system, I added the
dtoverlay= disable-bt to my /boot/config.txt file. The /boot/overlays/README says...

Code: Select all

Name:   disable-bt
Info:   Disable onboard Bluetooth on Pi 3B, 3B+, 3A+, 4B and Zero W, restoring
        UART0/ttyAMA0 over GPIOs 14 & 15.
        N.B. To disable the systemd service that initialises the modem so it
        doesn't use the UART, use 'sudo systemctl disable hciuart'.
Load:   dtoverlay=disable-bt
Params: <None>
I was hoping that this setting would disable of all of the additional Bluetooth software that I had installed in my failed BT speaker attempt. I then noticed that my serial port connection on GPIO 14&15 would not receive. I'm using wiringPi serial functions; the serialDataAvail(fd) function returns -1 with errno=5.

I commented out the dtoverlay=disable-bt line in /boot/config.txt and everything worked fine again.

I'm just now rebuilding my system from the latest distro. This seems my best option to get rid of all the superfluous BT stuff I installed.

cleverca22
Posts: 3576
Joined: Sat Aug 18, 2012 2:33 pm

Re: Serial Port.

Tue Apr 20, 2021 8:07 pm

the correct solution, is to always use /dev/serial0

depending on if bluetooth is enabled or not, you need to correctly pick between ttyAMA0 and ttyS0
but serial0 is a symlink pointing to the right one, so you dont have to guess!

Return to “Troubleshooting”