Communicating with stepper driver over RS232 or RS485

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 to communicate with devices, but I'm not sure how well that would integrate with node red.

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.

1 Like

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?


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

1 Like

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!

1 Like

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

1 Like

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?

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.

1 Like