I have a board for the RDM6300 which can read RFID tags. I could successfully test the board using an ESP32. Here is the micropython code:
from machine import UART, Pin
import time
uart = UART(1, 9600)
uart.init(9600, bits=8, parity=None, stop=1, rx=9, tx=10)
pin = Pin(26, Pin.OUT)
def flashLED():
pin.value(1)
time.sleep(.1)
pin.value(0)
flashLED()
while True:
b = uart.read()
if not b == None:
print(b)
flashLED()
So whenever a tag is read I flash an LED. This works just fine. So now I want to attach the board to my RaspberryPi Zero.
I did enable the serial interface using sudo raspi-config
. Also I disabled the terminal over that port. I did reboot after changing that.
After reboot I do see the following instances for the serial connection:
$ ls /dev/ -lia | grep serial
217 lrwxrwxrwx 1 root root 5 Jul 25 12:11 serial0 -> ttyS0
196 lrwxrwxrwx 1 root root 7 Jul 25 12:11 serial1 -> ttyAMA0
I added pi
to the group dialout
:
sudo adduser pi dialout
When I do cat /dev/serial0
then the prompt is "captured" while cat /dev/serial1
exists immediately.
Now I found a script that reads from the UART like so:
import serial
from time import sleep
ser = serial.Serial("/dev/serial0", baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=10)
while True:
rx_data =ser.readline()
print(rx_data)
I had to run the script using sudo since otherwise I would get the following error:
/dev/serial0: [Errno 16] Device or resource busy: '/dev/serial0'
Please note that I tried both /dev/serial0
and /dev/serial1
respectively.
The output of the RDMBoard is connected to RX of the Pi (namely Pin 15). I tried pin 14 too.
I don't get any data back when reading from my serial
stream. As you can see I did try a few different things but it seems that I'm stuck. Any help would be greatly appreciated!
Update: While I got it working now (see my answer below) I'm still curious on how to get this working using the serial interface.
pi-zero-w
), but in Raspberry Pi OS/dev/serial0
is the default serial port (on pins 8,10 - BCM 14,15) but is not enabled by default.