Osama29 / NILM

Non-Intrusive Load Monitoring Device
2 stars 0 forks source link

Raspberry Pi Issue - SerialException: Could not open port /dev/ttyS0 [Errno 13] Permission denied: '/dev/ttyS0 #2

Open HazardousCoder opened 10 months ago

HazardousCoder commented 10 months ago

I keep getting this error when i run the code after setting up the raspberry pi

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 322, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/ttyS0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/raspberrypi/PZEM-004t_RaspberryPi.py", line 15, in <module>
    serial_port = serial.Serial(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, xonxoff=0)
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 244, in __init__
    self.open()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 325, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyS0: [Errno 13] Permission denied: '/dev/ttyS0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/raspberrypi/PZEM-004t_RaspberryPi.py", line 122, in <module>
    master.close()
NameError: name 'master' is not defined

------------------
(program exited with code: 1)
Press return to continue

how to fix this issue?

Osama29 commented 10 months ago

the issue can be solved by accessing the raspi-config using these commands in the terminal.

the problem should be resolved after applying those steps