RS485/RS232/Serial transport class for mysensors.org
-
@andriej
RS485 was not designet for multimaster communication, where 2 devices can communicate on the bus at same time. RS485 bus state at this time is not defined. For example if node on RS485 on one end of bus sends message end perform "control" lisening on bus if recieve the same message( what is with correct circuit of RS485 transsiever immposible ), then this received message can be the same. But if in the same time another node on oposite end of bus sends different message, then node on the middle of bus recieves something random.
But CAN bus has allways defined state. It has dominate state and recesive state, so node witch send dominate bit cannot be pushed yb node witch at the same time sends recesive bit. I now, thet this feature we cannot use with normal serial communication, but still we can controll correct sending of datagram by lisening bus by sender. If we recieve the same message what we send, there is 100% shure, that the same message lisens every node on CAN bus. On RS485 this is not garanted. Bus topology is the same end we dont need "dePin". So we can use normal serial library. And CAN transciever is not so expensive as wrote LeoDesigner. Look here:And sorry for my english
@kimot Thank you for the information - your english is good enough to understand. :-)
I'm just looking for more simple protocol than ethernet to send data from various places - wired.
And it seems that, for longer distance and cat5e cable in-wall, ethernet is the only choice :-( -
@kimot Thank you for the information - your english is good enough to understand. :-)
I'm just looking for more simple protocol than ethernet to send data from various places - wired.
And it seems that, for longer distance and cat5e cable in-wall, ethernet is the only choice :-(@andriej
Just put CAT5e to every place (or even two CAT5e to each TV, room - as I done myself). Later you will decide what kind of signals will travel over CAT5e wire. It can be Ethernet or RS485, CANbus, or something else. Regular twisted pair Ethernet is also has a star topology with central hub/switch. (You may also remember an old Ethernet system with one base cable and terminating resistors on the both ends). For a really long distance - RS485 is the winner anyway - up to 1200m on slow speed. -
@andriej
Just put CAT5e to every place (or even two CAT5e to each TV, room - as I done myself). Later you will decide what kind of signals will travel over CAT5e wire. It can be Ethernet or RS485, CANbus, or something else. Regular twisted pair Ethernet is also has a star topology with central hub/switch. (You may also remember an old Ethernet system with one base cable and terminating resistors on the both ends). For a really long distance - RS485 is the winner anyway - up to 1200m on slow speed.@LeoDesigner I will put cat5e for 'LAN' purposes to proper socket, but I also want to control my lights not via connecting/disconnecting 230V in-wall, but in central control panel.
I was planning to use doorbell push buttons on walls just to give signal to automation and then MCU will set proper relays/dimmers on/off etc.That's why I was thinking about putting cat5e also to on-wall switches, then on 1 pair make the +/-12V signal, another pair for data bus etc. And now I'm looking for most efficient way to connect it everything together.
Each room will have temperature sensor for sure (in the switch), some may have dimmers etc. Last idea was to put mini arduinos inside the hole in wall, but I'm afraid of resetting them every once in a while, just because arduino likes to hang itself... -
@andriej remember to calculate how much current you can take thru cat5e and how much load there can be with one pair.
From wikipedia: "Maximum current per conductor 0.577A". So this would make P=UxI -> 12Vx0.577A=6.92W. There is calculations where one nano can take max 1.4Watts. You could use more wires of the car5e for power or lift voltage upper. 48Vx0.577A=27.70W ;) -
@andriej remember to calculate how much current you can take thru cat5e and how much load there can be with one pair.
From wikipedia: "Maximum current per conductor 0.577A". So this would make P=UxI -> 12Vx0.577A=6.92W. There is calculations where one nano can take max 1.4Watts. You could use more wires of the car5e for power or lift voltage upper. 48Vx0.577A=27.70W ;)@pjr I'm aware of that :-)
Still struggling with decision either to use the CAT5e just as a loooong cable to (doorbell) switch or use it to PoE small nanos all over the place and run i.e. MQTT on each wall-switch separate.
In second option the RS485 protocol would be the best, because of small form factor (smaller than ethernet port inside switch) and possibility to use MySensors too ;-) -
I think, that CAN transceiver chip is better then RS485 transceiver chip.
Then we dont need direction setting pin and bus state is better determined, becose CAn bus is prepered for bus collisions, RS485 not.
I mean only CAN bus transceiver, not CAN controller ! For example MCP2551 or MCP2562.
And we can use normal serial library. -
@andriej said:
use it to PoE small nanos all over the place
Which components do you have in mind? I 'm thinking in that direction too.
-
@kimot what has to be done to prepare MySensors to use CAN?
I'm thinking about ordering some modules for tests. :-)@andriej
It is a pity that not paying more attention mysensors.org for nodes interconnected by wires. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. I think that used ICSC library does not address this matter satisfactorily and with a larger number of sensor problems arise. ICSC library uses a Serial Software library by heavyweight each node on the bus, because all must be checke every bit transmitted on the bus. Look at different implementation:I think, thet using hardware UART is absolutely necessary.
Or why when we use a separate module for radio transmission, we use the special module for robust message transfer over the wired bus? CAN controllers are not so expensive in this days:After correct CAN controller configuration, we simply write a message to the CAN controller and forgot about it. No check or bus arbitration. And through interrupt pin from the controller just pick up the incoming message with our ID or broadcast.
I know it's not as simple as using only RS485 transmitter itself, but we are guaranteed connecting maximum of 110 nodes and various libraries for Arduino for this CAN controller exist.
-
@kimot what has to be done to prepare MySensors to use CAN?
I'm thinking about ordering some modules for tests. :-) -
@andriej
But on the other side, with simply CANbus, we have got only 8 byte payload for our data. -
@andriej
It is a pity that not paying more attention mysensors.org for nodes interconnected by wires. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. But it is very difficult to find peer-to-peer protocol for RS485. Mainly because of solving collisions on the bus when multiple sensors. I think that used ICSC library does not address this matter satisfactorily and with a larger number of sensor problems arise. ICSC library uses a Serial Software library by heavyweight each node on the bus, because all must be checke every bit transmitted on the bus. Look at different implementation:I think, thet using hardware UART is absolutely necessary.
Or why when we use a separate module for radio transmission, we use the special module for robust message transfer over the wired bus? CAN controllers are not so expensive in this days:After correct CAN controller configuration, we simply write a message to the CAN controller and forgot about it. No check or bus arbitration. And through interrupt pin from the controller just pick up the incoming message with our ID or broadcast.
I know it's not as simple as using only RS485 transmitter itself, but we are guaranteed connecting maximum of 110 nodes and various libraries for Arduino for this CAN controller exist.
@kimot
Thanks for pointing to mrbus.org.
I have seen this before - it's really nice implementation of RS485 bus management.
It's worth trying to implement it. However, I can see only one weak point of ICSC lib. It's a moment when both nodes listening a bus and starting to transmit at the same time. In this case the both packets will be lost. (This situation can occur only during the transmission of the first starting byte, so higher bus speed can make this situation rare.)
I have both the radio and wired mysensors network. And wired network in order of magnitude is more reliable. I have a really small amount of lost packets. The packets are retransmitted only due delay in the code of the nodes. -
HELP: Please instructions on how I can run this RS485 transport class for beginners.
Some basic questions:
- First point instructions: File "SerialTransport.h" and "SerialTransport.cpp" download to C:\Program Files (x86)\Arduino\libraries\MySensors[here]. is this correct ?
- On the second point instructions: "Add #include <SerialTransport.h> to your .ino sketch" but examples do not have this:
https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/MotionSensorRS485
https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/GatewaySerialRS485
way ?
In what file i must put this line "#include <SerialTransport.h>" ? main sketch ? - The third point instructions: Replace transport class with: "Replace transport class with: " where exactly ? Maybe I have a different version MySensors because I can not find the declaration "#define MY_RADIO_RF24" and replace it with a "#define MY_RS485". I do not know how to change the NRF to RS485 in lib MySensors. Please precise instructions with examples for the current version lib MySensors.
- Can I get examples of sketch (confirmed that work with the physical bus RS485) Gateway and sensor.
I use Windows, path of arduino lib is: C:\Program Files (x86)\Arduino\libraries.
The only thing that works:
When I connect RS485 to USB on Raspberry Pi (domoticz) and on the other side sensor (Arduino Pro Mini + DHT22) received on Raspberry:radek@raspberrypi $ cat /dev/ttyUSB0 radi init failIt sent the sensor by the RS485 to Rasberry PI. So the RS485 is working properly.
Sorry for my English and thank you for your help.
-
In the examples, there is no information on how to disable the radio NRF24 and enable RS485, this is my main problem.
MySensors still try init Radio NRF, because no radio connected in sending "radio init fail"
Renovate the house and so I want to use it:
Raspberry Pi (Domoticz) <--- USB ---> MySensor Gateway RS485 <--- RS485 (Cat5e) ---> MySensors Sensors & Actuators (x 20)Will show photos when I finish.
-
@radekzm said:
In the examples, there is no information on how to disable the radio NRF24 and enable RS485, this is my main problem.
It is this line that activates the RS485 transport (also note that no radio is activated).
https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewaySerialRS485/GatewaySerialRS485.ino#L56I haven't had the opportunity to test this thoroughly. So there might be issues.
-
I think that constat value:
#define MY_RS485It is doing nothing and changes nothing. This constat value is only on exmaple sketch. It is not a reference to the constat value in the library MySensros and mysensors-serial-transport.
Searching 1628 files for "MY_RS485"
0 matches??? I still do not know how to use the RS485 instead of NRF24 ???
-
That's exactly what I looking for !. In my version of the library that are missing.
In my version of the library that (supports RS485) are missing.
I downloaded the Library https://github.com/mysensors/Arduino/archive/master.zip this is my problem.
Should I download from https://github.com/mysensors/Arduino/tree/development/libraries/MySensors.The last question: Do I have just these two files download and replace from second url and that all ?