ryslaysall
Posts: 4
Joined: Wed Jan 13, 2016 5:10 am

Serial connection: No such file or directory: ' /dev/ttyS0'

Tue Oct 09, 2018 4:30 am

Hi

I'm using a Raspberry Pi 3B+ and is trying out serial connection.
what I did:
1. Enable serial connection
2. in command line: dmesg | grep tty

Code: Select all

[    0.001205] console [tty1] enabled
[    0.931779] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[    0.936465] console [ttyS0] disabled
[    0.939550] 3f215040.serial: ttyS0 at MMIO 0x0 (irq = 220, base_baud = 31250000) is a 16550
[    2.005494] console [ttyS0] enabled
[    6.207354] usb 1-1.2: cp210x converter now attached to ttyUSB0
3. In main.py

Code: Select all

ser = serial.Serial(
        port=' /dev/ttyS0', 
        baudrate = 9600
)
However I get this error message:

Code: Select all

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: ' /dev/ttyS0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 7, in <module>
    baudrate = 9600
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 236, in __init__
    self.open()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port  /dev/ttyS0: [Errno 2] No such file or directory: ' /dev/ttyS0'
Do I have the wrong path to /dev/ttyS0 or is it a permission issue?

User avatar
PeterO
Posts: 4257
Joined: Sun Jul 22, 2012 4:14 pm

Re: Serial connection: No such file or directory: ' /dev/ttyS0'

Tue Oct 09, 2018 7:07 am

It looks like you have a USB serial adapter plugged in ...

Code: Select all

[    6.207354] usb 1-1.2: cp210x converter now attached to ttyUSB0
If that is the device you are trying to use, then it is accessed via /dev/ttyUSB0

Also, the onboard serial interface is accessed via /dev/ttyAMA0

HTH

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

DirkS
Posts: 9211
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Serial connection: No such file or directory: ' /dev/ttyS0'

Tue Oct 09, 2018 7:47 am

PeterO wrote:
Tue Oct 09, 2018 7:07 am
Also, the onboard serial interface is accessed via /dev/ttyAMA0
:?:
On a Pi3B+ with just serial enabled it will be /dev/serial0 or /dev/ttyS0
/dev/ttyAMA0 is used by bluetooth

User avatar
bensimmo
Posts: 3307
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Serial connection: No such file or directory: ' /dev/ttyS0'

Tue Oct 09, 2018 7:55 am

How did you enable the serial connection ?

It should normally be done (as an easy method)
sudo raspi-config
Select option 5, Interfacing options,
then option P6, Serial,
Select No to Serial Console
Select Yes to Serial Port.
Reboot.

you'll find it on /dev/serial0

though that is if you are using the two GPIO UART pins.
Not for USB Serial, with that you just plug it in and use /dev/ttyUSB0 as mentioned above.

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