Chip/sensor to get number of connected devices in series

Hi,

I am looking for somekind of chips or sensors that can be connected in series and then report back how many of them there are.

So imagine I have my Arduino A and my chips c. I should then be able to connect them like:

A--c--c--c, and they should be able to report back that there are three of them. The order should not matter.

I hope it makes sense. I've been Googling around forever with no results.

Do you know if anything like this exists?

Are you willing to program the sensor's so they can determine this? Seems to be quite an undertaking for some undetermined reason!

Paul

Can you explain a bit more what you're trying to do?

If you have an unknown number of chips connected to the same pin or pins, you can't tell how many are connected without something more. Some ideas from the common interfaces where you can have multiple devices on the same pins

have address pins and use a protocol that uses some form of addressing (I2C - that's why many I2C devices have address pins).

Have an extra line going to each place where a device can be connected, and use that line to tell the device that it's the one you're talking to (this is what SPI does)

Give each device a unique ID so you can use that to identify it (OneWire does this)

Sort of - some I2C devices have a jumper-settable address selection, from 0 or 1 up to 0 to 8.
You could run the I2C scan code and see how many valid addresses responded.
For devices with only 1 bit for address select, each device can have its address select bit controlled via an Arduino pin like a slave select (or from a shift register to save on pins), the one device with a 0 responds to that I2C address, the rest are looking for the address corresponding to a 1 on the bit do not respond

Or you could redevelop the Token Ring network.

Paul

There are also 'simplifications' of the TRN suggested by PaulS.
Each node is polled by the host, and is self-aware, and initialises itself before passing further requests down the line.
So you know the first 'id' returned is the first node in the chain, second is next etc...

The actual ID in each node can be selectable, pre-programmed (like one wire), or a random number... if the downstream node sees an upstream trying to report a duplicated id, it retries the init request (for a new, different node ID.

Thanks for the replies! I will look into I2C and Token Ring Network.

What I want is to be able to connect an arbitrary number of "blocks", in series, to my Arduino. So each of these blocks have power in, ground in, power out, ground out, and an addressable LED. But in my project I do not know how many blocks there are connected when the Arduino boots, and therefore I cannot specify the number of addressable LED's.

The best thing would be a chip/sensor with a programmable ID, so the Arduino could know that this block have e.g. three LEDs instead of one.

Hope it made sense :slight_smile:

The best thing would be a chip/sensor with a programmable ID,

Actually - the best thing is a random ID.
That way, when you replace a node - you don't have to change or remember anything - it installs itself!

The bus master - simply keeps a table of the node IDs as they are returned - in order from nearest (first) to the last.

lastchancename:
Actually - the best thing is a random ID.
That way, when you replace a node - you don't have to change or remember anything - it installs itself!

The bus master - simply keeps a table of the node IDs as they are returned - in order from nearest (first) to the last.

What I mean is that it could be nice to have a specified ID, so the block could emit something like "I am an X-block" or "I am an Y-block", and then I would have predefined what they are capable of, e.g. having 3 LEDs or 2 LEDs.

SomethingClever:
What I mean is that it could be nice to have a specified ID, so the block could emit something like "I am an X-block" or "I am an Y-block", and then I would have predefined what they are capable of, e.g. having 3 LEDs or 2 LEDs.

Yes, but the MAC-address should be separate from the function-description. Once the master has the address of every slave connected, then it can query the slaves to find out what they are and what they can do.

MODBUS may also be a useful protocol to look at. You just need to use the broadcast address to request all slaves to return their addresses. The slaves wait a random amount of time before responding, so that they don't all talk at once. If a slave doesn't get a reply from the master then it should wait another random time before transmitting again. Or the master sends a request to all "unconnected" slaves regularly and any slave which has yet to receive an acknowledgement from the master reports its address. Once you have the list of addresses, MODBUS is very efficient and relatively easy to write programs for masters and slaves.

@MorganS

I will look into that - thanks. It is also important knowing where in the series the slave is, so they need to know who are in front of them.

OK, then you must use some network where each slave copies the data to the 'downstream' slaves. Token Ring, probably. I2C, MODBUS and most others don't have any idea of the order that they are connected.

Each data packet can come from the master with an address for the desired slave. Say you want to talk to slave 3, for example. Send address "3". Slave 1 gets this, sees that it's not addressed to it, so it sends it onwards with the address reduced by 1. Slave 2 sees "2" so it knows the packet needs to take one more hop. It reduces the address by 1 and forwards it. Slave 3 sees that the address is now "1" so it knows that it is the one which must respond to that packet.

Use a string of Teensy Arduinos as they have enough serial ports to designate one as 'upstream' and one as 'downstream'. SoftwareSerial can be used on other Arduino types that only have one hardware serial.

The tricky part with using Serial for this is you can't just connect all the slave transmit lines to the master's receive pin. The ones which are LOW will fight the one which is HIGH. You need to have every slave release the transmit pin by making it INPUT after the serial transmission has gone out. This is where SoftwareSerial may actually be more useful.

Thank you! I will look into that :slight_smile:

I just thought about, as since I use addressable LEDs, I actually only need the slaves to tell where in the line they are and how many LEDs they have.

So maybe I should make a system looking something like this:
Arduino: A, Slave: s

A--s1--s2--s3--s4

So when the system is turned on, the slaves starts emitting upstream (the only way they can). They could emit a string like "s4-2led+", then s3 would get the message and add to the string "s4-2led+s3-1led+" and so on. When s1 then emits the string, the Arduino would know both the number of slaves, their order and their respectable number of LEDs.

.. and back to Reply #5

lastchancename:
.. and back to Reply #5

Yes :slight_smile: I just hoped there were some plug and play device for this, but I guess that was kind of naive.