# Trying to get serial port working

**URL:** https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129
**Category:** General
**Created:** [19 June 2022 10:28 UTC](https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129 "2022-06-19T10:28:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Roaders](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roaders/32/11282_2.png) [@Roaders](https://discourse.nodered.org/u/Roaders)
#### Post date: [19 June 2022 10:28 UTC](https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129/1 "2022-06-19T10:28:18Z")

</div>

Hi All  
I am trying to get my raspberry pi to connect to an RS232 port to add the data received to a database. After quite a bit of pain actually getting the USB port to work correctly (it seems the driver doesn't work in latest raspberry pi os) I am now trying to get a loopback to work in node red. I have tried this with both my USB serial port (ttyUSB0) and the included serial port on the raspberry pi (ttyAMA0).

I have connected the correct pins together on the rs232 plug and I have connected gpio pins 8 and 10 together. In node red I am send a simple string payload to the serial in node but am getting nothing back from the receive node.

In the console I see that the serial ports are correctly opened by node red:

```auto
19 Jun 11:20:12 - [info] [serialconfig:d94a50c03d0c040f] serial port /dev/ttyUSB0 opened at 57600 baud 8N1
19 Jun 11:20:12 - [info] [serialconfig:493cbee11e72cc59] serial port /dev/ttyAMA0 opened at 57600 baud 8N1

```

the baud is what is returned when I run this:

```auto
pi@raspberrypi:~ $ stty -F /dev/ttyAMA0
speed 57600 baud; line = 15;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

```

I'm a bit lost now and it seems to me (if my understanding of how this works is correct but it might not be) that I should be getting whatever I send into the serial out node back from the serial in node.

Any help much appreciated!

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [19 June 2022 11:18 UTC](https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129/2 "2022-06-19T11:18:51Z")

</div>

Maybe you can share/show use the code you are using in NR.  
Did you added CR& LF ( \r\n ) to the OUTPUT in the out node?

---

<div class="post-metadata">

### Author: ![Roaders](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roaders/32/11282_2.png) [@Roaders](https://discourse.nodered.org/u/Roaders)
#### Post date: [19 June 2022 13:08 UTC](https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129/3 "2022-06-19T13:08:23Z")

</div>

here is my flow:

```auto
[{"id":"3617213c276d34c0","type":"serial in","z":"c9ed69e89c5c1d8b","name":"serial in","serial":"493cbee11e72cc59","x":250,"y":620,"wires":[["41c00b1533cb5be6"]]},{"id":"41c00b1533cb5be6","type":"debug","z":"c9ed69e89c5c1d8b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":620,"wires":[]},{"id":"092ce461233fbbd8","type":"inject","z":"c9ed69e89c5c1d8b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":520,"wires":[["2b8a5d1faaa8ada6"]]},{"id":"feddaa0e6e68a27a","type":"serial out","z":"c9ed69e89c5c1d8b","name":"","serial":"493cbee11e72cc59","x":670,"y":520,"wires":[]},{"id":"2b8a5d1faaa8ada6","type":"change","z":"c9ed69e89c5c1d8b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"hello world","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":520,"wires":[["feddaa0e6e68a27a"]]},{"id":"493cbee11e72cc59","type":"serial-port","serialport":"/dev/ttyAMA0","serialbaud":"57600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"\\r\\n","responsetimeout":"10000"}]

```

I tried adding `\r\n` to the output but it didn't seem to make any difference.

---

<div class="post-metadata">

### Author: ![Roaders](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roaders/32/11282_2.png) [@Roaders](https://discourse.nodered.org/u/Roaders)
#### Post date: [19 June 2022 13:35 UTC](https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129/4 "2022-06-19T13:35:21Z")

</div>

OK, I have got it working. I had not setup the serial port configuration node properly. I either needed to add `\n` to the end of messages AND split the input on `\n`:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2d2bb45dbe746e43c9f43d81a7b52d323202944.png)  
alternatively you can just wait for a period to split the input up (probably the simplest to get right):  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/2537e1db516822503eac26cbe3560a026ebe15eb.png)

---

<div class="post-metadata">

### Author: ![Roaders](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roaders/32/11282_2.png) [@Roaders](https://discourse.nodered.org/u/Roaders)
#### Post date: [19 June 2022 13:36 UTC](https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129/5 "2022-06-19T13:36:13Z")

</div>

Also for RS232 make sure that you bridge the correct pins. I was looking at a mirror image of the plug so had bridged the wrong ones.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 August 2022 13:36 UTC](https://discourse.nodered.org/t/trying-to-get-serial-port-working/64129/6 "2022-08-18T13:36:53Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
