Pages: 1 [2]   Go Down
Author Topic: Communication between a number of Arduino's?  (Read 2630 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been asked a few questions privately which I will respond to here, as they are interesting:

a) Can you hang multiple devices on the two wires between, on your drawing, the master and slave? (As envisioned for the "BreakWire LAN")

Yes, absolutely. Although I haven't tested it this Wikipedia page makes it clear that this is an intended  use:

http://en.wikipedia.org/wiki/Rs485

What I haven't done, and I wondered about that, was put in some sort of bias resistors (pull-up/pull-down) to make sure that the network has a known state if no device is addressing it. That is probably very sensible. See the diagram on the Wikipedia page.

b) Can you have a "masterless" net, if you overcome all that must be overcome in software? In other words, do you NEED a "master" somewhere, because of some hardware issue? (I do understand that having a master would make the software side much, much easier.)

I see no hardware reason not to. The point of having a master is to solve contention, so that the master is "in charge". But until the master decides to do something effectively electrically they are all equal.

c) Will the circuits be damaged if two devices try to transmit at the same time?

According to the datasheet for the LTC1480 they anticipate that this might happen, and the device is designed to handle it (that is, not fail).

d) Can the interface chip simultaneously send data and monitor what is appearing on the data lines, i.e. the lines connected to  pins 6 and 7?

Not the chip, I suppose you could connect the output of it back into the Arduino's digital inputs. I'm not sure what you would gain, as timing would be critical. I think the I2C hardware has some provision for that, that is "is what I am setting the lines to actually what they are doing?".

I would keep things simple if possible, and have a master, even if the master "chooses itself" at runtime. That is, when a device powers up, if it doesn't "hear" anything for a second it could assume that it is the first one, and try to become the master.

No doubt there are ways, but for the simple application of something like a home security system, or driving some signs from a central point, there is probably not much point to it.
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

(Oops! this crossed the ABOVE post "in the mail"... that is, they were both being typed at the same time... this paragraph added later.)

====
Thank you, Nick, for the work on the RS-485. (And for the reply to my offline message!)

A few questions arise... I've given them letter IDs to make (I hope) further discussion easier....

You've drawn what I'm hoping is just an example.... a "master" and a single "slave".

Having one participant in the LAN as "master" makes a whole bunch of things easier, but, in hardware, is the "master" "special" in any way? (That was question "A") Could we, for the sake of an example, have two peers interconnected (Q.B), say one at my house and one at my neighbors. And if EITHER detected something amiss... e.g. an intruder into an "empty" house... it would send a message onto the LAN saying "Help, help! Ring the bells"?

And, assuming that much is okay, could there be three peers on the LAN, not just two? (Q.C)

===
Another area of concern....

Suppose it is okay to have three devices on the LAN. And suppose, by bad luck, two of them begin to send data onto the LAN at the same time? Is it able to endure such an event without problems? Without harm to the electronics? (Q.D) "Obviously" (to everyone, I imagine), if two devices are both trying to send, the signal in the LAN will be gibberish. Is there a way for each of the sending devices to "watch" the LAN, as it tries to send? A way for it to see that its message is clashing with another message? (Q.E) What the programmer sets the system up to DO about a collision is a different question, for another day. My question today is: Can the sending device "see" that a collision is taking place? (Q. E re-iterated.)

Thanks! RS-485 might be just the wheel that I don't need to re-invent!
« Last Edit: November 14, 2011, 07:33:12 pm by tkbyd » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is the "master" "special" in any way?

No, except that some sort of pull-up/pull-down resistors should probably be on the network somewhere.

Quote
Could we, for the sake of an example, have two peers interconnected (Q.B), say one at my house and one at my neighbors. And if EITHER detected something amiss...

Well, you could. In other words, everyone listens, and sometimes somebody talks. In this example, it would be unlikely burglars would break into two houses at the same millisecond.

Quote
could there be three peers on the LAN, not just two

Lots of them, I imagine.

Quote
Is it able to endure such an event without problems? Without harm to the electronics?

According to the datasheet, yes.

Quote
Can the sending device "see" that a collision is taking place?

I'm not sure about that. But what I would do is send a message, and await some sort of response. If you don't get a response, re-send it. Then I would add a randomizing interval (like TCP/IP does I think) so that both ends don't try to resend at the same moment.

But I don't see any real reason why you couldn't have a master/slave arrangement. Then the master controls who talks when (like a teacher in a classroom). That way everyone doesn't talk at once.

Plus, the master could query (eg. every 1/10 of a second) each slave: "is everything OK?". So the slave could reply "burglars!".

This is safer really anyway, because if the burglars cut the wire (or turned off the power) and you are relying upon the slave initiating the conversation, you can't tell the difference between silence (because the power or wire is cut) and silence because nothing is wrong.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think Nick covered just about everything but I'll add a bit.

RS485 is restricted to 32 Unit Loads (ULs) and at first that meant 32 devices. These days however transceivers can be found that are 1/4 or even 1/8th UL, so you can have up to 256 devices on an RS485 line.

In a master/slave setup there is no physical difference between the two, well I suppose there can be but there doesn't have to be.   

Reliable collision detection is difficult. The common way to do it is have every node read what it's writing (just leave the receiver enabled), this will probably allow the two offending nodes to detect each other but other nodes might have trouble. If the two nodes are transmitting say 50% out of phase the waveform will be severely deformed and other nodes won't know so they may receive crap.

Therefore you need a good protocol to deal with this.

Also, Nick has drawn the standard configuration, I don't know how that works with clash detection as I think the levels will be undefined and anyway it can't be good to have conflicting voltages being driven onto the wire. The transceivers probably handle that but it's not good practice IMO to design a system that expects this contention.

There is a different way of wiring the transmitter that gets around this problem but all in all this is a multi-master issue and master/slave is much easier.

Having said that I'm working on a multi master network at present

http://busnet.robgray.com/index.php

This originally had all the clash detection etc but it got too complicated so I've simplified it. Rather than a bus topology I have a ring topology. This is potentially more reliable (a cut cable has no affect on the network). This is a multi-master network, any node can transmit at any time and there are no clash issues etc. Also, when finished there will be no special code required on the host device (say the Arduino), just read and write from/to the I2C port. At least that's the theory smiley

Quote
RS-485 might be just the wheel that I don't need to re-invent!
All the above is not just an RS485 issue, the same applies to any transmission media so you can't get away from it smiley That BreakWire will have the same problem and many others that RS485 has dealt with.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you all... lots of good stuff!

However, as for....

Quote
Then the master controls who talks when (like a teacher in a classroom).

You were never a teacher, were you? At least not of secondary or elementary school classes. <smiley-kitty>
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You were never a teacher, were you?

Well that was the theory. smiley
No I wasn't.


I've done a fairly lengthy write-up on the hardware, an error-checking protocol, and some example sketches here:

http://www.gammon.com.au/forum/?id=11428

This demonstrates how one Arduino can do something (like control a light) by sending via a cable pair to another one, using RS485.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Jeez Nick you have way too much time on your hands to knock that up over night.

Quote
No I wasn't.
Are you sure, you do good write ups.

The testing of UCSRxx is the way to go, but does have the issue you mentioned.

Many new processors have an RS485 mode on UARTs, with this mode there is a dedicated control pin that is deactivated at the end of the current character, you run this pin to the RE/DE pins on the transceiver and the hardware does the rest.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you sure, you do good write ups.

I was in charge of training at the company I worked at, for a while. smiley
Logged

Pages: 1 [2]   Go Up
Jump to: