I was able to make it work by following part of the instructions in this video (https://www.youtube.com/watch?v=StFZj7gSwNs) and making adjustments where necessary.
The steps I took:
-
I added the user pi
to the groups dialout
and tty
with
sudo usermod -a -G dialout pi
sudo usermod -a -G tty pi
-
Then I stopped the service getty
.
It's used as a terminal port to log into the raspi and to do console logging.
To provide this service the raspberry uses the serial port and blocks it for other use (at least if you're not root). To stop the service use:
sudo systemctl stop [email protected]
Then I disabled the service:
sudo systemctl disable [email protected]
-
When I looked in the /boot/cmdline.txt
it was just empty. The /boot/config.txt
file also mentions that you shouldn't change it so I didn't put the enable_uart
in there. I found that it includes the file syscfg.txt
which includes nobtcfg.txt
(both are located in /boot/firmware
). In there it says that the bluetooth module is disabled already (nobt = no bluetooth). In the nobtcmd.txt
(included in nobtcfg.txt
and also mentioned in config.txt
) the output of the serial console is set up. As I still wasn't able to use the UART without using sudo I enabled the commented out line dtoverlay=pi3-disable-bt
in nobtcfg.txt
and removed console=ttyAMA0,115200
in nobtcmd.txt
. After that I rebooted and it worked!
Also be careful with the UART connection as it seems to be able to interfere with the booting process. If the raspi is not booting anymore, disconnect / power down the other UART device. You can also monitor the booting process of the raspi with an HDMI cable to see what's happening. Maybe this can be improved by not allowing the UART access to the console somehow (maybe remove console=tty1
in boot/firmware/nobtcmd.txt
?).
Note that next to the nobtcfg.txt
/ nobtcmd.txt
(no bluetooth) files there are also btcfg.txt
/ btcmd.txt
for a configuration with bluetooth.
To program the UART communication I used pyserial.
Setup:
import serial
self.uart = serial.Serial('/dev/serial0', baudrate=115200, timeout=1, bytesize=8, parity='N', stopbits=1,rtscts=False,xonxoff=False)
Write bytes:
self.uart.write(bytearray([1,2,3]))
Write characters:
self.uart.write(letter.encode('UTF-8')
or
self.uart.write(b'ABC')
Read number of bytes:
self.uart.read(num_bytes)
Read a line (until linebreak or timeout):
self.uart.readline()
Close port again
self.uart.close()
Cheers
fb21