Enable Uart Communication on Pi4 Ubuntu 20.04
I Have Ubuntu 20.04 (32 Bit) Installed on Rpi4 (4Gb). I Have Loopback Wire Installed on Pin 8,10. I Need to Use Bluetooth and Also Basic Serial Communication...
I have Ubuntu 20.04 (32 bit) installed on RPI4 (4GB). I have loopback wire installed on Pin 8,10.
I need to use Bluetooth and also basic serial communication over Pin 8,10 to communicate with a Roboclaw motor controller.
Did install RASPI-CONFIG on Ubuntu using script at but even though it installed successfully it loads with improper boot configuration error. That led me to /boot/firmware directory where I found config.txt, cmdline.txt etc. I removed the console=...
$ dmesg | grep tty
[ 0.001061] printk: console [tty0] enabled
[ 1.919367] fe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 29, base_baud = 0) is a PL011 rev2
[ 1.924677] fe215040.serial: ttyS0 at MMIO 0x0 (irq = 31, base_baud = 62500000) is a 16550
So doesn't look like I disabled the console. How do I do that?
$ ls -l /dev/ttyS[0123]
crw-rw---- 1 root dialout 4, 64 Jun 27 12:32 /dev/ttyS0
$ ls -l /dev/serial
lrwxrwxrwx 1 root root 7 Apr 1 11:23 /dev/serial1 -> ttyAMA0
Second when I run sudo minicom -b 115200 -o -D /dev/ttyS0 (with loopback in place - verified correctly installed)
I see no characters. No verification of communication with serial.
Tried to change baud, parity, flow control settings with no effect.
Also have a simple serial test python which also fails to send/receive over serial at /dev/ttyS0 whether I run with sudo or without.
UPDATE I got an updated install script (same github link above) and now have successfully installed RASPI-CONFIG, however while I can run it the directory structure on the RPi4 w/ Ubuntu 20.04 is different enough that it fails to find the config files it tries to change.
$ sudo raspi-config
grep: /boot/cmdline.txt: No such file or directory
sed: can't read /boot/cmdline.txt: No such file or directory
sed: can't read /boot/cmdline.txt: No such file or directory
I presume that are other Raspberry Pi 4 owners who intend to use the serial port and there's got to be a way to do what RASPI-CONFIG is trying to do on Ubuntu.
I've found the files in /boot/firmware
What should I change manually in them that RASPI-CONFIG would do via script?
4 Answers
I had a bunch of trouble talking to a roboclaw motor on an rpi4 (model B) under Ubuntu 20.04 (64 bit). I was able to resolve it, though I had to disable Bluetooth to get there. Unfortunately, I'm not sure at this point how to get there without disabling Bluetooth. Reader beware.
Confirmed this works with 5 roboclaw motor controllers on the same serial bus.
That said, here's how I did it (note that this is cliffsnotes of this procedure):
- Disable
sudo systemctl stop sudo systemctl disable sudo systemctl mask - Setup udev rules
- put below content in new file
/etc/udev/rules.d/10-local.rulesKERNEL=="ttyS0", SYMLINK+="serial0" GROUP="tty" MODE="0660" KERNEL=="ttyAMA0", SYMLINK+="serial1" GROUP="tty" MODE="0660" - Reload udev rules:
sudo udevadm control --reload-rules && sudo udevadm trigger
- put below content in new file
- Add user to
ttygroup:sudo adduser ubuntu tty - Delete substring
console=serial0,115200from/boot/firmware/cmdline.txt - Add newline
dtoverlay=disable-btto/boot/firmware/config.txt(I put it right under thecmdline=cmdline.txtline) - Restart
- (Optional) Feel free to test with this script:
Note that after this set up, you need to use ttyAMA0 (or alias serial1), not ttyS0. The first uses the full hardware UART, the second uses a "mini-UART" implementation that seems to not work so well under Ubuntu 20.04 (at least with the roboclaw, in my hardware setup. YMMV.). Some more discussion here on GitHub.
I have a setup using both Bluetooth/hci0 and the miniUART/ttyS0 at the same time with Ubuntu 20.04 (Ubuntu 5.4.0-1034.37-raspi 5.4.101) 64bit on Raspberry Pi 4 Model B Rev 1.1 (4G memory). Here is what I did:
Back up the original
config.txtandcmdline.txtfilessudo cp -pr /boot/firmware/cmdline.txt /boot/firmware/cmdline.txt-orig sudo cp -pr /boot/firmware/config.txt /boot/firmware/config.txt-origEdit
/boot/firmware/config.txtto comment out theenable_uart=1like below,#enable_uart=1 cmdline=cmdline.txtRemove the console setting
console=serial0,115200from/boot/firmware/cmdline.txtDisable the Serial Service which used the miniUART
sudo systemctl stop sudo systemctl disable sudo systemctl maskAdd the user which will use the miniUART to
ttyanddialoutgroupsudo adduser ${USER} tty sudo adduser ${USER} dialoutFinally, reboot Ubuntu 20.04, then both
hci0and/dev/ttyS0can work at the same time for me.
Detailed documentation about the UART can be found at
exactly the same problem I also have. A workaround for the wrong path of the raspi-config script may be a softlink like
ln -s /boot/firmware/cmdline.txt /boot/cmdline.txt
But this doesn't solve the origin problem. I'm sorry.
A simple solution is to use a USB to TTL Adapter to connect the roboclaw to a USB on the pi rather than UART GPIO pins. This will work out of the box without the need for config changes on the pi other than specifying the USB port in the roboclaw driver code. In my experience it is best to use a SiLabs CP2012 based USB to TTL adaptor (as for example sold by adafruit or available on amazon ) as that chipset is widely supported on linux and other OS'es and certainly on Ubuntu does not need custom drivers.