Raspberry Pi 3 /dev/ttyAMA0 serial port cannot connect - Permission Denied [Solved]

What is the problem?
Trying to connect Raspberry Pi 3 to Anet A8 printer via UART serial connection. Was working on older version of OctoPrint

What did you already try to solve it?
SSH'd into Pi and added enable_uart=1 and dtoverlay=pi3-disable-bt and dtoverlay=pi3-miniuart-bt. I also ran sudo systemctl disable hciuart to turn off service that initializes bluetooth modem.

Logs (octoprint.log, serial.log or output on terminal tab at a minimum, browser error console if UI issue ... no logs, no support!)

Changing monitoring state from "Offline" to "Detecting serial port"
Serial port list: ['/dev/ttyAMA0']
Connecting to: /dev/ttyAMA0
Changing monitoring state from "Detecting serial port" to "Error: Connection error, see Terminal tab"
Unexpected error while connecting to serial port: AUTO SerialException: '[Errno 13] could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'' @ comm.py:_openSerial:2661 (hook default)

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible)
Running newest version of OctoPrint Version 1.3.12 on Raspberry Pi 3 brand new flash via etcher. Printer is Anet A8 running a flashed version of Marlin (probably about 1 year old), not the ticking timebomb firmware it shipped with.

I was running an older version of OctoPrint (about 1 year old) on my Raspberry Pi 0W connected directly using UART. It was working perfect. I hadn't used my printer in several months due to some broken parts and waiting on the funds then the shipping from China. Finally put everything back together and booted it up today to find that it had a lot of updates, but was complaining about the environment needing update. I followed the recommended path of backing up through the menu and flashing a new image then restoring the backup I had made previously. While I was at it, I swapped a Raspberry Pi 3 into place so that I could take advantage of the Pi Cam (not connected yet). When everything was accessible again and I tried to connect to the printer I got the above error. I swapped the SD card back to the original Pi 0W to see if it is something wrong with the Pi 3, but it is now doing the same issues. I would prefer to connect through UART so that I get a direct connection and avoid issues with the USB transmission and cable, and I am designing a custom case that mounts the Pi right on top of the Anet board and don't want the extra cabling making a mess.

Make sure that you're either disabling Bluetooth OR you're giving it the mini UART (but not both).

It's useful to just go into sudo raspi-config, go to Interfaces -> Serial and answer "no", "yes" to the next two prompts. The "yes" enables the UART like you've done but the "no" part also removes the UART from the console tty.

You didn't mention how you installed OctoPrint. If you used the OctoPi image then the pi user is already in the correct groups: gpio and dialout. The second of these allows the pi user to access serial ports.

Thank you for the reply, I had only disabled Bluetooth and when that didn't work I found a post on a different forum about making the UART work and they claimed needing to do both, I will remove it from the mini and try your changes to raspi-config. I wrote that I flashed by etcher, but now realize that didn't really provide the correct info. I used etcher to flash the latest OctoPi image to a 32GB SD. I did try a chmod 666 /Dev/ttyAMA0 per another site and it got farther into the connection, but ended with an incorrect login error. Subsequent attempt to reconnect showing original error again.

I don't think I would try to manipulate the /dev area's rights. Once you disconnect that cable the device path part of that tree is then removed and you'd be back to square one again anyway.

If you look at this solution, there are two versions suggested, the second one hints at the rights issue. But this isn't great advice because as soon as you pull the cable the device is gone. Read the next suggestion since it's what Guy/Foosel have already done for you by adding the pi user to the dialout group.

I disabled the bluetooth -> mini-uart entry and ran raspi-config, entering the options you suggested. After the pi rebooted I was able to successfully connect via serial again. Thank you so much.

BTW - in raspi-config i had the option "Interfacing Options" instead of "Interfaces". I don't know if that is a version thing or not, but I figured I'd document it in case anyone else tries this and doesn't see the option verbatim.

1 Like