Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. rs485 on nano

rs485 on nano

Scheduled Pinned Locked Moved General Discussion
44 Posts 14 Posters 19.9k Views 15 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • skatunS Offline
    skatunS Offline
    skatun
    wrote on last edited by
    #9

    @dbemowsk so i added the usb device, it produces gibberish:

    ~þx
    

    different baud-rates, gibberish changes.....

    gibberish from the node, but nothing from gateway, I also changed gateway to uno as a test without success, here is the code on gateway which i commented out:

    
    // Flash leds on rx/tx/err
    //#define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // 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 
    
    //#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
    
    dbemowskD consul58C 2 Replies Last reply
    0
    • skatunS skatun

      @dbemowsk so i added the usb device, it produces gibberish:

      ~þx
      

      different baud-rates, gibberish changes.....

      gibberish from the node, but nothing from gateway, I also changed gateway to uno as a test without success, here is the code on gateway which i commented out:

      
      // Flash leds on rx/tx/err
      //#define MY_LEDS_BLINKING_FEATURE
      // Set blinking period
      //#define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // 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 
      
      //#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
      
      dbemowskD Offline
      dbemowskD Offline
      dbemowsk
      wrote on last edited by
      #10

      @skatun

      so i added the usb device, it produces gibberish:

      When working with serial communication, gibberish means that your nodes are talking at different baud rates. Once you get the same baud on both ends, you should see something readable. What baud rate do you have your node set to for the software serial connection? Whatever that is set to is the baud rate that you need to set the USB device to. Once you get that communicating, then check the software serial baud on the gateway. The problem could be that you have differing baud rates on both. If that is the case, your gateway is seeing similar gibberish that you are seeing on your USB adapter and thus does not know what to do with it.

      Another thing is that if you have your baud rate set too high, even though both sides are using matching baud rates, you can still see gibberish. Try starting everything on a lower baud like 9600. If that works, try the next baud rate, and the next. You may be able to run at 115200, but if you have debugging turned on it may have trouble communicating at that speed.

      Also, don't confuse your hardware serial with your software serial. This is the hardware UART serial baud definition:

      Serial.begin(115200);
      

      And this is the software serial baud definition:

      RS485Serial.begin(9600);
      

      These do not necessarily need to match. It is the software serial at all points that need to match.

      Let me know if any of that helps.

      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

      1 Reply Last reply
      0
      • skatunS skatun

        @dbemowsk so i added the usb device, it produces gibberish:

        ~þx
        

        different baud-rates, gibberish changes.....

        gibberish from the node, but nothing from gateway, I also changed gateway to uno as a test without success, here is the code on gateway which i commented out:

        
        // Flash leds on rx/tx/err
        //#define MY_LEDS_BLINKING_FEATURE
        // Set blinking period
        //#define MY_DEFAULT_LED_BLINK_PERIOD 300
        
        // 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 
        
        //#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
        
        consul58C Offline
        consul58C Offline
        consul58
        wrote on last edited by consul58
        #11

        @skatun
        Hi,
        I found the solution.

        Look at this

        Place the following in your Node-Sketch e.g. for Node ID 23

         #define MY_NODE_ID 23
        

        and the communication between node and Gateway is ok.

        I hope this works for you.

        bocmauB 1 Reply Last reply
        1
        • P Offline
          P Offline
          pjr
          wrote on last edited by pjr
          #12

          @skatun did you got this working?
          I faced similar situation when I was accidentally connected rx & tx wrong way around on my GW. The sensor node was constantly polling for parent but got no response.

          The "gibberish" on RS485 bus might also be the control chars the transport uses.. SOH, STX, ETX and EOT.
          See this post.

          In my GW sketch I have these two enabled:

          #define MY_INCLUSION_MODE_FEATURE
          #define MY_INCLUSION_MODE_DURATION 60 
          
          skatunS 1 Reply Last reply
          0
          • P pjr

            @skatun did you got this working?
            I faced similar situation when I was accidentally connected rx & tx wrong way around on my GW. The sensor node was constantly polling for parent but got no response.

            The "gibberish" on RS485 bus might also be the control chars the transport uses.. SOH, STX, ETX and EOT.
            See this post.

            In my GW sketch I have these two enabled:

            #define MY_INCLUSION_MODE_FEATURE
            #define MY_INCLUSION_MODE_DURATION 60 
            
            skatunS Offline
            skatunS Offline
            skatun
            wrote on last edited by
            #13

            @pjr @consul58 Have been away the last 5 days, will update the thread with the result tomorrow. Can anyone lighten me up on benefit of having inclusion button, and what inclusion time should be set to?

            1 Reply Last reply
            0
            • hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by
              #14

              The inclusion mode was initially developed for Vera because it had the bad behaviour of needing a restart (of its main process) each time a device was added.

              It is all a controller-side thing after all (all messages, including presentation is always passed to controller). But the mode can be turned on using a physical button on the gateway device. Which results in a message to controller saying start/stop inclusion mode.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pjr
                wrote on last edited by
                #15

                Good to know. Think then I can throw that away since I'm using domoticz.

                1 Reply Last reply
                0
                • skatunS Offline
                  skatunS Offline
                  skatun
                  wrote on last edited by
                  #16

                  Implemented fixed node ID without success, I think maybe the rs485 adapter on gateway is broken, will test more tomorrow

                  wimdW 1 Reply Last reply
                  0
                  • skatunS skatun

                    Implemented fixed node ID without success, I think maybe the rs485 adapter on gateway is broken, will test more tomorrow

                    wimdW Offline
                    wimdW Offline
                    wimd
                    wrote on last edited by
                    #17

                    @skatun Will join this discussion as well. I have exately the same issue. My set up is a nano as sensor and an uno as gateway.
                    I verified correct wiring of RS485 network is correctly doen I used this sketch (swith ReceiveOrSend to RS485Transmit or RS485Receive on both nodes;
                    :

                    #include <AltSoftSerial.h>
                    
                    AltSoftSerial altSerial;
                    #define SSerialTxControl 2 //RS485 Direction control
                    
                    #define RS485Transmit HIGH
                    #define RS485Receive LOW
                    bool ReceiveOrSend = RS485Transmit;
                    
                    void setup() {
                    
                    Serial.begin(9600);
                    Serial.println("AltSoftSerial Test Begin");
                    pinMode(SSerialTxControl, OUTPUT);
                    digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
                    altSerial.begin(9600);
                    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");
                    delay(2000);
                    } else
                    {
                    
                    if (altSerial.available()) {
                    receivedOnRS485 = altSerial.read();
                    Serial.print("ontvagen=");
                    Serial.println(receivedOnRS485);
                    }
                    }
                    }```
                    dbemowskD 1 Reply Last reply
                    0
                    • wimdW wimd

                      @skatun Will join this discussion as well. I have exately the same issue. My set up is a nano as sensor and an uno as gateway.
                      I verified correct wiring of RS485 network is correctly doen I used this sketch (swith ReceiveOrSend to RS485Transmit or RS485Receive on both nodes;
                      :

                      #include <AltSoftSerial.h>
                      
                      AltSoftSerial altSerial;
                      #define SSerialTxControl 2 //RS485 Direction control
                      
                      #define RS485Transmit HIGH
                      #define RS485Receive LOW
                      bool ReceiveOrSend = RS485Transmit;
                      
                      void setup() {
                      
                      Serial.begin(9600);
                      Serial.println("AltSoftSerial Test Begin");
                      pinMode(SSerialTxControl, OUTPUT);
                      digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
                      altSerial.begin(9600);
                      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");
                      delay(2000);
                      } else
                      {
                      
                      if (altSerial.available()) {
                      receivedOnRS485 = altSerial.read();
                      Serial.print("ontvagen=");
                      Serial.println(receivedOnRS485);
                      }
                      }
                      }```
                      dbemowskD Offline
                      dbemowskD Offline
                      dbemowsk
                      wrote on last edited by
                      #18

                      @wimd As my reply stated in the other thread, it would be helpful to see all sketches being used so we can determine better where the problem may lie.

                      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                      wimdW 1 Reply Last reply
                      0
                      • dbemowskD dbemowsk

                        @wimd As my reply stated in the other thread, it would be helpful to see all sketches being used so we can determine better where the problem may lie.

                        wimdW Offline
                        wimdW Offline
                        wimd
                        wrote on last edited by
                        #19

                        @dbemowsk It are the standard examples.

                        For the gateway (Uno) :

                        * The MySensors Arduino library handles the wireless radio link and protocol
                         * between your home built sensors/actuators and HA controller of choice.
                         * The sensors forms a self healing radio network with optional repeaters. Each
                         * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                         * network topology allowing messages to be routed to nodes.
                         *
                         * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                         * Copyright (C) 2013-2015 Sensnology AB
                         * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                         *
                         * Documentation: http://www.mysensors.org
                         * Support Forum: http://forum.mysensors.org
                         *
                         * This program is free software; you can redistribute it and/or
                         * modify it under the terms of the GNU General Public License
                         * version 2 as published by the Free Software Foundation.
                         *
                         *******************************
                         *
                         * DESCRIPTION
                         * The RS485 Gateway prints data received from sensors on the serial link. 
                         * The gateway accepts input on seral which will be sent out on
                         * the RS485 link.
                         *
                         * Wire connections (OPTIONAL):
                         * - Inclusion button should be connected between digital pin 3 and GND  
                         * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
                         *
                         * LEDs (OPTIONAL):
                         * - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
                         * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
                         * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
                         * - ERR (red) - fast blink on error during transmission error or recieve crc error 
                         * 
                         * The gateway uses AltSoftSerial to handle two serial links 
                         * on one Arduino. Use the following pins for RS485 link
                         * 
                         *  Board          Transmit  Receive   PWM Unusable
                         * -----          --------  -------   ------------
                         * Teensy 3.0 & 3.1  21        20         22
                         * Teensy 2.0         9        10       (none)
                         * Teensy++ 2.0      25         4       26, 27
                         * Arduino Uno        9         8         10
                         * Arduino Leonardo   5        13       (none)
                         * Arduino Mega      46        48       44, 45
                         * Wiring-S           5         6          4
                         * Sanguino          13        14         12
                         * 
                         */
                        
                        // 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 2
                        
                        // Set RS485 baud rate to use
                        #define MY_RS485_BAUD_RATE 9600
                        
                        // Enable serial gateway
                        #define MY_GATEWAY_SERIAL
                        
                        // Flash leds on rx/tx/err
                        #define MY_LEDS_BLINKING_FEATURE
                        // Set blinking period
                        #define MY_DEFAULT_LED_BLINK_PERIOD 300
                        
                        // 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 
                        
                        #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 <SPI.h>
                        #include <MySensors.h>  
                        
                        void setup() { 
                          // Setup locally attached sensors
                        }
                        
                        void presentation() {
                         // Present locally attached sensors 
                        }
                        
                        void loop() { 
                          // Send locally attached sensor data here 
                        }
                        

                        For the sensor (Nano):

                        /**
                         * The MySensors Arduino library handles the wireless radio link and protocol
                         * between your home built sensors/actuators and HA controller of choice.
                         * The sensors forms a self healing radio network with optional repeaters. Each
                         * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                         * network topology allowing messages to be routed to nodes.
                         *
                         * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                         * Copyright (C) 2013-2015 Sensnology AB
                         * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                         *
                         * Documentation: http://www.mysensors.org
                         * Support Forum: http://forum.mysensors.org
                         *
                         * This program is free software; you can redistribute it and/or
                         * modify it under the terms of the GNU General Public License
                         * version 2 as published by the Free Software Foundation.
                         *
                         *******************************
                         *
                         * REVISION HISTORY
                         * Version 1.0 - Henrik Ekblad
                         * 
                         * DESCRIPTION
                         * This is an example of sensors using RS485 as transport layer
                         * 
                         * Motion Sensor example using HC-SR501 
                         * http://www.mysensors.org/build/motion
                         * 
                         * The transport uses AltSoftSerial to handle two serial links 
                         * on one Arduino. Use the following pins for RS485 link
                         * 
                         *  Board          Transmit  Receive   PWM Unusable
                         * -----          --------  -------   ------------
                         * Teensy 3.0 & 3.1  21        20         22
                         * Teensy 2.0         9        10       (none)
                         * Teensy++ 2.0      25         4       26, 27
                         * Arduino Uno        9         8         10
                         * Arduino Leonardo   5        13       (none)
                         * Arduino Mega      46        48       44, 45
                         * Wiring-S           5         6          4
                         * Sanguino          13        14         12 * 
                         * 
                         */
                        
                        
                        // 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_RS485_BAUD_RATE 9600
                        
                        #include <SPI.h>
                        #include <MySensors.h>
                        
                        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
                          boolean 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);
                        }
                        
                        
                        skatunS 1 Reply Last reply
                        0
                        • wimdW wimd

                          @dbemowsk It are the standard examples.

                          For the gateway (Uno) :

                          * The MySensors Arduino library handles the wireless radio link and protocol
                           * between your home built sensors/actuators and HA controller of choice.
                           * The sensors forms a self healing radio network with optional repeaters. Each
                           * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                           * network topology allowing messages to be routed to nodes.
                           *
                           * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                           * Copyright (C) 2013-2015 Sensnology AB
                           * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                           *
                           * Documentation: http://www.mysensors.org
                           * Support Forum: http://forum.mysensors.org
                           *
                           * This program is free software; you can redistribute it and/or
                           * modify it under the terms of the GNU General Public License
                           * version 2 as published by the Free Software Foundation.
                           *
                           *******************************
                           *
                           * DESCRIPTION
                           * The RS485 Gateway prints data received from sensors on the serial link. 
                           * The gateway accepts input on seral which will be sent out on
                           * the RS485 link.
                           *
                           * Wire connections (OPTIONAL):
                           * - Inclusion button should be connected between digital pin 3 and GND  
                           * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
                           *
                           * LEDs (OPTIONAL):
                           * - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
                           * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
                           * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
                           * - ERR (red) - fast blink on error during transmission error or recieve crc error 
                           * 
                           * The gateway uses AltSoftSerial to handle two serial links 
                           * on one Arduino. Use the following pins for RS485 link
                           * 
                           *  Board          Transmit  Receive   PWM Unusable
                           * -----          --------  -------   ------------
                           * Teensy 3.0 & 3.1  21        20         22
                           * Teensy 2.0         9        10       (none)
                           * Teensy++ 2.0      25         4       26, 27
                           * Arduino Uno        9         8         10
                           * Arduino Leonardo   5        13       (none)
                           * Arduino Mega      46        48       44, 45
                           * Wiring-S           5         6          4
                           * Sanguino          13        14         12
                           * 
                           */
                          
                          // 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 2
                          
                          // Set RS485 baud rate to use
                          #define MY_RS485_BAUD_RATE 9600
                          
                          // Enable serial gateway
                          #define MY_GATEWAY_SERIAL
                          
                          // Flash leds on rx/tx/err
                          #define MY_LEDS_BLINKING_FEATURE
                          // Set blinking period
                          #define MY_DEFAULT_LED_BLINK_PERIOD 300
                          
                          // 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 
                          
                          #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 <SPI.h>
                          #include <MySensors.h>  
                          
                          void setup() { 
                            // Setup locally attached sensors
                          }
                          
                          void presentation() {
                           // Present locally attached sensors 
                          }
                          
                          void loop() { 
                            // Send locally attached sensor data here 
                          }
                          

                          For the sensor (Nano):

                          /**
                           * The MySensors Arduino library handles the wireless radio link and protocol
                           * between your home built sensors/actuators and HA controller of choice.
                           * The sensors forms a self healing radio network with optional repeaters. Each
                           * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                           * network topology allowing messages to be routed to nodes.
                           *
                           * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                           * Copyright (C) 2013-2015 Sensnology AB
                           * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                           *
                           * Documentation: http://www.mysensors.org
                           * Support Forum: http://forum.mysensors.org
                           *
                           * This program is free software; you can redistribute it and/or
                           * modify it under the terms of the GNU General Public License
                           * version 2 as published by the Free Software Foundation.
                           *
                           *******************************
                           *
                           * REVISION HISTORY
                           * Version 1.0 - Henrik Ekblad
                           * 
                           * DESCRIPTION
                           * This is an example of sensors using RS485 as transport layer
                           * 
                           * Motion Sensor example using HC-SR501 
                           * http://www.mysensors.org/build/motion
                           * 
                           * The transport uses AltSoftSerial to handle two serial links 
                           * on one Arduino. Use the following pins for RS485 link
                           * 
                           *  Board          Transmit  Receive   PWM Unusable
                           * -----          --------  -------   ------------
                           * Teensy 3.0 & 3.1  21        20         22
                           * Teensy 2.0         9        10       (none)
                           * Teensy++ 2.0      25         4       26, 27
                           * Arduino Uno        9         8         10
                           * Arduino Leonardo   5        13       (none)
                           * Arduino Mega      46        48       44, 45
                           * Wiring-S           5         6          4
                           * Sanguino          13        14         12 * 
                           * 
                           */
                          
                          
                          // 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_RS485_BAUD_RATE 9600
                          
                          #include <SPI.h>
                          #include <MySensors.h>
                          
                          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
                            boolean 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);
                          }
                          
                          
                          skatunS Offline
                          skatunS Offline
                          skatun
                          wrote on last edited by
                          #20

                          @wimd include debug and remove inclusion from the sketches and it should be ok. I have ordered new rs485 shield, i expect that to be the issue..

                          wimdW R 2 Replies Last reply
                          0
                          • consul58C consul58

                            @skatun
                            Hi,
                            I found the solution.

                            Look at this

                            Place the following in your Node-Sketch e.g. for Node ID 23

                             #define MY_NODE_ID 23
                            

                            and the communication between node and Gateway is ok.

                            I hope this works for you.

                            bocmauB Offline
                            bocmauB Offline
                            bocmau
                            wrote on last edited by
                            #21

                            @consul58 said:

                            #define MY_NODE_ID 23

                            Thanks for the tip now works

                            1 Reply Last reply
                            0
                            • skatunS skatun

                              @wimd include debug and remove inclusion from the sketches and it should be ok. I have ordered new rs485 shield, i expect that to be the issue..

                              wimdW Offline
                              wimdW Offline
                              wimd
                              wrote on last edited by
                              #22

                              @skatun include debug, removal of inclusion and define MY_NODE_ID enabled communication on the RS485 bus.

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                Reza
                                wrote on last edited by
                                #23
                                This post is deleted!
                                1 Reply Last reply
                                0
                                • skatunS skatun

                                  @wimd include debug and remove inclusion from the sketches and it should be ok. I have ordered new rs485 shield, i expect that to be the issue..

                                  R Offline
                                  R Offline
                                  Reza
                                  wrote on last edited by Reza
                                  #24

                                  @skatun my problem is solve . you test this and feedback me. use 3.3v and gnd pins in arduino use for rs485 module.

                                  b0rmannB 1 Reply Last reply
                                  0
                                  • R Offline
                                    R Offline
                                    Reza
                                    wrote on last edited by Reza
                                    #25

                                    is this wiring true for rs485 ? thank you
                                    0_1485716457105_123.jpg

                                    also which cable is appropriate for A and B?

                                    1 Reply Last reply
                                    0
                                    • R Reza

                                      @skatun my problem is solve . you test this and feedback me. use 3.3v and gnd pins in arduino use for rs485 module.

                                      b0rmannB Offline
                                      b0rmannB Offline
                                      b0rmann
                                      wrote on last edited by
                                      #26

                                      @Reza

                                      no. rs485 must have LINEAR BUS topology.

                                      R 2 Replies Last reply
                                      1
                                      • b0rmannB b0rmann

                                        @Reza

                                        no. rs485 must have LINEAR BUS topology.

                                        R Offline
                                        R Offline
                                        Reza
                                        wrote on last edited by
                                        #27

                                        @b0rmann my pic is not a bus ? i think this is a bus topology !

                                        1 Reply Last reply
                                        0
                                        • b0rmannB b0rmann

                                          @Reza

                                          no. rs485 must have LINEAR BUS topology.

                                          R Offline
                                          R Offline
                                          Reza
                                          wrote on last edited by Reza
                                          #28

                                          @b0rmann
                                          this is a bus ?
                                          0_1485723151109_RS485-Schnittstelle-11.png

                                          so in end of A and B , what am i do ?

                                          dbemowskD wimdW 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          18

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular