# Communicating with stepper driver over RS232 or RS485

**URL:** <https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061>\
**Category:** General\
**Created:** [17 November 2020 13:07 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061 "2020-11-17T13:07:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sensors](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sensors](https://discourse.nodered.org/u/Sensors)\
**Post date:** [17 November 2020 13:07 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/1 "2020-11-17T13:07:44Z")

</div>

Hello all,

I'm fairly new to node red so still getting my head around the best way to do things...

I have a Trinamic multi-stepper driver which can communicate over RS232 or RS485, which I need to first configure with a series of specific commands, before then sending occasional additional varied commands and waiting for responses to continue with different processes.

I think what I want to do is send one command and wait for a response before moving to the next automatically. This might have to be looped a few times with altered parameters to configure each individual motor driver channel with different settings.

What's the best way to achieve this? I can't seem to get my head around how to send cmd1, receive response, send cmd2, receive response, etc. in a way that I can loop and configure it.

Trinamic do offer a [Python library](https://github.com/trinamic/PyTrinamic) to communicate with devices, but I'm not sure how well that would integrate with node red.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 November 2020 14:27 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/2 "2020-11-17T14:27:11Z")

</div>

If no-one else chimes in who knows about that device then the easiest thing is probably to use the python library. You can use an exec node to call a python script (or a daemon node), or you could have a service written in python which communicates with node-red via MQTT.

---

<div class="post-metadata">

**Author:** ![Sensors](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sensors](https://discourse.nodered.org/u/Sensors)\
**Post date:** [17 November 2020 16:30 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/3 "2020-11-17T16:30:25Z")

</div>

So could I call a script which would take care of all the set up, and then from there on communicate with it over MQTT? Or will it only run in the background if it's a service?

his definitely sounds like a good approach though, I'm keen to explore it. Do you have any resources on how I might be able to pass the data back and forth between Node Red and the running script/service? Also, does Node Red handle all the MQTT server stuff or would I need to run something else to deal with this?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 November 2020 21:29 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/4 "2020-11-17T21:29:51Z")

</div>

> [@Sensors](#):
>
> So could I call a script which would take care of all the set up, and then from there on communicate with it over MQTT? Or will it only run in the background if it's a service?

Either

If you add the mqtt client code into the python code (which I gather is very easy) and you install mosquitto as an mqtt broker (which again is very easy) then node-red will easily connect to mqtt to give you a comms channel between the two. If you haven't used mqtt before then have a look at this excellent tutorial [MQTT Essentials - All Core Concepts Explained](https://www.hivemq.com/mqtt-essentials/)

---

<div class="post-metadata">

**Author:** ![Sensors](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sensors](https://discourse.nodered.org/u/Sensors)\
**Post date:** [18 November 2020 11:25 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/5 "2020-11-18T11:25:37Z")

</div>

Thanks, I'll look into that.

I've also stumbled across the Daemon node, which I think may allow me to set up the script in the first instance before then communicating with it via MQTT. Maybe I can do everything through the daemon node, but I'm not totally sure if that's a good idea yet!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 November 2020 12:21 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/6 "2020-11-18T12:21:02Z")

</div>

Yes, the daemon node is one of the options, as I mentioned in my first post.

---

<div class="post-metadata">

**Author:** ![Sensors](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sensors](https://discourse.nodered.org/u/Sensors)\
**Post date:** [18 November 2020 14:38 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/7 "2020-11-18T14:38:59Z")

</div>

Ah so you did! Apologies I didn't immediately pick up on that, it's been a bit of a learning process going down a few rabbit holes!

In terms of sending data/commands to a script running in the Daemon node, is MQTT the only way to achieve this?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 November 2020 15:05 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/8 "2020-11-18T15:05:53Z")

</div>

> [@Sensors](#):
>
> is MQTT the only way to achieve this?

No, there are numerous ways, you could use http for example, but I am sure MQTT is the easiest. It is almost trivial. Two minutes to install mosquitto, two minutes to configure an mqtt node in node-red and, I understand, it is only a few lines of python.

---

<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:** [17 January 2021 15:05 UTC](https://discourse.nodered.org/t/communicating-with-stepper-driver-over-rs232-or-rs485/36061/9 "2021-01-17T15:05:55Z")

</div>

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