Corrupted data from RS485 Sensor Node

  • Hello. I'm using Arduino Pro Mini (atmega328) and checking one of basic examples (MotionSensorRS485). The gateway is connected via same RS485 converter. Unfortunately they do not communicate.
    First I checked connection (direct TX-RX/RX-TX) connection - with failure. Then I took another USB/TTL converter to check what is on the output of softserial - and I found some kind of garbage data. It looks like wrong baudrate so I checked all "standard" speeds from 2400 up to 115200. (Configured to 9600).
    Then I enabled DEBUG, enabled HWSERIAL and set to Serial. Both baudrates set to 9600. So I have now both, the communication frame and debug. See screenshot below.


    When I disable DEBUG, only corrupted frame left:

    The code:

    //#define MY_DEBUG
    //#define MY_DEBUG_LOCAL
    // Enable RS485 transport layer
    #define MY_RS485
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    // Set RS485 baud rate to use
    #define MY_BAUD_RATE 9600
    #define MY_RS485_BAUD_RATE 9600 //19200 //57600 //38400 //9600
    #define MY_RS485_SOH_COUNT 1
    #define MY_RS485_HWSERIAL Serial
    //#define MY_PASSIVE_NODE
    #define MY_NODE_ID 10
    #include <MySensors.h>
    uint32_t SLEEP_TIME = 3000;//+120000 // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define CHILD_ID 1   // Id of the sensor child
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    void setup()
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    void presentation()
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Motion Sensor", "1.0");
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID, S_MOTION);
    void loop()
        // Read digital motion value
        bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
        send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        //sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);

    An Idea? Arduino board is not corrupted, any short sketch with SoftSerial library works fine. Haven't checked MySensors with SoftSerial though. MySensors version 2.3.2. Checked on Arduino IDE and VSC.

  • What about RS485 bus topology and connection to RS485 recievers on Arduino Pro Mini module?

  • Hi Cabat. Both checked. I wrote my own code to test it. I'm having my own working RS485 network at home already. I did it by myself and I'm pretty experienced in debugging ;). I want to switch to MySensors now due to more flexibility.
    So to summarize:

    • it is not a RS485 issue, tested,
    • it is not a USB/TTL converter issue, tested,
    • it is not an UART bitrate issue, not on the PC side at least,
    • there is no difference if I use hardware or software serial - same content.

    I have conserns about the Library. According to this page:
    the typical frame sent by a node should be like this:
    12;6;0;0;3;My Light\n

    As you can see on picture in firs post, when I configured to use HWSerial for RS485 and DEBUG set ON, I shall expect both - Communication and Debug on the same line. Debug data is correct, but the frame is nothing like a text message - looks like the content is sent in HEX not ASCII.
    I learned there is no encryption, so it is not an encrypted data I assume.

  • RS485 data is different to serial api. Serial api is only from gateway to controller.
    Please check links in 1st post.

  • Yes, I realized that last Sunday. I went through the code of library. I had to switch to another project for a week or so, then I come back to it. Thanks!

Log in to reply

Suggested Topics

  • 15
  • 3
  • 11
  • 5
  • 1
  • 4
  • 4
  • 42