# Cant get serialport to work

**URL:** <https://discourse.nodered.org/t/cant-get-serialport-to-work/6719>\
**Category:** General\
**Created:** [12 January 2019 14:47 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719 "2019-01-12T14:47:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChuckBanger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chuckbanger/32/5122_2.png) [@ChuckBanger](https://discourse.nodered.org/u/ChuckBanger)\
**Post date:** [12 January 2019 14:47 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/1 "2019-01-12T14:47:21Z")

</div>

I have a node red installed om a RPI3. I'a new to node red so maybe this is easy...

I try to use node-red-node-serialport to send serial request. When i hit deploy i get this debug message: "serial port /dev/ttyS0 error: Error: Error: Permission denied, cannot open /dev/ttyS0"

And when i try to run my flow the serial request node i get this: {"\_msgid":"405525b5.e8422c","topic":"","request\_payload":"A100","request\_msgid":"405525b5.e8422c","port":"/dev/ttyS0","status":"ERR\_TIMEOUT"}

My flow:  
`[{"id":"753a664c.ef994","type":"inject","z":"323daace.0f9796","name":"","topic":"","payload":"A100","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":480,"wires":[["5ae185b8.cf4aa4"]]},{"id":"5ae185b8.cf4aa4","type":"serial request","z":"323daace.0f9796","name":"","serial":"a94ce253.ff6bd","x":440,"y":480,"wires":[["9b09df4b.b7662"]]},{"id":"9b09df4b.b7662","type":"debug","z":"323daace.0f9796","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":480,"wires":[]},{"id":"a94ce253.ff6bd","type":"serial-port","z":"","serialport":"/dev/ttyS0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false,"responsetimeout":"10000"}]`

This python script works, so i know serial works in my pi:  
`#!/user/bin/python  
import serial  
ser = serial.Serial('/dev/ttyS0',9600)

while True:  
ser.write('A100')`

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [12 January 2019 14:55 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/2 "2019-01-12T14:55:55Z")

</div>

Only one thing can access the serial port make sure nothing else is accessing it

---

<div class="post-metadata">

**Author:** ![ChuckBanger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chuckbanger/32/5122_2.png) [@ChuckBanger](https://discourse.nodered.org/u/ChuckBanger)\
**Post date:** [12 January 2019 16:03 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/3 "2019-01-12T16:03:47Z")

</div>

I have turned off bluetooth and reboot the pi. But I get the same result that's what you mean...

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 January 2019 17:23 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/4 "2019-01-12T17:23:04Z")

</div>

> [@ChuckBanger](#):
>
> "serial port /dev/ttyS0 error: Error: Error: Permission denied, cannot open /dev/ttyS0"

The error shows you exactly what is wrong.

The user id you are using to run Node-RED does not have rights to the serial ports.

Check the permissions on `/dev/ttyS0` by issuing the command `ls -l /dev/ttyS0` from a command prompt. You will see the owning user followed by the group. Make sure that the user id running Node-RED is in the group. Then restart Node-RED.

---

<div class="post-metadata">

**Author:** ![ChuckBanger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chuckbanger/32/5122_2.png) [@ChuckBanger](https://discourse.nodered.org/u/ChuckBanger)\
**Post date:** [13 January 2019 09:28 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/5 "2019-01-13T09:28:18Z")

</div>

Okay thanks. When i run `ls -l /dev/ttyS0` I get: `crw--w---- 1 root tty 4, 64 Jan 12 14:02 /dev/ttyS0`

There is a user called nodered so I added that to tty by running `usermod -a -G tty nodered`, but no luck.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [13 January 2019 09:32 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/6 "2019-01-13T09:32:02Z")

</div>

what user are you when you start Node-RED ?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 January 2019 09:37 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/7 "2019-01-13T09:37:43Z")

</div>

with those permissions - even the tty group only has write access which doesn't seem right. What created that serial port in the first place ?

---

<div class="post-metadata">

**Author:** ![ChuckBanger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chuckbanger/32/5122_2.png) [@ChuckBanger](https://discourse.nodered.org/u/ChuckBanger)\
**Post date:** [13 January 2019 09:48 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/8 "2019-01-13T09:48:16Z")

</div>

I use DietPi and installed node-red via dietpi-software. So I guess user nodered is running node-red. But I don't know

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 January 2019 12:08 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/9 "2019-01-13T12:08:49Z")

</div>

Did you configure/enable the serialport correctly via the DietPi software ? Does it work OK outside of Node-RED ?

---

<div class="post-metadata">

**Author:** ![ChuckBanger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chuckbanger/32/5122_2.png) [@ChuckBanger](https://discourse.nodered.org/u/ChuckBanger)\
**Post date:** [13 January 2019 12:32 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/10 "2019-01-13T12:32:07Z")

</div>

I installed serialport from "Manage Palette" in node-red. And i've tested so many things so I don't know any more what i've done and what was done by the installation process. Yes i tested with this simple python script and it works:  
#!/user/bin/python  
import serial  
ser = serial.Serial('/dev/ttyS0',9600)

while True:  
ser.write('A100')

---

<div class="post-metadata">

**Author:** ![ChuckBanger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chuckbanger/32/5122_2.png) [@ChuckBanger](https://discourse.nodered.org/u/ChuckBanger)\
**Post date:** [13 January 2019 12:56 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/11 "2019-01-13T12:56:31Z")

</div>

I solved it. It's a litle embarrassing. But i run this `chmod a+rw /dev/ttyS0` so it was an access thing. I thought I've done that but clearly no. Thanks for the help 😀

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 January 2019 15:10 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/12 "2019-01-13T15:10:41Z")

</div>

> [@ChuckBanger](#):
>
> ls -l /dev/ttyS0

Generally, serial and USB ports should belong to the "dialout" group:

```
crw-rw---- 1 root dialout 188, 0 Jan 13 14:14 /dev/ttyUSB0

```

That's what most people would expect I think. Rather than adding your Node-RED user to `tty` which isn't especially safe.

---

<div class="post-metadata">

**Author:** ![sairfan1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sairfan1/32/39373_2.png) [@sairfan1](https://discourse.nodered.org/u/sairfan1)\
**Post date:** [28 March 2021 00:06 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/13 "2021-03-28T00:06:09Z")

</div>

When i run the command `ls -l /dev/ttyS0` I can see follwoing

> [@TotallyInformation](#):
>
> crw-rw---- 1 root tty 4, 64 Mar 27 15:53 /dev/ttyS0

what could be the solution change the group for serial port from tty to dialout or anything else i should try,  
while finding the solution i find out that people are chasing this issue since 2016 i hope some of then have found something. thanks

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 March 2021 00:28 UTC](https://discourse.nodered.org/t/cant-get-serialport-to-work/6719/14 "2021-03-28T00:28:59Z")

</div>

You can simply add the user running Node-RED to the `tty` group.

On Debian:

```auto
sudo adduser reduser tty

```

Just note that you will have to log the `reduser` (or whatever user is running Node-RED) out and back in again.

However, I don't think ttyS0 _should_ have a group ownership of `tty`, it is not usual on any version of Linux I'm familiar with. While other _real_ tty devices are root/tty owned, the serial ports should all be root/dialout.

So what I would actually do is change the ownership and add the user to the dialout group.

```auto
sudo chown root:dialout /dev/ttyS*
sudo adduser reduser dialout

```

This will give you a more standard configuration and it is generally more secure as well.

[SystemGroups - Debian Wiki](https://wiki.debian.org/SystemGroups)

> [@sairfan1](#):
>
> while finding the solution i find out that people are chasing this issue since 2016 i hope some of then have found something. thanks

Do you have a reference? Which version of Linux?
