poojasuresh
Posts: 1
Joined: Thu Nov 16, 2017 7:57 am

Accessing permission to open port /dev/ttyS0 for Serial communication

Thu Nov 16, 2017 8:13 am

Good Afternoon,
I am trying to send data through UART to the microcontroller. But I am getting an error as below:

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Documents/Radio Altimeter/Radaltuart_3l.py", line 17, in <module>
    bytesize=serial.EIGHTBITS
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 261, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 278, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
SerialException: could not open port /dev/ttyS0: [Errno 13] Permission denied: '/dev/ttyS0'
I have used command sudo chmod 666 /dev/ttyS0 and it works fine but once i reboot it or shut it down and run my code I get the same error. I want to permanently change the permissions. I am also the member of dialout group:

Code: Select all

[email protected]:~ $ ls -l /dev/ttyS0
crw--w---- 1 root tty 4, 64 Nov 16 07:38 /dev/ttyS0
[email protected]:~ $ sudo adduser pi dialout
The user `pi' is already a member of `dialout'.
So can anyone please let me know a permanent solution for the problem?

User avatar
topguy
Posts: 5333
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Accessing permission to open port /dev/ttyS0 for Serial communication

Thu Nov 16, 2017 2:17 pm

You can see that ttyS0 has group "tty" so maybe add "pi" to that group instead.

Have you checked if you have a "/dev/serial0" device also ?

lara1
Posts: 12
Joined: Fri Dec 22, 2017 6:43 pm

Re: Accessing permission to open port /dev/ttyS0 for Serial communication

Wed Mar 21, 2018 9:00 pm

Good day guys.I have experienced the same problem,when I change the permission to serial port,after 10 minutes the setting change alone and I lose the permission at groups.
I already add the user pi to the groups dialout and tty.
I used sudo chmod 766 ttyAMA0 or sudo chmod -R a+rw ttyAMA0 commands.Can you suggest me other actions?Thanks

User avatar
DougieLawson
Posts: 34924
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Accessing permission to open port /dev/ttyS0 for Serial communication

Wed Mar 21, 2018 10:12 pm

Your userid needs to be in the dialout and netdev groups.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

lara1
Posts: 12
Joined: Fri Dec 22, 2017 6:43 pm

Re: Accessing permission to open port /dev/ttyS0 for Serial communication

Thu Mar 22, 2018 7:30 pm

Hi Dougie,I checked many times the groups.Below the list of pi user.
I already tried to use the comands as root.

[email protected]:~ $ groups pi
pi : pi root adm tty dialout cdrom sudo audio www-data video plugdev games users input netdev spi i2c

[email protected]:~ $ ls -l /dev/ttyAMA0
crw--w---- 1 root tty 204, 64 Mar 22 20:12 /dev/ttyAMA0

[email protected]:~ $ sudo chmod 777 /dev/ttyAMA0

[email protected]:~ $ ls -l /dev/ttyAMA0
crwxrwxrwx 1 root tty 204, 64 Mar 22 20:13 /dev/ttyAMA0

[email protected]:~ $ ls -l /dev/ttyAMA0
crw--w---- 1 root tty 204, 64 Mar 22 20:15 /dev/ttyAMA0

After 2 minutes the permissions are changed alone!!!
Have you got any idea?Thanks

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Accessing permission to open port /dev/ttyS0 for Serial communication

Mon Mar 26, 2018 5:36 pm

I believe you are bumping heads with udev.
Try creating a file in /etc/udev/rules.d with the suffix .rules, e.g. local.rules, and add a line like this to it:

ACTION=="add", KERNEL=="ttyS0", MODE="0666"

As a FYI, I have had timing issues with the serial port hardware on the Rpi so your mileage may vary.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
jojopi
Posts: 3060
Joined: Tue Oct 11, 2011 8:38 pm

Re: Accessing permission to open port /dev/ttyS0 for Serial communication

Mon Mar 26, 2018 6:28 pm

lara1 wrote:
Thu Mar 22, 2018 7:30 pm
[email protected]:~ $ sudo chmod 777 /dev/ttyAMA0
Richard-TX wrote:
Mon Mar 26, 2018 5:36 pm
ACTION=="add", KERNEL=="ttyS0", MODE="0666"
Let us not go crazy. 0666 or 0777 is never the right mode for anything.

The problem here is that something else is using the device. That is why it is in group "tty" instead of "dialout".

Disable serial shell in the interfacing options in "sudo raspi-config".

nabeel313
Posts: 1
Joined: Wed Jan 02, 2019 11:34 am

Re: Accessing permission to open port /dev/ttyS0 for Serial communication

Wed Jan 02, 2019 11:38 am

open the terminal
try to execute the program with sudo

Return to “Interfacing (DSI, CSI, I2C, etc.)”