I've connected a USB to Serial bridge dongle, and running dmesg | grep tty outputted the following:
[ 0.000000] console [tty0] enabled
[603199.380677] usb 2-2: cp210x converter now attached to ttyUSB0So now I'm trying to write to it as per the answer in this previous question by running the following:
cat hello.txt > /dev/ttyUSB0and
sudo cat hello.txt > /dev/ttyUSB0But both result in the following error:
bash: /dev/ttyUSB0: Permission deniedWhat am I doing wrong?
Thanks
2 Answers
If you still want to use sudo to access the port, the issue is that cat is running with root privileges, but the redirection isn't. Try cat hello.txt | sudo tee /dev/ttyUSB0. This uses the tee tool, run as root. It outputs both to stdout (the terminal), and to the specified destination (in this case, the serial port).
By default as I recall serial ports on Ubuntu belong to the "dialout" group. You can add yourself to this group by running something like the following:
sudo gpasswd --add jodes dialoutYou may need to log out and log back in before this takes effect, but after doing so you should be able to read and write from and to your serial ports including USB to serial converters.
1