Finding New Devices on Network

Hello all,

I have a serial network setup on RS 485. Each device in another Arduino that has a hard-coded address, sort of like a mini MAC address.

I want to periodically query the network to determine if there is a new Arduino. If I simply send a command I don't want all the Arduinos to reply so how would I set it up to add new devices one by one?

I just need a push in the right direction as I've hit a wall.

do you know the address of the newly connected Arduino before you look for it?

Maybe you could do something like this on the client

if(previouslyAnnouncedConnection == false){
  //command to listen for specific "new arduino?" command from host arduino
  if(commandReceived){
     //   send response
     previouslyAnnouncedConnection = true;
    }
}

No they will be randomly generated. I plan on making enough that manually keeping track will be silly.

I think that what Qdeathstar meant was "Do you know the address? [u]If not[/u], maybe...".

Well wouldn't all NEW Arduinos then reply to that command? I am using RS 485 so I believe only one can transmit at a time.

Here's how I might approach it:

  • From time to time, the master broadcasts a query to new devices.
  • Each new device randomly decides whether or not to reply. The probability of response has to be low enough to ensure that sometimes only one new device will respond to the query. Usually, there's only one new device at a time, so the probability can be 1/2 or better.The response should contain some unique identifier for the device.
  • If two devices answer, the response will be garbled, and won't pass message integrity checks. It'll be treated as no response. RS-485 can withstand bus contention indefinitely.
  • When the master hears from a new device, it greets it, referencing its unique identifier, does some initial housekeeping, and registers the device on the network.
  • When the new device connects with the master, it stops thinking of itself as a new device, and no longer responds to a new device query. Of course, that's presuming that you can take liberties with the communication protocol. If you're committed to some particular protocol already, you'll have fewer options.

So, tell us: Are you committed to an existing protocol? What kind of device is the master - something with plenty of speed and storage, like a PC, or something small, like another Arduino?

Everything will be Arduino Megas or Unos. The Master will be a Mega for sure. I'm using RS 485 as the hardware standard and wiring things up in spec to that(At least I believe so). The software side is custom so variances from any protocol are okay.

I didn't think of the random % chance to talk back. With how fast the Arduino can communicate even if I ran the periodic query once every second(Fast to us slow to Arduino) and set the random chance to like 20% in most cases it should connect within a minute which is fine by me. I don't need it to be super fast. Thanks!

After reflection, you might be able to accomplish this more simply by simply polling all the unused addresses in turn. If the address space is reasonably small - say, 255 devices addresses and one broadcast address - it shouldn't take too long to register a new device.

The best approach might be to communicate with all existing devices, and then try one unused address, go back to the existing devices, and try another unused address. I would expect that a no-reply timeout would take a long time compared to a successful handshake, so it might be best to avoid trying them all in a burst.