RS485 network not running... please help!



  • Hi,
    I know here are some who got it working, but there is still some bug for me. Luckily I was able to get it so far, that the gateway is recognizing the messages of the node - but the node don't know it ;-/. It starts the pairing process up and again for endless time...

    Please give me the so important hints.
    I copy you all the code to give the most possible information:

    gateway code:

    // hard coded device id:
    #define MY_NODE_ID 0
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 7
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Enable this if RS485 is connected to a hardware serial port
    //#define MY_RS485_HWSERIAL Serial1
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    /*
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3
    */
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    #define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
    
    #include <MySensors.h>
    
    void setup()
    {
    	// Setup locally attached sensors
    }
    
    void presentation()
    {
    	// Present locally attached sensors
    }
    
    void loop()
    {
    	// Send locally attached sensor data here
    }
    

    gateway output:
    0;255;3;0;9;MCO:BGN:INIT GW,CP=RSNGA--,VER=2.1.1
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;18;2.1.1
    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    0;255;3;0;9;TSF:MSG:READ,23-23-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSF:MSG:BC
    0;255;3;0;9;TSF:MSG:FPAR REQ,ID=23
    0;255;3;0;9;TSF:CKU:OK,FCTRL
    0;255;3;0;9;TSF:MSG:GWL OK
    0;255;3;0;9;TSF:MSG:SEND,0-0-23-23,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    0;255;3;0;9;TSF:MSG:READ,23-23-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSF:MSG:BC
    0;255;3;0;9;TSF:MSG:FPAR REQ,ID=23
    0;255;3;0;9;TSF:CKU:OK,FCTRL
    0;255;3;0;9;TSF:MSG:GWL OK
    0;255;3;0;9;TSF:MSG:SEND,0-0-23-23,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0

    node code:

    // software serial:
    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(8, 9);
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 7
    
    #include <MySensors.h>
    
    // hard coded device id:
    #define MY_NODE_ID 23
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Enable this if RS485 is connected to a hardware serial port
    #define MY_RS485_HWSERIAL mySerial
    
    unsigned long SLEEP_TIME = 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;
    
    	Serial.println(tripped);
    	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);
    }
    

    node output:
    MCO:BGN:INIT NODE,CP=RSNNAβ€”,VER=2.1.1
    3 TSM:INIT
    4 TSF:WUR:MS=0
    5 TSM:INIT:TSP OK
    7 TSF:SID:OK,ID=23
    9 TSM:FPAR
    26 TSF:MSG:SEND,23-23-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2033 !TSM:FPAR:NO REPLY
    2035 TSM:FPAR
    2053 TSF:MSG:SEND,23-23-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4061 !TSM:FPAR:NO REPLY
    4063 TSM:FPAR
    4080 TSF:MSG:SEND,23-23-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6088 !TSM:FPAR:NO REPLY
    6090 TSM:FPAR
    6108 TSF:MSG:SEND,23-23-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8116 !TSM:FPAR:FAIL
    8117 TSM:FAIL:CNT=1
    8119 TSM:FAIL:PDT
    18122 TSM:FAIL:RE-INIT

    Do you have any idea what can I do?

    Thank you very much for your support!
    Best regards Kduino


  • Mod

    The gateway is getting the request from node and it replies but the node is not receiving, did you check the cabling/termination?



  • Hi gohan,
    thank you very much, I will check that. The node and gateway are only 5 cm away from each other since I am using a testing area. So no realtime conditions yet. Therefore I didn't use a terminating resistor which is (I thought until now) ok for the length below of some meters...


  • Mod

    The termination prevents signal from bouncing back when it reaches the end of the cable



  • Hi, I tried different Max485 modules but it was just the same. Finally I directly connected the two machines over RX->TX and TX->RX, then it is working fine. So I go in further investigation now where to find the problem on RS485 πŸ˜‰



  • @kduino
    Try
    #define MY_NODE_ID 23

    before

    #include <MySensors.h>

    not after.

    Try RS485 examples from MySensors library - "MotionSensorRS485"
    only add
    #define MY_NODE_ID 23

    before

    #include <MySensors.h>

    It works.



  • Hi,
    unfortunately it is not working. I have two R200 resistors at the end of my 3 cm long track, I changed the position of MY_NODE_ID...
    I will look on the RS485 network closer the next days. Thank you for your help!
    Have a nice weekend.


  • Mod

    Try with a lower resistance. But what cable are you using?



  • For testing I just put the two max485 bricks on a strip board and bridged a->a and b->b, 2-3 cm long jumper wire πŸ™‚
    I will use a cable instead in the afternoon together with two r100.
    I also tested different max bricks to rule out malfunction. Without success.



  • @kimot
    I started with the examples. Then I introduced soft serial and as far as I consider the direct connection via serial it works. So I checked the de pins, they go active while sending. All good in this part... but together with the max485 the node still doesn't get the gateways response. We will see. Need another evening to try.



  • "Writing multiple SOH"
    Most likely not the problem what AP has but I think its good to mention also in this thread: https://forum.mysensors.org/post/56960



  • Hi,
    ok I started the next run, I checked the voltage levels (Multimeter is showing a differential of A&B of 0.2 V and is going up during sending.
    The Breadboard has no short circuit potential, the wire is now 2x2x0.3 and about 50 cm long, I added R100 to each end...
    Then I copied the sketches of the rs485 stresstest posted in the forum...
    But it is not working though... ;-(
    Any ideas?
    Thank you.

    This is what the node prints now:
    621470 TSM:FPAR
    4621471 TSM:FPAR:STATP=0
    4621474 TSM:ID
    4621475 TSM:ID:OK
    4621477 TSM:UPL
    4621488 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    4623496 TSM:UPL
    4623506 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    4625513 TSM:UPL
    4625523 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    4627530 TSM:UPL
    4627540 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    4629548 !TSM:UPL:FAIL

    Is there any place where I can look up the abbreviations?


  • Mod

    @kduino main site, look for log parser



  • @kduino
    We can see debug info from your node.
    It is through USB port on Arduino?

    Because I can see:

    #define MY_RS485_HWSERIAL mySerial

    In your node code example.

    HW serial on Arduino is connected to serial-USB converter normally.
    You cannot use it for both - debug through USB and RS485 at the some time.

    But I think, it is mistake only, because on the start of the code you define:
    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(8, 9);

    Try delete HW serial definition.

    According debug info, it seems, that your node can sending and gateway is receiving his messages,
    but node do not receive messages from gateway.

    Or, if your communication works with direct TX-RX connection, try drivers for CAN bus instead of MAX485 ones. It eliminates possible problems with DEpin.



  • Hi Kimot,
    thank you for your message. I have already built several nodes which don't have the right pinout since I didn't come across mysensors at this time. I asked here in the forum and @hek wrote, I can use SoftwareSerial as well defining it via MY_RS485_HARDWARESERIAL. It will fallback to AltSoftSerial if it doesn't work correctly...
    As I mentioned I used this configuration also connecting RX-TX and TX-RX directly and it worked fine. So I assume something is wrong with the RS485 part of my setting. Unfortunately I don't have some Can driver at home.
    The DE-Pins are working correctly. Each of them I connected to Led and they are flashing while sending (I assume). So there is somehow a connection, but only in one direction.
    My next step is to change the input output pins on the node arduino, sometimes one have bad luck and is struggling for weeks on a problem and the simple result is one burned pin...
    Thank you again I keep you updated,
    kduino



  • @gohan Thank you, the main message is:
    Status: OK (OK=success, NACK=no radio ACK received)
    So I have to investigate the RX channel of my node.
    By kduino


  • Mod

    @kimot can you really swap rs485 with a can bus driver and everything would still work without changing code?



  • Hi,
    Trank you all for your support. I got in running finally.
    I reassembled the complete thing on the breadboard. Then I connected the wires directly (rx-tx and tx-rx). After changing the position of the inclusion of mysensors.h for some times and using the standard pins and the preset node id it worked.
    Then I went further to test software serial lib which worked great. Then I extended the model to use the rs485 and after some adaptation of the wires (it's always the wires after some frustrating nights) it worked.
    For understanding I integrated also two led to signaling the sending via the de pin. This helped a lot.
    As this was working correctly I turned up the speed. Ok, 250.000 bps were too much, but 115.200 were running without any complaints. On a breadboard though but without any cable adaption or resistor as final terminator.
    So for this topic we can conclude that if rs485 is not even running on 9600 bps on a breadboard, it's not because of the cable or the terminating resistors. In this setting it should work anyway. Unless you have no bug somewhere else....
    So for all my followers again thank you very much. I can only suggest to myself to reassemble the test unit completely to rule out any wrong connections....
    Bye kduino



  • @hek
    I used some time to get further. As my tests show I can easily use the Arduino nano on pin 8 and 9, but the strategy of using SoftwareSerial you mentioned is not working.
    See what I did below. The problem is now as follows:
    If I state the HW_SERIAL command before the inclusion of mysensors.h the hardware serial is somehow not initialized and therefore throws an error on compilation. Only hardware serial ports are allowed.
    If I state the HW_SERIAL command after the inclusion of mysensors.h the inlcusion has no effect, thus the defined pins are not rx and tx.
    Do you know any advice for that?

    Thank you so much for your support!

    By kduino

    Part of my ino file:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 3
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // node Id:
    #define MY_NODE_ID 5
    
    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(4, 2); // RX, TX
    
    #include <MySensors.h>
    #include <Bounce2.h>
    
    // Enable this if RS485 is connected to a hardware serial port
    #define MY_RS485_HWSERIAL mySerial
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    

    Part of the error:
    This line is marked yellow:
    #define MY_RS485_HWSERIAL mySerial
    Error description:

    MySTestSensorRS485_working__2017-06-20_vRS485_1:68: error: invalid initialization of reference of type 'HardwareSerial&' from expression of type 'SoftwareSerial'
     #define MY_RS485_HWSERIAL mySerial
                               ^
    /Users/macmuc/Documents/Arduino/libraries/MySensors-master/core/MyTransportRS485.cpp:97:24: note: in expansion of macro 'MY_RS485_HWSERIAL'
     HardwareSerial& _dev = MY_RS485_HWSERIAL;
                            ^
    exit status 1
    invalid initialization of reference of type 'HardwareSerial&' from expression of type 'SoftwareSerial'
    


  • Note about RS485:

    I've had (non-MySensors) issues with RS485 with some setups due to the fact that while the bus is not driven (no one sends anything) it's floating and not in idle state. This makes receivers pick random garbage. To make it stable you'd need to add pullup to the A line and pulldown to the B line (hope I remember polarity right way). Those will make sure the line stays idle. With two 120R terminators (both ends) the pullup/down needs to be quite small to create enough voltage across 60R. One could calculate (I think spec says 200mV), but I've used 470..680R with 5V system. Some interface modules may have these or similar current source on board.

    Termination with low speeds and short lines seems not so critical in practise.



  • Hi Kisse66,

    thank you very much for this advice. Most of the forum writers are pointing on the terminating resistors, but in my experience they are not the key.
    I put two 680R from B to GND and A to 5V and the reliability I experienced has improved tremendously!
    Thank you for the hint.

    Another question I have: The gateway is receiving the messages now but there is no ACK. How can I ask for an ack for security relevant messages?

    Thank you
    By kduino


Log in to reply
 

Suggested Topics

47
Online

11.4k
Users

11.1k
Topics

112.6k
Posts