💬 Building a wired RS485 sensor network

  • @mfalkvidd I am referring to the code samples from the article 🙂 I think it would be good to have a well documented working example. Maybe that's just me but I am getting a feeling there's a lot of scattered info about RS485 configuration.

  • Admin

    The article was written only a day ago. I'm open to add more information you see fit. Asked the community for help creating a wiring diagram in Fritzing but no one took up the request 😉

    The examples in the article are from directly from the 2.0 repository and should contain the configuration needed.

  • @hek OK, thanks for the hint - thought the article is older. Anyway as I am already on it, I will try to prepare something.

    BTW, Apart from the SerialGateway (where Serial is obviously not available for the debug), should the Serial work for the debug? Assuming I am using AltSoftSerial or Serial1 for the RS485 I guess it should be possible. However with DEBUG on I was not able to get it to work.

  • Admin

    Yes, for a regular node you should be able to print debug info.

  • Please, how many sensors on the bus you tested? I think, that this multimaster rs485 protocol is not very usefull for large number of nodes and heavy traffic..
    I am working on protocol for CAN bus nodes connected to to the serial gateway, but documentation for mysensors code is very bad.
    Its easier for me make it from scratch and use mysensors serial protocol between gateway and controller. only.

  • I would like to create a rs485 network that is 'local' to a specific device, (one that uses many arduinos to manage a process currently using a mega hardware serial ports as the intermediary and local interface ) and one mysensors note to relay sensor data from the rs485(local network) to the wireless mysensors network. Mostly I am wondering if I can use the wired network gateway and wireless network repeter features at the same time? any help is appreciated.


  • Hi, I build up the set up with serial gateway and the motion sensor but nothing happens (only nonsence is is seen in the serial monitor)
    However if I run this small program using the AltSoftSerial library I can communicatie without any issue in both directions.
    Have others the same issue, or what do I overlook?

    #include <AltSoftSerial.h>

    AltSoftSerial altSerial;
    #define SSerialTxControl 2 //RS485 Direction control

    #define RS485Transmit HIGH
    #define RS485Receive LOW
    bool ReceiveOrSend = RS485Transmit;

    void setup() {

    Serial.println("AltSoftSerial Test Begin");
    pinMode(SSerialTxControl, OUTPUT);
    digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
    if (ReceiveOrSend ){
    Serial.println("send mode");
    digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
    } else
    digitalWrite(SSerialTxControl, RS485Receive); // Enable RS485 Transmit
    Serial.println("receive mode");

    void loop() {
    char receivedOnRS485;

    if (ReceiveOrSend ){
    altSerial.println(" Hello world");
    } else

    if (altSerial.available()) {
    receivedOnRS485 = altSerial.read();

  • 2.1.0-beta tested and works between two nanos over altsoftserial
    COM6:GW, COM9:Bus monitor and COM5:Node

  • Tried this but I get an errormessage when I complile sketch for the gateway.
    The node presents itself but the messsage is not recognised/ answered by the gateway.

  • Has anyone else got this working alright ? I've connected 5v, GND, pins 8 to RD. 9 to DI. DE + RE to 2 and connected the rs485 modules via A B. Not getting any replys. Does the rs485 link need a resistor across it? Cheers.

  • @wimd Thanks mate! That topic was just what I was looking for. Works perfectly with defining a node ID!

    Just added this to my sensor node:

    #define MY_NODE_ID <X>

    and everything came together. Thank you for your quick reply.

  • Yes. It is very bad for beginners, that examples in MySensors library are wrong.
    Example "MotionSensorRS485" will never work and I think, that author not tested it.
    MY_NODE_ID must be always defined for node in RS485 network, because is used for RS485 network addressing.
    Obtaining NODE_ID from controller with currentRS485 network implementation is impossible and I think it should be clearly mentioned in the examples and documentation.

  • Admin

    Would be better if someone with a RS485 setup could analyse and fix the root cause of why automatic id assignment doesn't work than just change the example to use static ids.

    Did the id request reach your controller or gateway? Did the id response get to your gateway?

  • @hek
    I think it is simply. In radio network, each node has its unique "radio ID" , witch is used for delivering messages between nodes in radio network. So node can send message " Give me NODE_ID" and gateway or controller knows to witch radio ID send message with assigned NODE_ID in it.
    But in RS485 network we had not unique network ID by default - we use directly NODE_ID for addressing messages between nodes.

  • Admin

    No, it follow exactly the same flow as in a radio network. The gateway (and nodes) should listen to "channel" 255 which is used for broadcast messages (picked up by anyone interested; I.e. repeaters and nodes waiting for new id).

    When a id request is sent out from a node, the gateway will forward it to the controller.. the controller sends out the new id on 255 (which is forwarded by the gateway) and (hopefully) picked up by the new node.

    So somewhere in stil flow the message is not sent along for some reason. Which controller do you use @kimot?

  • @hek
    I am using Domoticz, but not using RS485, instead I am working on CAN protocol layer for MySensors or using only MySensors serial gateway protocol in my CAN-to-Domoticz gateway. For that reason I am studying source code of MYSensors a lot of. Its only useful documentation source, unfortunately.
    Imagine, if you "switch on" entire your network with 10 nodes. Each node send request for NODE_ID to the gateway and gateway send broadcast with assigned NODE_ID. How RS485 nodes recognizes, that this NODE_ID is exactly for specific node?
    Why in radio network is something like MY_RF24_NODE_ADDRESS?
    ( five bytes long, 4 are constant, fifth is radio ID )
    I seems, that entire this "MySensors network DHCP" stuff is made in different level then MyTransportXXXXX.cpp level. Maybe radio drivers ?
    If you know, how it works, pleas write here or send link, please.
    I can imagine only mechanism, when only one new node is connected at time, or some random generated number in each node or unique serial number etc. Then gateway can send NODE_ID with this "mark" end receiving node knows, that this is for it.

  • Admin

    @kimot said:

    Imagine, if you "switch on" entire your network with 10 nodes. Each node send request for NODE_ID to the gateway and gateway send broadcast with assigned NODE_ID. How RS485 nodes recognizes, that this NODE_ID is exactly for specific node?

    This will not work (and the same applies for a radio network). All nodes will then pick the broadcasted id.

    This is known limitation and has its technical background in how the radios work and that the new have problem generating a good unique random number when it starts blank.

    I know we had some ideas of adding a payload (random number) on the id-request payload identifying the requesting node. The node then also check that this number is the same in the id-response. But would break backward compatibility with the serial protocol so it would only happen in a bigger (3.0?) release.

    Edit: Added issue so we won't forget it.

  • @hek
    Thanks for your explanation.
    Last question for you. I cannot find information about internal message strukture.
    Only this discussion:
    "hacking" libraries

    Witch version is actual?

    I need myself write translation between my network message format and MySensors message format to use
    something like MyTransportRS485.cpp. But I have limited number of bytes for payload, so I need modify and test "data" array too.

Log in to reply

Suggested Topics





Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.