1

I am trying to get access to the /dev/ttyS0 file in an attempt to connect an OPC to the RPi via TX and RX connection.

However, when I am in the /dev directory, when I type in /dev/ttyS0 I get the message: "Permission denied." How do I overcome this problem?

1

3 Answers 3

1

I'll assume your question is literal.

You can't execute a device as a program.

If you want to see what is arriving on /dev/ttyS0 do

cat </dev/ttyS0

If you want to write to /dev/ttyS0 do

echo "text" >/dev/ttyS0

Normally you write a program to talk to the serial link or use something like minicom to debug.

If this doesn't help could you edit your question and show the result of

ls -l /dev/ttyS0

and

stty -F /dev/ttyS0

If your permissions are not correct you may need to precede the commands with sudo.

6
  • When I do the command 'cat </dev/ttyS0' I get 'bash: /dev/ttyS0: No such file or directory'
    – user44164
    Commented Apr 12, 2016 at 18:43
  • Do I need to create a '/dev/ttyS0' file?
    – user44164
    Commented Apr 12, 2016 at 18:44
  • Which model Pi are you using?
    – joan
    Commented Apr 12, 2016 at 18:49
  • Model A, one of the first Pi's
    – user44164
    Commented Apr 12, 2016 at 19:31
  • It turns out I just solved the problem by using /dev/ttyUSB0, however I am pretty confused why that worked. Initially I had the tx and rx pins on a device hooked up to a VGA to USB converter which then plugged into the Pi USB port. I wanted to remove this VGA converter so I connected the TX and RX pins from the device to the Pi's TX and RX pins (as well as ground). I thought that I would need to change this /dev file in my python script to some sort of serial port (/dev/ttyS0) but I guess not. Do you know why this is?
    – user44164
    Commented Apr 12, 2016 at 19:38
1

As has been answered in the comments, Raspberry Pis don't generally have a /dev/ttyS0 device. The GPIO serial port is typically /dev/ttyAMA0, although that's not always the case on a Raspberry Pi 3.

All available serial ports belong to the dialout group, so for convenient read/write access it's best to issue this command once:

sudo usermod -a -G dialout pi

(This may be a default now on Raspbian.) You need to log out and back in again for this change to work, but then it should be valid indefinitely.

Serial ports can also have aliases. /dev/serial0 (or dev/serial1 by default on a 3) points to /dev/ttyAMA0. There are also the /dev/serial/by-path/* and /dev/serial/by-id/* devices that can be helpful for identifying particular ports. If you have multiple USB serial devices, the system will allocate ttyUSB0 to the first one identified, ttyUSB1 to the next, and so on. These aren't always in the same order, so the by-path and by-id aliases help you find the right physical port.

0

I use them all the time.

Usually it will be /dev/ttyUSB0

but for some Chinese Arduino Unos it can be /dev/ttyACM0.

The way you find out is to do a

ls /dev/tty*

then connect your device and do it again.

You will see where it has appeared in the list.

You must be a member of the dialout group to use them.

If you install Arduino IDE it will automatically add you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.