Ok, so my application comprises a series of servo motors, up to 8, controlled via an Arduino Uno. Each motor attaches to a Darlington driver, which connects to a 74LS595 shift register. The shift registers cascade from the Arduino, pretty much as depicted in the attachment. Note: The attached image depicts two servos coming from each shift register, but my project will only be using one servo per register. Imagine though that each shift-regsiter/driver/motor instance is a seperate piece of hardware that connects to the preceding one via a plug/socket, which chains up the digital pins, common ground and voltage rails. At any given time there will be between one and 8 instances connected together. I should also mention that my project uses three more Arduino pins for a second set of cascaded 74LS595’s to control LED’s. So each module will have 2 shift registers, a driver and motor attached to one of them, and a series of LED’s connected to the other.
The device has a switchable configuration mode, in which it does a count of how many devices are attached, and this could be achieved by sacrificing one bit on each register to be held permanently high or low, in contrast to the other 7 bits when in config mode. It’s just a simple pattern match to detect how many “units” are present. Whatever method for detecting is used, the count is then saved to EEPROM. When flicked over to normal operation, and each time the device is reset/powered on, this count is read back from EEPROM and another device-count-calculation is performed. If the numbers don’t match, then we must go back into config mode.
It’s important that I know how many devices are attached when we enter normal operation. It’s even more important to know when this changes as the device will think it’s behaving normally but in reality it’s failing one of its prime purposes.
Here’s the thing, I don’t have a problem with any of the above, but what I can’t detect by this method is whether or not the add-on devices have been reassembled in a different order. For example; 1) user switches on in normal mode and is advised config needs to be done before normal operation, 2) user performs automated config, 3) user resets and enjoys device in normal mode, 4) (and here’s the problem) user switches device off and pulls modules apart, reassembling in different order but the same original number of modules, 5) user turns device back on and Arduino is none the wiser.
So my question is this: How can I uniquely identify each module, so that when I’m in config mode I can store not only the device count, but each individual identifier too. If I could do this I could detect their assembled order and either recalibrate or better yet, have the device gracefully adapt to the new order.