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. Development
  3. RS485/RS232/Serial transport class for mysensors.org

RS485/RS232/Serial transport class for mysensors.org

Scheduled Pinned Locked Moved Development
rs485 serialrs485
143 Posts 27 Posters 102.9k Views 27 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.
  • T Offline
    T Offline
    TimO
    Hero Member
    wrote on last edited by
    #4

    Woah, nice!! I've thought about doing the same but didn't find the time.
    I will try to test, the RS485 are already lying on my desk.

    1 Reply Last reply
    0
    • TheoLT Offline
      TheoLT Offline
      TheoL
      Contest Winner
      wrote on last edited by
      #5

      I have to wait before my Guests will leave, but this is something I'm interested in. Will check it in a week or two. I want to have a sensor that checks whenever I lay in my bed. I'd preffer to transfer this kind of details wired and not wireless ;)

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

        Testing this will be next thing in my todo-list. Just ordered needed parts :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shabba
          wrote on last edited by
          #7

          I just started a thread on using sensors without a radio. So this really caught my attention. Would it be possible to modify it to use the USB Serial interface for arduinos that have it?

          L 1 Reply Last reply
          0
          • S shabba

            I just started a thread on using sensors without a radio. So this really caught my attention. Would it be possible to modify it to use the USB Serial interface for arduinos that have it?

            L Offline
            L Offline
            LeoDesigner
            wrote on last edited by LeoDesigner
            #8

            @shabba I am not quite understood what exactly you want to do with USB. You can use arduino nano without any problems at all.
            All you have to do just to make sure to disconnect your RS485 bus from RX pin during the time when you will upload your sketch/firmware.
            Also it is possible to use this class without any converters at all. See attached simple schematics on github page.
            Regarding USB - you can attach an RS485-USB adapter to this bus as well too.
            So it is an universal solution for a serial communication between many arduinos via serial port. Please note about possibility to connect this bus to RPi directly. ICSC lib include the library for RPi too.
            Also, it's better to disable DEBUG option in mysensors config file to avoid additional traffic on the serial bus.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              shabba
              wrote on last edited by
              #9

              @LeoDesigner Sorry for not being clear. I was looking to connect my Arduino Mega (has about a dozen sensors and relays connected to it) to my existing RPi2 sensors serial gateway (using a UNO). I was hoping I could use a second USB/Serial port on the RPi2 to receive messages from the Mega.

              L 1 Reply Last reply
              0
              • S shabba

                @LeoDesigner Sorry for not being clear. I was looking to connect my Arduino Mega (has about a dozen sensors and relays connected to it) to my existing RPi2 sensors serial gateway (using a UNO). I was hoping I could use a second USB/Serial port on the RPi2 to receive messages from the Mega.

                L Offline
                L Offline
                LeoDesigner
                wrote on last edited by
                #10

                @shabba Take a look to https://github.com/MajenkoLibraries/ICSC/tree/master/debian
                It may be a starting point for you. You can adopt this part of the ICSC library to your RPi2 setup.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  LeoDesigner
                  wrote on last edited by LeoDesigner
                  #11

                  Finally I am received my RS485 modules.
                  Here is the working example of gateway with two nodes:

                  https://youtu.be/4Ls95PKLwng

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

                    @LeoDesigner

                    To test this I ordered a few of these..
                    http://www.ebay.com/itm/381374599127?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

                    Hope they are the correct model.

                    L 1 Reply Last reply
                    0
                    • hekH hek

                      @LeoDesigner

                      To test this I ordered a few of these..
                      http://www.ebay.com/itm/381374599127?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

                      Hope they are the correct model.

                      L Offline
                      L Offline
                      LeoDesigner
                      wrote on last edited by LeoDesigner
                      #13

                      @hek
                      My modules are from http://www.aliexpress.com/item/FREE-SHIPPING-5PCS-LOT-MAX485-module-RS485-module-TTL-turn-RS-485-module-MCU-development-accessories/1718665649.html
                      They are the same as yours - based on MAX485.
                      However, it is possible to run a simple TTL signal level bus on a short distances.
                      (https://github.com/leodesigner/mysensors-serial-transport/blob/master/sch.png)

                      hekH 1 Reply Last reply
                      0
                      • L LeoDesigner

                        @hek
                        My modules are from http://www.aliexpress.com/item/FREE-SHIPPING-5PCS-LOT-MAX485-module-RS485-module-TTL-turn-RS-485-module-MCU-development-accessories/1718665649.html
                        They are the same as yours - based on MAX485.
                        However, it is possible to run a simple TTL signal level bus on a short distances.
                        (https://github.com/leodesigner/mysensors-serial-transport/blob/master/sch.png)

                        hekH Offline
                        hekH Offline
                        hek
                        Admin
                        wrote on last edited by
                        #14

                        @LeoDesigner

                        I've incorporated a slimmed down of the RS485 transport layer in this branch (soon to be merged into development):

                        https://github.com/mysensors/Arduino/tree/serial-transport/libraries/MySensors

                        But I've still haven't received my RS485 modules... Do you have time to run a small test?

                        Gateway:
                        https://github.com/mysensors/Arduino/tree/serial-transport/libraries/MySensors/examples/GatewaySerialRS485

                        And a test-motion sensor sketch:
                        https://github.com/mysensors/Arduino/tree/serial-transport/libraries/MySensors/examples/MotionSensorRS485

                        But you could use any example just replacing #define MY_RADIO_RF24 with #define MY_RS485

                        I've used the AltSerial library for RS485 communication so we can cope with dual serial ports on the serial gateway. This library requires using pins documented in sketch.

                        L 1 Reply Last reply
                        0
                        • hekH hek

                          @LeoDesigner

                          I've incorporated a slimmed down of the RS485 transport layer in this branch (soon to be merged into development):

                          https://github.com/mysensors/Arduino/tree/serial-transport/libraries/MySensors

                          But I've still haven't received my RS485 modules... Do you have time to run a small test?

                          Gateway:
                          https://github.com/mysensors/Arduino/tree/serial-transport/libraries/MySensors/examples/GatewaySerialRS485

                          And a test-motion sensor sketch:
                          https://github.com/mysensors/Arduino/tree/serial-transport/libraries/MySensors/examples/MotionSensorRS485

                          But you could use any example just replacing #define MY_RADIO_RF24 with #define MY_RS485

                          I've used the AltSerial library for RS485 communication so we can cope with dual serial ports on the serial gateway. This library requires using pins documented in sketch.

                          L Offline
                          L Offline
                          LeoDesigner
                          wrote on last edited by
                          #15

                          @hek
                          My example boxes are installed right now on the site and doing a daily job :)
                          It will take time to build a new one. I may try a breadboard, but I am still busy to finish additional improvements to mysensors.org project. (I will share them later - it's will be interesting too - I hope :) )

                          Actually, it's easy to test RS485 transport without a RS485 converters - just use a simple schematics I have been talking before.
                          Also, you may want to look to this: https://github.com/MajenkoLibraries/ICSC/pulls
                          It's untested support for SoftwareSerial option for library.
                          With AltSerial we will be forced to use only a documented pins.

                          Anyway - I am glad to contribute a bit to great mysensors community.

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

                            Thanks,

                            @LeoDesigner said:

                            With AltSerial we will be forced to use only a documented pins.

                            Yes, I know. But AltSerial can handle higher speeds. I preferred that over the SoftwareSerial flexibility regarding pin selection. Hope I did the right choice ;)

                            L 1 Reply Last reply
                            0
                            • hekH hek

                              Thanks,

                              @LeoDesigner said:

                              With AltSerial we will be forced to use only a documented pins.

                              Yes, I know. But AltSerial can handle higher speeds. I preferred that over the SoftwareSerial flexibility regarding pin selection. Hope I did the right choice ;)

                              L Offline
                              L Offline
                              LeoDesigner
                              wrote on last edited by
                              #17

                              @hek
                              Speed is one of the reasons why I have decided to use hardware serial. :)
                              But we should be flexible and universal as much as we can. I had been thinking also to add support for over the wire firmware update. As you have done with wireless.

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

                                With a new bootloader? Using external flash+DualOptiBoot it should work already.

                                L 1 Reply Last reply
                                0
                                • hekH hek

                                  With a new bootloader? Using external flash+DualOptiBoot it should work already.

                                  L Offline
                                  L Offline
                                  LeoDesigner
                                  wrote on last edited by
                                  #19

                                  @hek
                                  Sure - but it can be possible done with standard bootloader - we just have to emulate standard Arduino sketch upload process on the gateway side. But I am not sure if it's possible to do with half duplex protocol. Just an idea.

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

                                    Interesting idea. Looking forward hearing about your results.

                                    1 Reply Last reply
                                    0
                                    • tbowmoT Offline
                                      tbowmoT Offline
                                      tbowmo
                                      Admin
                                      wrote on last edited by
                                      #21

                                      @LeoDesigner

                                      If using the standard bootloader, wouldn't it break the FW update if one of the other nodes on the bus starts to transmit?

                                      L 1 Reply Last reply
                                      0
                                      • tbowmoT tbowmo

                                        @LeoDesigner

                                        If using the standard bootloader, wouldn't it break the FW update if one of the other nodes on the bus starts to transmit?

                                        L Offline
                                        L Offline
                                        LeoDesigner
                                        wrote on last edited by
                                        #22

                                        @tbowmo
                                        Node will listen RS485 bus before it will try to transmit anything (just like Ethernet).
                                        So other nodes will behave yourself :)
                                        But we have another difficulty: standard bootloader know nothing about TX/RX (dePin) management. So, we need to modify it to be able correctly emulate Arduino upload process. Maybe a simple schematics with diode will work in that case.
                                        I am still busy with other improvements.

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          TimO
                                          Hero Member
                                          wrote on last edited by
                                          #23

                                          @hek I've tested your code and can't get it working yet.

                                          I've installed the gateway and a DHT22 sketch on two nanos and connected them directly via D8 and D9.

                                          // Enable RS485 transport layer
                                          #define MY_RS485
                                          
                                          // Set RS485 baud rate to use
                                          #define MY_RS485_BAUD_RATE 9600
                                          
                                          
                                          #include <MySensor.h>
                                          #include <DHT.h>  
                                          
                                          #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
                                          #define CHILD_ID_HUM 0
                                          #define CHILD_ID_TEMP 1
                                          #define HUMIDITY_SENSOR_DIGITAL_PIN 3
                                          #define RS485_DE_PIN 4
                                          unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
                                          
                                          // Initialize motion message
                                          DHT dht;
                                          boolean metric = true; 
                                          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                                          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                                          
                                          void setup()  
                                          {  
                                            dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
                                          }
                                          
                                          void presentation()  {
                                            // Send the sketch version information to the gateway and Controller
                                            sendSketchInfo("Humidity Sensor", "1.0");
                                          
                                            // Register all sensors to gw (they will be created as child devices)
                                            present(CHILD_ID_HUM, S_HUM);
                                            present(CHILD_ID_TEMP, S_TEMP);
                                          }
                                          
                                          void loop()     
                                          {     
                                            float temperature = dht.getTemperature();
                                            if (isnan(temperature)) {
                                                Serial.println("Failed reading temperature from DHT");
                                            } else  {
                                              send(msgTemp.set(temperature, 1));
                                              Serial.print("T: ");
                                              Serial.println(temperature);
                                            }
                                            
                                            float humidity = dht.getHumidity();
                                            if (isnan(humidity)) {
                                                Serial.println("Failed reading humidity from DHT");
                                            } else {
                                                send(msgHum.set(humidity, 1));
                                                Serial.print("H: ");
                                                Serial.println(humidity);
                                            }
                                            // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
                                            sleep(SLEEP_TIME);
                                          }
                                          

                                          The sketch is working fine according to serial output. But nothing is seen on the gateway.

                                          So, to find out, where there is a problem, I connected my Programmer (mySmartUSB MK3) to D8/D9 of the sensor and I'm able to see that there is output but the chars are not readable so I tried different baudrates than 9600. That didn' help. What I can say is, that the output is generated every 3 seconds, so the ports are right.

                                          To make sure I'm not doing something wrong with the programmer, I connected it to D0/D1 and switched baudrate to 115200 and it shows the serial output as expected.

                                          Any idea where to look next?

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          11

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 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