Detecting Arduinos order

Hello,

I have a project that will use a lot of Arduinos. I need to connect them one after another , each one of them will have an ID (stored probably in EEPROM), and I need to receive a string in the first one of them that show the order of the connected ids.

For example if I have 3 connected, it could be 1-2-3 or 2-3-1....

Any idea how can I do it - hardware wide and software wise.

Thanks a lot !

Assuming you have at least two Serial ports - or use SoftwareSerial - it can be done quite straightforwardly. Say Serial1 gets connected to Serial2 (or Master) downstream, Serial2 gets connected to Serial1 upstream, and stick to that scheme.

Master queries Arduino1, gets ID from Arduino1.
Arduino1 queries Arduino2, gets ID from Arduino2, sends it to Master.
Arduino2 queries Arduino3, gets ID from Arduino3, sends it Arduino1, which sends it to Master.
Arduino3 queries Arduino4, realises there's no Arduino4, sends special character/number to Arduino2, which sends it Arduino1, which sends it to Master.

The master receives Arduino1 ID, Arduino2 ID, Arduino3 ID, terminator. Now you know the order in which they're linked, and how many there are in the chain.

Now of course the question: what are you actually trying to do here?

@wvmarle I don't think your idea works and it ignores features that the chips have to offer.

Take a look at I2C or the addressed serial what the USARTS have to offer. You will of course have to

A. give them there addresses when they are programmed

B. and let the master know what physical order they are in.

There is no way (that works well) to let you work out the physical order along the BUS at run time.

Mark

Why would it not work? I think the idea is good.

You can also do it on I2C if you use Arduino Dues. They have 2 I2C ports. One can be a slave and the other is master. Every one checks if it has any other connected to its output. If it is asked (as a slave) it can report its own number plus the others downstream.

Didn't we answer this quite thoroughly recently for someone with a complex MIDI daisy-chain project?

@holmes4

I suspect that OP wants to avoid point B. Maybe OP can explain why this approach was chosen and an auto-detect is required.

And I doubt that a bus structure as in I2C or 9-bit serial allows to detect the sequence.

wvmarle's approach should allow that as far as I can see.

Hi,
Welcome to the forum.

What is your application that uses many Arduino and needs them to communicate?
How far apart are they?

Can you tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom... :slight_smile:

@OP - is this a bus architecture or daisy-chain?
Peer-to-peer or designated master?