Using ttyAMA0 port in RPi

Hi,
I’m trying to connect my raspberry pi to another device using serial connection pins (BCM14 and BCM15 pins of RPI), but it says that “The port is already open.”.
There was same problem in Raspbian distro, that was using the serial port as console and i was able to disable that by ‘raspi-config’ util, but there is no such application in Ubuntu-Mate. So how can i disable the using of ttyAMA0 as console and make it free for my usage?

Thanks

Hi,

does this help?:

https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=17360

Thanks for reply, not it did not help.
My problem is how to disable console (or getty or whatever it is) on ttyAMA0 port which is setted by default on ubuntu mate.

This maybe?:

1 Like

I’m trying on ubuntu-mate. but still same (after doing solution in the link), problem not fixed…

What about updating the “/boot/cmdline.txt” file and add the parameter “console=ttyAMA0,115200”?

1 Like

Adding this parameter will disable console on ttyAMA0?
I should reinstall ubuntu mate on sd cart to check this solution out…

Thanks anyways

Since UART was dominated by BT.
You should disable BT first theoretically!

Try this:
https://openenergymonitor.org/emon/node/12311

I have the same problem.
Nothing of above looks work.

Most of references on the internet assume that you use raspbian.
For examples:

  • several solution propose using the pi3-disable-bt overlay, but it looks it is only available for raspbian, this last example also mention to disable the hci service, but such service even does not exist on ubuntu mate.

Any idea?

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:

  1. I added the user pi to the groups dialout and tty with
    sudo usermod -a -G dialout pi
    sudo usermod -a -G tty pi

  2. 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]

  3. 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