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?


Log in to reply
 

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