Trying to get serial port working

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:

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:

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!

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?

here is my flow:

[{"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.

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:

alternatively you can just wait for a period to split the input up (probably the simplest to get right):

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.

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