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. My Project
  3. CAN bus transport implementation for MYS

CAN bus transport implementation for MYS

Scheduled Pinned Locked Moved My Project
35 Posts 12 Posters 13.0k Views 16 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.
  • H Offline
    H Offline
    hausinger
    wrote on last edited by
    #3

    And this is, what I'm wrote there:

    I'm very interested in your development.
    What kind of can bus module are you using? I found 2 different modules for very less money. The very small module is called SN65HVD230 (controlled by serial rx, tx) and cost approximately 1,75$ from China. The other module with bigger size is called MCP2515 (controlled by spi) and cost approximately 1,26 $ from China. Both are very cheap.
    What is you currently status in this case?
    I'm planning to use it for my new house in some month.

    Thank you

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kimot
      wrote on last edited by
      #4

      @hausinger

      SN65HVD230 is only CAN bus driver. It has no inteligence, so you need MCP2515 or microcontroller with CAN periphery.
      By the way I think, that using CAN drivers is better for RS485 connection in MYSensors then RS485 drivers.
      For 3 reasons for me:

      1. You do not need a pin for direction control - you can use a common serial library. For galvanic isolation, it is enough just to separate the two signals.
      2. The status of the bus is always precisely defined. What reads the sending node is exactly what read all the other nodes on the bus. It is not true when using RS485 drivers in multimaster bus.
      3. CAN bus drivers are constructed such, that when the processor transmits a dominant state for too long time, the driver disconnects the processor from the bus and connectes it after another change of the pin TX. So node with defective or hanged program can not block the entire bus.
      1 Reply Last reply
      0
      • K Offline
        K Offline
        kimot
        wrote on last edited by
        #5

        @hausinger
        For now, most important for me is connect 14 thermostats for electrical floor heating through serial gateway to some controller. It is bus with stable number of nodes (14 ) with the same design. Nothing time critical. No many changes in the future. For this bus I will use some "light" variant MODBUS protocol. Only read and write registers. Gateway will act like master and will translate modbus messages to the serial port for controller.
        Each thermostat has its own intelligence and bus is used for data collectio nonly. Setting the desired temperature and control and report critical conditions etc.
        And CAN bus drivers only.
        That is I am working now on.
        Simultaneously, I work on the transmission of CAN messages, but the problem got to the main solution later.
        ( I have 2 other buses. One for PIR and smoke detectors in each room and second is universal bus through entire home and outside too.
        It is mostly in separate wall sockets ( RJ11 6p6c ). On both I will use CAN bus with CAN controllers)

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hausinger
          wrote on last edited by
          #6

          @kimot
          thank you for your answers in this case.

          You think, the SN65HVD230 is better than the max485? Can I use the SN65HVD230 with mysensors and Transport class rs485 without changes in the code? If yes, how do I do with the "DE-Pin" ?

          I don't know, why you are using 3 Bus Systems at your home? Why not 1 Stable Bus?

          I want a stable bus for several things in my new home. PIR, Standard button Switch, Contacts (Window, Smoke), Dimmers, RGB Dimmers, Temperaturesensors, Relays should be my nodes. The Problem in this case is, that I want to use my nodes even when the bus have Errors.
          So if you seperate the communication from sensors to Gateway (with your self made library, as you wrote here) and the Gateway communication with the Controller with the mysensors libs, that would be excactly what I'm locking for.

          My idea besides of that is, that nodes can work without the bus. For examble the push button Switch can Switch the light, even when the bus is down. With mysensors this is not possible, because nodes have to register to the Gateway. Mysensors should be a "add on" for the nodes in my home, to control all on one place - openhab.

          I also want to have a stable bus, because it would be very bad, when i press a push button and nothing happens (=is dark in the room), because the bus is busy. Sure it doesn't matter if a temp sensor can't transmit it's value to the Controller. But for Switch / PIR it is very important.

          N 1 Reply Last reply
          0
          • N Offline
            N Offline
            napo7
            Hardware Contributor
            wrote on last edited by napo7
            #7

            I agree with @kimot : the RS485 bus is not designed to have many masters on the same bus.
            So, when you want to use RS485, you have 2 choices :

            • The master polls the slaves to ask them if they have something to say (you give them the "right" to talk)
            • Each device tries to talk when needed, with the risk of collision, and the message could not be correctly transmitted.

            Using a MCP2551 driver (without a MCP2515 controller) allows to use the benefits of CAN bus : If 2 masters talk at the same time, one of them will "see" that one of the bit he tried to push on the bus has been overwritten by another one, and will have to try again a few times later. This is not collision avoidance, but collision detection.
            Of course, since we use only a CAN driver and not a controller, we must do the checks via software (listen to what is being heard as we're talking).

            I have some arduinos laying around, and some MCP2551. I must do some tests.

            1 Reply Last reply
            0
            • scalzS Offline
              scalzS Offline
              scalz
              Hardware Contributor
              wrote on last edited by scalz
              #8

              in case, this is also an interesting note about CAN, for 3.3v transceivers, http://www.ti.com/lit/an/slla337/slla337.pdf
              esp32 has a CAN controller, so it will just need the transceiver i think (I'm waiting their lib release). geek sidenote :)

              Keep the good work, I also think CAN bus is very reliable compared to halfduplex rs485.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                napo7
                Hardware Contributor
                wrote on last edited by
                #9

                Yes, this device is interresting.

                None the less, we're thinking of using only a CAN driver without controller, in a kind of RS485 bus...
                This way, we make an hybride bus : simplicity of RS485, with multi-master possibilities of CAN thanks to the way his driver works !
                So, having a CAN controller on ESP32 is ( from my point of view) not-so-much usefull.

                1 Reply Last reply
                0
                • H hausinger

                  @kimot
                  thank you for your answers in this case.

                  You think, the SN65HVD230 is better than the max485? Can I use the SN65HVD230 with mysensors and Transport class rs485 without changes in the code? If yes, how do I do with the "DE-Pin" ?

                  I don't know, why you are using 3 Bus Systems at your home? Why not 1 Stable Bus?

                  I want a stable bus for several things in my new home. PIR, Standard button Switch, Contacts (Window, Smoke), Dimmers, RGB Dimmers, Temperaturesensors, Relays should be my nodes. The Problem in this case is, that I want to use my nodes even when the bus have Errors.
                  So if you seperate the communication from sensors to Gateway (with your self made library, as you wrote here) and the Gateway communication with the Controller with the mysensors libs, that would be excactly what I'm locking for.

                  My idea besides of that is, that nodes can work without the bus. For examble the push button Switch can Switch the light, even when the bus is down. With mysensors this is not possible, because nodes have to register to the Gateway. Mysensors should be a "add on" for the nodes in my home, to control all on one place - openhab.

                  I also want to have a stable bus, because it would be very bad, when i press a push button and nothing happens (=is dark in the room), because the bus is busy. Sure it doesn't matter if a temp sensor can't transmit it's value to the Controller. But for Switch / PIR it is very important.

                  N Offline
                  N Offline
                  napo7
                  Hardware Contributor
                  wrote on last edited by
                  #10

                  @hausinger said:

                  My idea besides of that is, that nodes can work without the bus. For examble the push button Switch can Switch the light, even when the bus is down. With mysensors this is not possible, because nodes have to register to the Gateway. Mysensors should be a "add on" for the nodes in my home, to control all on one place - openhab.

                  The only way to handle this kind of problem, is to make device with INPUT and OUTPUT at the same time !
                  You would then have to think of an intelligent way of handling what happens when the INPUT see events :
                  Do you have to transmit it to the gateway, wait for a reply, and then fall back to a "fail" mode if the gateway doesn't reply after a delay ?
                  Do you prefer handling the event simply by turning ON/OFF the output, and just inform the gateway of what happening ? this way, even if the bus is down, your device will continue to work... but you're loosing the benefits of having an intelligent controller/gateway that can make decisions...

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

                    @kimot Would it be hard to write CANbus version of the transport class based on rs485 implementation? Is there some extra things you need to handle on top of "basic serial communication"?

                    N 1 Reply Last reply
                    0
                    • N napo7

                      @hausinger said:

                      My idea besides of that is, that nodes can work without the bus. For examble the push button Switch can Switch the light, even when the bus is down. With mysensors this is not possible, because nodes have to register to the Gateway. Mysensors should be a "add on" for the nodes in my home, to control all on one place - openhab.

                      The only way to handle this kind of problem, is to make device with INPUT and OUTPUT at the same time !
                      You would then have to think of an intelligent way of handling what happens when the INPUT see events :
                      Do you have to transmit it to the gateway, wait for a reply, and then fall back to a "fail" mode if the gateway doesn't reply after a delay ?
                      Do you prefer handling the event simply by turning ON/OFF the output, and just inform the gateway of what happening ? this way, even if the bus is down, your device will continue to work... but you're loosing the benefits of having an intelligent controller/gateway that can make decisions...

                      H Offline
                      H Offline
                      hausinger
                      wrote on last edited by
                      #12

                      @napo7

                      @napo7 said:

                      @hausinger said:

                      My idea besides of that is, that nodes can work without the bus. For examble the push button Switch can Switch the light, even when the bus is down. With mysensors this is not possible, because nodes have to register to the Gateway. Mysensors should be a "add on" for the nodes in my home, to control all on one place - openhab.

                      The only way to handle this kind of problem, is to make device with INPUT and OUTPUT at the same time !
                      You would then have to think of an intelligent way of handling what happens when the INPUT see events :
                      Do you have to transmit it to the gateway, wait for a reply, and then fall back to a "fail" mode if the gateway doesn't reply after a delay ?
                      Do you prefer handling the event simply by turning ON/OFF the output, and just inform the gateway of what happening ? this way, even if the bus is down, your device will continue to work... but you're loosing the benefits of having an intelligent controller/gateway that can make decisions...

                      Hi @napo7
                      Yes, i would prefer handling it direct on the nodes. Not only ON/OFF, also dimmer (1 short press on the push button - Light on (last value) + turn on power supply of the lamps (Relais=1), 1 short press on the push button - light off + turn power supply off of the lamps (Relais=0), 1 Long press on the bush putton - dimming). The Gateway (and Controller) should be able to do the same Thing, if the bus is ok. But if it fials, i could use it localy and so i'm not in a dark room.

                      1 Reply Last reply
                      0
                      • P pjr

                        @kimot Would it be hard to write CANbus version of the transport class based on rs485 implementation? Is there some extra things you need to handle on top of "basic serial communication"?

                        N Offline
                        N Offline
                        napo7
                        Hardware Contributor
                        wrote on last edited by
                        #13

                        @pjr
                        Hi,

                        If we want to use CAN drivers instead of RS485 drivers, we don't have to add anything to the code.
                        We will benefit of CAN drivers capabilities, but we still have to write some code to handle collisions.

                        If we want to use a CAN CONTROLLER, yes, there is more to do :we must setup the CAN controller each time the board start-up : this is needed to tell the CAN controller on which kind of message we must listen to, what is our ID (CAN controller do all the filtering job...), etc...

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

                          @napo7 and if we use CAN CONTROLLER it does all the needed collision avoiding, detection and "resending" and it dont need to be written in the transport class? Only the initalization of the CAN CONTROLLER needs to be added?

                          Is there much difference in communication reliability if we use CAN DRIVER vs. RS485 DRIVER currently without modifying the rs485 transport class?

                          1 Reply Last reply
                          0
                          • N Offline
                            N Offline
                            napo7
                            Hardware Contributor
                            wrote on last edited by
                            #15

                            Yes, the CAN controller handles all this stuff (collision detection and resending...)
                            So, yes, only CAN initialization has to be added.

                            In facts, NO, without adding code, there will be no difference between between the two drivers. I haven't looked at the class, but if we use a CAN driver, the goal is to use its advantages to "allow" collisions and handle them better.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              gonzalonal
                              wrote on last edited by
                              #16

                              Hi everyone. Have there been any developments regarding CAN Bus Controller integration to MySensors Library?
                              Thanks.

                              K 1 Reply Last reply
                              0
                              • G gonzalonal

                                Hi everyone. Have there been any developments regarding CAN Bus Controller integration to MySensors Library?
                                Thanks.

                                K Offline
                                K Offline
                                kimot
                                wrote on last edited by kimot
                                #17

                                @gonzalonal
                                Yes I am.
                                But I have got a lot of other works, so It's going slowly.
                                The problem is, that CAN can transfer only 29 bits ID ( 3 bytes + 5 bits ) and max. 8 bytes of data.
                                MySensors message has got max. 32 bytes ( 7 bytes header and 25 bytes of data ).
                                I must either send MySensors message like 3 packets of CAN messages or limit properties of MySensors protocol.
                                Now I am working on second variant.
                                I am able code to one CAN message:
                                6 bits - destination
                                6 bis - sender
                                (gateway, broadcast, 62 nodes - it is enough for me for one bus. I plane three buses and gateway can " translate " or "expand" nodes ID from and to controller )
                                1 bit - RACK
                                1 bit - IS ACK
                                3 bits - command
                                6 bits - type ( MY sensors has 56 types max. now )
                                6 bits - sensor id ( only 64 sensors per node ... )
                                3 bits - payload type ( int, uint, long .... )

                                The sum of these is not 29, but 32 so I am using a little "hacking" data length field in CAN frame to obtain additional 3 bits.
                                For data I have got 8 bytes.
                                It is enough for conventional data types from char to floating point.
                                Only text messages are limited to 8 bytes. But for us, old boys, who remember old DOS file names, it is enough.

                                In this time, I am able send and receive packets in that format between nodes and now I am working on transfer RS485 library to CAN library.
                                The problem is, that RS485 library sends destination address, node id, length of message and then MySensors message, witch "surprisingly" contain again destination and sender bytes. A little bit redundant for me.
                                So I must remove some fields from MySensors message, put it to CAN ID and send only payload in CAN data fields.
                                When I receive CAN message, I must again assemble correct MySensors message format and put it to MySensors system.
                                But unfortunately only documentation is library code itself :o(

                                I try a "stress test" like here:
                                https://forum.mysensors.org/topic/5051/rs485-stress-test

                                I send 10 000 messages from two nodes to "gateway" ( 22kbps ).
                                Result - zero messages lost.
                                But it is expectable with CAN.

                                1 Reply Last reply
                                4
                                • P Offline
                                  P Offline
                                  pjr
                                  wrote on last edited by
                                  #18

                                  @kimot what hw you are using? MCP2515 + MCP2551?

                                  K 1 Reply Last reply
                                  0
                                  • P pjr

                                    @kimot what hw you are using? MCP2515 + MCP2551?

                                    K Offline
                                    K Offline
                                    kimot
                                    wrote on last edited by
                                    #19

                                    @pjr
                                    This module.
                                    http://www.ebay.com/itm/Arduino-MCP2515-CAN-Bus-Module-TJA1050-Receiver-SPI-Module-/311520457612?hash=item488810f38c:g:g8MAAOSwu4BVzbWC

                                    1 Reply Last reply
                                    0
                                    • ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on last edited by
                                      #20

                                      Hello,

                                      I'm really interested in the solution you are working on (can bus with mysensors). I would like as much as possible to avoid a wireless network but I still would like to use the "mysensors" libraries and protocol. As this project as a lot of users it's a warranty of longevity.

                                      @kimot : your trials seems great, did you have the change of getting further?

                                      K 1 Reply Last reply
                                      0
                                      • ? A Former User

                                        Hello,

                                        I'm really interested in the solution you are working on (can bus with mysensors). I would like as much as possible to avoid a wireless network but I still would like to use the "mysensors" libraries and protocol. As this project as a lot of users it's a warranty of longevity.

                                        @kimot : your trials seems great, did you have the change of getting further?

                                        K Offline
                                        K Offline
                                        kimot
                                        wrote on last edited by
                                        #21

                                        @gasuter
                                        I think I am able sending data from node to gateway (GW) and through it to controller.
                                        There is limited data space in CAN message, so I must avoid sending long strings and send all as possible like integers, longs, floats etc. It is not problem when sending from node to GW, because in the message header is field, which describes type of payload and according GW code, I assume, it can translate it to strings for controller correctly.
                                        But problem is, when GW receives data from controller. Payload is always string and I must convert it to int, long, float and sometimes short string for sending it through CAN bus to the node. But from serial protocol GW can not recognize, what type of this payload is. I think I need to built some translation table for each serial protocol TYPE to variable type.
                                        But maybe each controller sends different type of data for the same sensor value (0, 1 x "on", "off" ).
                                        Or better something "smart" like "when there is a dot and not letter in string, it is float", "if there are only numbers, it is int or long" ....

                                        1 Reply Last reply
                                        0
                                        • wallyllamaW Offline
                                          wallyllamaW Offline
                                          wallyllama
                                          wrote on last edited by
                                          #22

                                          Sorry to hijack a bit, but j1708 looks like it can do bit level collision detection with a max485, it means controlling the DE line. More work than CANBus?

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


                                          30

                                          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