RS485/RS232/Serial transport class for mysensors.org
-
I am very interested in doing this as I have many sensors local to my gateway. I use domoticz and see from http://www.domoticz.com/forum/viewtopic.php?f=6&t=8018 that people are doing this. I was just wondering would this do as a USB adaptor? Seems very cheap :
Also was looking at :
http://www.aliexpress.com/item/FREE-SHIPPING-5PCS-LOT-MAX485-module-RS485-module-TTL-turn-RS-485-module-MCU-development-accessories/1718665649.htmlAppreciate any feedback.
Thanks.
-
Hi everyone !
I needed a wired solution for my several nodes.
Here is the serial rs485/rs232 wired network transport for mysensors.
https://github.com/leodesigner/mysensors-serial-transport
It is based on the Majenko ICSC serial library.
Can you please test it? It is a beta version - but it is working for me.
(However, I am still waiting for my rs485 boards to arrive)
You can find more technical information at
http://sourceforge.net/p/arduino-icsc/wiki/RS-485/To use it, you have to:
- Put SerialTransport.cpp and SerialTransport.h to folder/directory/path SerialTransport in your library.
- Add #include <SerialTransport.h> to your .ino sketch
- Replace transport class with:
MyTransportSerial transport(Serial,0,-1); // serial port, node, dePin (-1 disabled)
Please let me know about bugs and how it is working for you.
I'm searching for a usb transport class, could i use this??
I'd like to connect my arduino (with sensors/actuators connected to it) to my rasberrypi through usb, without the wireless part, but still see them as mysensors sensors.
Is this possible or could someone make a transport class for it???
-
I'm searching for a usb transport class, could i use this??
I'd like to connect my arduino (with sensors/actuators connected to it) to my rasberrypi through usb, without the wireless part, but still see them as mysensors sensors.
Is this possible or could someone make a transport class for it???
@MarkV
Regarding the USB to RS485 adapters:
I think they are using a some kind of serial to USB chip like CH340/341. So your RPi will be able to see RS485 bus as the regular serial port. It may work. It worth trying, you can always build an Ethernet GW later in other case.@shabba
I am using exactly the same MAX485 modules. It is much more reliable media comparing to radio communication.@hek
Thanks for adding DE pin management code. -
hi.
I am not sure if it can be useful.. I have read this note recently, about rs485 powering chip (3.3v or 5v). And I found this interesting, for knowledge..
https://e2e.ti.com/support/interface/industrial_interface/f/142/t/93260
So what I understand here, and it makes sense, is that : even if some rs485 chips are able to be powered with 3.3v or 5v, if you want to power it with 3.3v, it can work of course with a 5v chip, but it is better to use a true 3.3v chip only. Because they are more sensitive to be rs485 compliant (better internal transistor).Always good to know :smiley:
-
@LeoDesigner : yeah, you're right, that is needed.
But there seems to be another problem, I can't get the current development code to work. I've simply interconnected two Nanos at D8/D9. The gateway and the motion example come up fine according to serial output and the motion sensor definiatly sends something via AltSerial but the gateway doesn't seem to recognize it.
A simple test, where I pipe the input on hardware serial of one nano to AltSerial on the second nano and from there to hardware serial works just fine, so hardware and AltSerial is working.
Sender:
#include <AltSoftSerial.h> AltSoftSerial altSerial; void setup() { Serial.begin(115200); Serial.println("Demo begins"); altSerial.begin(115200); } void loop() { char c; if (Serial.available()) { c = Serial.read(); altSerial.print(c); } }Receiver:
#include <AltSoftSerial.h> AltSoftSerial altSerial; void setup() { Serial.begin(115200); Serial.println("Demo begins"); altSerial.begin(115200); } void loop() { char c; if (altSerial.available()) { c = altSerial.read(); Serial.print(c); } }@TimO I cloned the current development branch, and tried to use a modified motion sketch, and a gateway sketch, simply interconnecting two mini-pros with TTL serial : the same problem appears.
I can only see garbage sent on the AltSerial pins, so the gateway don't see the message.
Before I dig more and start debugging, did anybody made progress on that problem ?
-
@anti: I'm glad, I'm not the only one! :-)
I've tried to find the problem, but had no luck.What is bugging me: it was working with a early version, before it was merged into development, but I don't see any changes.
I've not tested the latest / current version though.
-
Hi!
Glad to see 'wired' version of MySensor protocol coming.
One question - how long wires and how many sensors on one pair/multiple pairs will be supported?I'm thinking about cabling for new home, which means many meters of cable to every sensor/door/actuator/ligth/meter etc.
In best scenario - one cat5e - one termination (sensor/node/etc.)
Currently I'm looking for a cabled version of protocol to support it and be 101% stable (no hiccups and freezes over the protocol), so I can rely on my home.MySensors seems to be great to implement, but I'm worried about the signal... I was thinking about letting something around 12-24-30V thru one pair of Cat5 to power all nodes from one power-source (with backup batteries).
Or - are there any better alternatives for RS485, that doesn't need resistors, have no limitations of 32 devices etc?
-
Hi!
Glad to see 'wired' version of MySensor protocol coming.
One question - how long wires and how many sensors on one pair/multiple pairs will be supported?I'm thinking about cabling for new home, which means many meters of cable to every sensor/door/actuator/ligth/meter etc.
In best scenario - one cat5e - one termination (sensor/node/etc.)
Currently I'm looking for a cabled version of protocol to support it and be 101% stable (no hiccups and freezes over the protocol), so I can rely on my home.MySensors seems to be great to implement, but I'm worried about the signal... I was thinking about letting something around 12-24-30V thru one pair of Cat5 to power all nodes from one power-source (with backup batteries).
Or - are there any better alternatives for RS485, that doesn't need resistors, have no limitations of 32 devices etc?
@andriej
According to: https://en.wikipedia.org/wiki/RS-485
"It offers data transmission speeds of 35 Mbit/s up to 10 m and 100 kbit/s at 1200 m. "
also check this: https://www.maximintegrated.com/en/app-notes/index.mvp/id/367
You may design a bus with up to 256 nodes.
CAT5 is the best choice anyway for any type of communication (I mean you can run regular Ethernet on them too).
Check the video at the beginning of the post. It's a working example of two remote nodes connected only with one CAT5 cable over 50m. They are working at 115200 - however speed might be up to 1 Mbit/s. -
@andriej
According to: https://en.wikipedia.org/wiki/RS-485
"It offers data transmission speeds of 35 Mbit/s up to 10 m and 100 kbit/s at 1200 m. "
also check this: https://www.maximintegrated.com/en/app-notes/index.mvp/id/367
You may design a bus with up to 256 nodes.
CAT5 is the best choice anyway for any type of communication (I mean you can run regular Ethernet on them too).
Check the video at the beginning of the post. It's a working example of two remote nodes connected only with one CAT5 cable over 50m. They are working at 115200 - however speed might be up to 1 Mbit/s.@LeoDesigner but how would I connect all sensors in house and relays too?
SOme resistors needed? Star topology? Few gateways? -
@LeoDesigner but how would I connect all sensors in house and relays too?
SOme resistors needed? Star topology? Few gateways?@andriej
The star topology could be a problem. However for low speed nodes this may work anyway.
You may need something like RS485 hub :) or a GW with many RS485 bus ports.
Or just a separate MAX485 board for each node. You need to test it. -
@TimO Well... it turns out that the garbage seen on the wire was not garbage, just the binary serial protocol. And the node was desperately attempting to find a parent, with no success.
FYI this is how I workaround it. But I did not feel like I could fix it for 100% sure.
The gateway ignored the broadcasts from the node. The following code in MyTransportRS485 triggered for probably wrong reasons (sender=0; nodeid=0;station=broadcast) :
if ((_recSender == _nodeId) || (_recStation != _nodeId && _recStation != BROADCAST_ADDRESS)) { _dev.print(" wrongid: ");Since the gateway was not responding correctly to the node broadcasts, I solved the serial communication problem between node and gateway by defining a fixed node Id :
#define MY_NODE_ID 10(ps: the MySensors version used was cloned from git today)
-
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. -
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. -
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.@kimot
Just a quick look
http://www.aliexpress.com/item/MCP2551-High-Speed-CAN-Communicate-Protocol-Controller-Bus-Interface-Module/32472004400.html?spm=2114.031010208.3.27.bEv7Im&ws_ab_test=searchweb201556_1,searchweb201644_3_79_78_77_82_80_62_81,searchweb201560_1,searchweb1451318400_6148
They are five times more expensive.
But it might be another option for wired network too.
@andrej it is still a line not a star topology. -
Ok so if it's line-wire, then maybe I could wire all cat5e's to one patch-panel, terminate them there and from the patchpanel I could daisy-chain them on one magistral connection and also feed the 12/24V on one pair (i.e. orange/white orange) and data (i.e. blue/white blue).
How do you guys think it would work for cables in-home in-wall?
I guess the power feed would work ok (even including the voltage drop) but what about the RS485/CAN length?
I plan to run cat5 to every switch.Still can't decide if I should connect on-wall switches straight to Arduino (to control relays further) or to use small arduinos inside every wall switch to better control sensors there (temperature on wall) and possibility to program every switch differently. The idea is to get every wire to basement anyway.
-
@kimot what would be the CAN topology needed?
Does it support star topology? Im looking for a in-home bus over cat5e in walls...Regards
@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
-
@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...