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 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?

3

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):

  1. Disable
    sudo systemctl stop 
    sudo systemctl disable 
    sudo systemctl mask 
    
  2. Setup udev rules
    • put below content in new file /etc/udev/rules.d/10-local.rules
      KERNEL=="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
  3. Add user to tty group: sudo adduser ubuntu tty
  4. Delete substring console=serial0,115200 from /boot/firmware/cmdline.txt
  5. Add newline dtoverlay=disable-bt to /boot/firmware/config.txt (I put it right under the cmdline=cmdline.txt line)
  6. Restart
  7. (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:

  1. Back up the original config.txt and cmdline.txt files

    sudo cp -pr /boot/firmware/cmdline.txt /boot/firmware/cmdline.txt-orig
    sudo cp -pr /boot/firmware/config.txt /boot/firmware/config.txt-orig
    
  2. Edit /boot/firmware/config.txt to comment out the enable_uart=1 like below,

    #enable_uart=1
    
    cmdline=cmdline.txt
    
  3. Remove the console setting console=serial0,115200 from /boot/firmware/cmdline.txt

  4. Disable the Serial Service which used the miniUART

    sudo systemctl stop 
    sudo systemctl disable 
    sudo systemctl mask 
    
  5. Add the user which will use the miniUART to tty and dialout group

    sudo adduser ${USER} tty
    sudo adduser ${USER} dialout
    
  6. Finally, reboot Ubuntu 20.04, then both hci0 and /dev/ttyS0 can 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest