树莓派Zero的ttyAMA0使用pi用户访问时拒绝访问(Permission denied)的解决办法(已在Zero上遇到并测试通过)

I'm also guessing that you are using a Pi 3B. On a Pi 3B, "/dev/ttyAMA0" is normally reserved for Bluetooth.

To use the Serial Port on the Pi 3B (or any model of Pi running updated Raspbian Jessie):

Remove the phrase "console=serial0,115200" from the file '/boot/cmdline.txt'. Note that this file must only contain 1 line, do not split the line when editing, or try to add comments. This prevents Linux sending boot messages to the Serial Port.

Add the line "enable_uart=1" to the end of the file '/boot/config.txt'. Ensure that this file does not contain any other commands referring to the uart. This takes care of all the background tasks needed to use the Serial Port on the Pi 3B.

Reboot.

Refer to your Serial Port in code as "/dev/serial0", that's serialZero, not serialOh!

No need to change groups or permissions from the defaults.

翻译:

(1)移除/boot/cmdline.txt中的console-serial,115200这一段

(2)在/boot/config.txt中添加enable_uart=1

新问题(20190522):

按照上面的配置访问/dev/ttyAMA0,虽然可以打开这个串口,但无法读取和写入,还要使用raspi-config按照下图所示修改配置:

树莓派Zero的ttyAMA0使用pi用户访问时拒绝访问(Permission denied)的解决办法(已在Zero上遇到并测试通过)_第1张图片

树莓派Zero的ttyAMA0使用pi用户访问时拒绝访问(Permission denied)的解决办法(已在Zero上遇到并测试通过)_第2张图片

树莓派Zero的ttyAMA0使用pi用户访问时拒绝访问(Permission denied)的解决办法(已在Zero上遇到并测试通过)_第3张图片

树莓派Zero的ttyAMA0使用pi用户访问时拒绝访问(Permission denied)的解决办法(已在Zero上遇到并测试通过)_第4张图片

并且此时串口为/dev/ttyS0,访问它就可以了

注意:上面raspi-config有两个确认对话框,一个选择“No", 一个选择"Yes"千万不要选错了

参考网址:https://www.raspberrypi.org/forums/viewtopic.php?p=1039118

你可能感兴趣的:(树莓派)