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.
  • 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
                  • wallyllamaW wallyllama

                    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 Offline
                    K Offline
                    kimot
                    wrote on last edited by kimot
                    #23

                    @wallyllama
                    I look at j1708 spec. and I think, that this protocol was born long before CAN.
                    It uses MAX485 bus drivers that way, that CAN bus drivers can works at higher speeds and better now.
                    And I must say, I can see better multimaster implementation for RS485 bus than j1708 ( clever addressing, bus arbitration, CRC instead of simple SUM etc. ) And there is AVR libraries so you do not start from scratch. For J1708 I can not find any.

                    1 Reply Last reply
                    0
                    • gohanG Offline
                      gohanG Offline
                      gohan
                      Mod
                      wrote on last edited by
                      #24

                      A friend of mine who works a lot with can bus told me that j1939 supports multi pack when bigger payloads are needed

                      K 1 Reply Last reply
                      0
                      • gohanG gohan

                        A friend of mine who works a lot with can bus told me that j1939 supports multi pack when bigger payloads are needed

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

                        @gohan
                        Thanks for your message.
                        All CAN controllers can send max 8 bytes of data, so longer messages must be divided to multiple packets. J1939 works this way too. That is what I do not want. With heavy traffic especially GW must again assemble packets to complete message, but packet of one message will not come one by one. Packets will be coming mixed from different nodes and GW must assemble them in memory to complete message from each node. So you for example has 30 messages in different state of completion. Some of them has received 1 packet and waiting for 2nd , some has 2nd and waiting for 3rd. ....
                        I am concerned that it does not work for ATmega328, and must be used processor with more RAM.

                        D 1 Reply Last reply
                        0
                        • gohanG Offline
                          gohanG Offline
                          gohan
                          Mod
                          wrote on last edited by
                          #26

                          I understand your concerns, but can bus is made more for industrial purposes. Maybe you need to find a more powerful replacement for the ATmega328

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

                            @kimot Thank you very much for your reply. It's sounds great and more I read about bus for IOT more I think Can is the best solution. But still the problem with the data length bother me. The more hack and tricks we have to add to a system the more problem we can have.

                            I made a little research on internet about Can and found that there is a new version called CAN FD that is actually compatible with CAN 2 but it can be used at a higher speed between to CAN FD nodes (but that is not really interesting us for our use). The real plus is that you can send data up to 64 bytes. And I think that could be the solution of the problem, no?

                            http://www.microchip.com/wwwproducts/en/MCP2561FD

                            K 1 Reply Last reply
                            0
                            • gohanG Offline
                              gohanG Offline
                              gohan
                              Mod
                              wrote on last edited by
                              #28

                              Agricultural vehicles now use ISOBUS (extension of j1939) that can send icons and images to the displays. Maybe you can take a look at it

                              1 Reply Last reply
                              0
                              • ? A Former User

                                @kimot Thank you very much for your reply. It's sounds great and more I read about bus for IOT more I think Can is the best solution. But still the problem with the data length bother me. The more hack and tricks we have to add to a system the more problem we can have.

                                I made a little research on internet about Can and found that there is a new version called CAN FD that is actually compatible with CAN 2 but it can be used at a higher speed between to CAN FD nodes (but that is not really interesting us for our use). The real plus is that you can send data up to 64 bytes. And I think that could be the solution of the problem, no?

                                http://www.microchip.com/wwwproducts/en/MCP2561FD

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

                                @gasuter
                                CAN FD looks good, until you start to looking for IO chips.
                                MCP2561FD is only CAN bus transceiver ( like MAX485 ) with higher speed ability, then traditional CAN bus drivers.
                                It has no logic "on board".
                                You need something like MCP2517.
                                But try find datasheet, prices etc. for this chip.
                                I think, it will be very expensive way for us, like standard CAN several years ago was.

                                Nca78N 1 Reply Last reply
                                0
                                • gohanG Offline
                                  gohanG Offline
                                  gohan
                                  Mod
                                  wrote on last edited by
                                  #30

                                  Better performance usually means more expensive 😁. Maybe for the moment we just need to find a good way to make rs485 perform a little better

                                  wallyllamaW 1 Reply Last reply
                                  0
                                  • gohanG gohan

                                    Better performance usually means more expensive 😁. Maybe for the moment we just need to find a good way to make rs485 perform a little better

                                    wallyllamaW Offline
                                    wallyllamaW Offline
                                    wallyllama
                                    wrote on last edited by
                                    #31

                                    @gohan this is exactly why i brought up j1708, it is a hardware spec(can be any software on top), that uses max485 chips, you drive the de line instead of tx and it allows you to "see" collisions on the line. It would need a layer that does retransmits, but i dont see why the mysensors rs485 code clouldnt ride on top of that. There is an id that is utransmitted first that all nodes have to watch for which is duplicated efforst as the mysensors layer has that.

                                    I see it like this pseudo code:

                                    All nodes listen for an id,
                                    if none, then start transmitting,
                                    watching for dominant bits in between bits that hint someone else is transmitting, if collision back off for random time.
                                    if no collision transmit full message as normal mysensors message
                                    Other nodes must listen until message ends then they can start a transmit after random interval.

                                    The secret is really in tying tx (it looks like) low and control de, re is enables always so you can see other bits. Once a node has the bus, everyone shuts up until it is done. You only decides "who has the floor" and how to know when they relinquish it.

                                    J1708 is 9600 baud, which may be ok, but ill bet it would work at higher speeds.

                                    1 Reply Last reply
                                    1
                                    • gohanG Offline
                                      gohanG Offline
                                      gohan
                                      Mod
                                      wrote on last edited by
                                      #32

                                      I am not sure if customizing too much that protocol is going to be a successful way. I'm concerned that if you can't get a team of developers working on it and maintain it in the future, people aren't going to use it because the risk of don't having any kind of support will discourage them

                                      1 Reply Last reply
                                      0
                                      • K kimot

                                        @gohan
                                        Thanks for your message.
                                        All CAN controllers can send max 8 bytes of data, so longer messages must be divided to multiple packets. J1939 works this way too. That is what I do not want. With heavy traffic especially GW must again assemble packets to complete message, but packet of one message will not come one by one. Packets will be coming mixed from different nodes and GW must assemble them in memory to complete message from each node. So you for example has 30 messages in different state of completion. Some of them has received 1 packet and waiting for 2nd , some has 2nd and waiting for 3rd. ....
                                        I am concerned that it does not work for ATmega328, and must be used processor with more RAM.

                                        D Offline
                                        D Offline
                                        dukelec
                                        wrote on last edited by dukelec
                                        #33

                                        @kimot
                                        Much agree with you, I don't like CAN bus, let's return to RS485 bus, I already create a stand alone RS485 controller chip (CDCTL-Bx) which support arbitration (as same as CAN) and user data in packet is up to 253 bytes, the baud rate is also higher than CAN or CAN FD, and it's much more easy to use than the CAN:
                                        https://github.com/dukelec/cdbus_doc (Open Source Project)

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          Steph33
                                          wrote on last edited by Steph33
                                          #34

                                          Hi all,
                                          I would really be very interested in having CAN bus managed by MySensors.
                                          My new house is being built and I already planed to have a RS485 bus running along the house (RJ45 cable with one pair dedicated to RS485 bus and one pair for gnd/+5V). Having done some tests, I realize that I'm facing a lot of collisions and I don't want to explain to my wife that the light does not switch on when she clicks the switch because of a collision ;)
                                          So, I'm was looking at solutions based on CAN bus and was even ready to give up with MySensors (although I love mySensors) when I ended up on this thread.
                                          @kimot : have you progressed on your implementation ?
                                          If so, I'm OK for being your beta-tester, I only need to exchange integers between the nodes and the gateway, no strings so the limitation of the packet size is not an issue for me : 8 bits are sufficient to me.

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


                                          24

                                          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