Enable serial port ttyAMA0

How do I enable the ttyAMA0 serial port on Raspberrypi?

I searched for this online and found tons of recommendations to edit the /boot/config.txt file. However this file does not exist on my system. This file is normally found on raspbian and my OS here seems to be Alpine.

cat /etc/os-release
NAME=“Alpine Linux”

Has HA changed to Alpine recently explaining the numerous documentation that does not match up anymore?

How can I enable ttyAMA0? I have an arduino connected to this and managed to setup the yaml and that. The port does not seem to work.

Any help appreciated.

1 Like

Are you using HassOS?
Did it work before (and before what)?
What are you trying to achieve?

Hi Chris,
You will probably be able to tell me which OS I have. I just went on the HA website → installation → raspberrypi and followed the instructions. (rpi4 64bit)

I have an arduino connected to ttyAMA0 and sending data streams of sensors in space separated values (text obviously):
X1 X2 X3

I have setup my yaml file as indicated on this page below.

That works well to see the the sensor in the overview pane but no data are received. (the arduino works well. no problem here as it does work using another OS).

Any documentation I find on the web does not match with what I see here. Looks like everything is out of date somehow. They all mention config.txt and cmdline.txt but that does not exist on here.

I am using the Terminal & SSH add-on to enter my commands. (I am still trying to figure out how to ssh natively to the box. Somehow wondering if the add-on is giving me a shell with its own specific environment? How do you ssh to it natively? (i.e. no web interface just ssh command from my ubuntu computer). Maybe a question for another thread.

First thing first I need to get the serial port working. ANy help?

yaml file below in case this is relevant. ( I doubt).

sensor:
  - platform: serial
    name: "RPICT"
    serial_port: /dev/ttyAMA0
    baudrate: 38400

  - platform: template
    sensors:
      arduino_t:
        friendly_name: Temperature
        unit_of_measurement: "C"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[1] | float }}"

Shutdown your pi. Take the SD card out. Insert in PC. Modify config.txt. Reinsert in Pi.

Config.txt is definitely there.

Thank you Francis. That did the trick. I can read the ttyAMA0 now. Still having to tune the yaml somehow.

I took the opportunity to include a ssh file inside the boot partition in the hope to have native ssh working but that failed.

Not a fan of these web terminals. Just give us a proper ssh access!

What modifications did you make to config.txt?

What did you change to make this work? I’m trying to use /dev/ttyS0

I still can’t get the UART working on the Raspberry Pi 5, running Home Assistant OS.

I can at least get the /dev/ttyAMA0 node to show up by following the Enabling Serial Console | Adafruit's Raspberry Pi Lesson 5. Using a Console Cable | Adafruit Learning System. Specifically, the dtparam=uart0 line was ultimately what make the AMA0 node appear/stay during runtime.

You can edit the config.txt by using the HDMI + keyboard, typing login and editing the /mnt/boot/config.txt file. That being said, this AMA0 doesn’t seem like the correct uart. IIRC, I though the default uart for raspberry pi was /dev/ttyS0 with an extra node/link from /dev/serial0 or something like that.

It is worth pointing out that the kernel does talk about registering ttyS0 and serial0 during boot time (dmesg), but then I can’t find these nodes anywhere during runtime.

Hi,

I posted a new feature request for HAOS, to implement enable uart on gpio 14&15 so as /dev/ttyAMA0 to appear. Please consider vote for the request to be implemented: RPI5 enable uart on GPIO14&GPIO15 on /dev/ttyAMA0

I spent a few days going around in circles with trying to get ttyAMA0 to show up through editing the config.txt on my RPi5. What finally worked for me was to make the changes in the [all] section of /mnt/boot/config.txt

This is of course after having gained access through using USB with a CONFIG partition holding my private key…

[all]
# Disable Bluetooth completely
dtoverlay=disable-bt

# Enable primary UART
enable_uart=1

# In case standard overlay doesn't work
dtparam=uart0=on

Bluetooth is now disabled on my device and the Z-Wave device I have ( RaZberry 7 Pro) shows up and was detected in Home Assistant.

Cheers!

is this in HAOS or in Raspbian?

I am revisiting this after my first post in 2021. Things have changed since.

I made the serial port working on a pi5 using the config below in the config.txt file

enable_uart=1
dtoverlay=disable-bt
dtoverlay=uart0

I can confirm that this setup works for RPi5 - one needs to update the file /boot/firmware/config.txt. Seems disabling “dtoverlay=disable-bt” is not necessary. UART continues to work fine after commenting this out.

enable_uart=1
#dtoverlay=disable-bt
dtoverlay=uart0

[Edit] Small update: I can remove also dtoverlay=uart0 and it works fine on my Pi5. But this may be an artifact of previous manipulations, also using raspi-config - not sure.

[Edit 2] Another working settings option is this one (I use it now):

[all]
dtparam=uart0
dtparam=uart0_console
uart_2ndstage=1