I want to automatically have my serial connection get permission through the code instead of having to use terminal to give permission every time.
I tried using import os to use os.system() to automatically give permission but permission is always denied.
def checkConnection(password):
if os.path.exists('/dev/ttyUSB0'):
usb = '/dev/ttyUSB0'
os.system('echo password | sudo chmod 666 /dev/ttyUSB0')
return usb
elif os.path.exists('/dev/ttyUSB1'):
usb = '/dev/ttyUSB0'
os.system('echo password | sudo chmod 666 /dev/ttyUSB1')
return usb
else:
print('Is there a console connected?')
The error that I keep getting is
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'