Arduino Settings with Resistors or Dip Switch or ?

Hello,

I have a device (x) that can have 1 to many (y) devices that x communicates with.
The number of y devices can vary at any time (1-10).
Each y device needs to have an identifier (1-10) assigned to it.

I need a mechanism to tell x that there are a fixed number of Y devices.
I also need a mechanism to assign an identifier (1-10) to the y devices.

Currently, I am using a series of resistors on the Y devices and based on the resistance of the Arduino Pro Mini 3.3v, I can determine it's identifier. It works fine on my breadboards but I am converting this design to a PCB and looking for a better solution.

My current thought is to use a dip switch and a resistor array. I looked at various potentiometers but did not find anything that I thought would work. A potentiometer that would click into fixed positions would work but I was not able to find one. Both solutions are based on using a band of resistance and converting that to an integer. I've got to believe there is a better way.

I appreciate any feedback or recommendations.

Show us your current schematic.

I don't have this yet in my current schematic. I only have the resistors mentioned.

Let's see your current schematic, or is it top secret?

Yeah; depending on the specifics, I can think of a number of approaches (you could, for example, have the slaves have a button (or two) that you can manipulate in a specific pattern to set it's ID (with feedback in form of blinks from an LED).)...

But yeah, schematic of what you're doing now and some specifics would help us make more useful suggestions.

When you say communicating with, I assume you mean over a physical wired connection? Details please?

I have a similar application where each device has a unique ID and I store this number on the MCU EEPROM.
The number is entered initially via the seral port terminal.

It saves the need for additional hardware and it can also be changed remotely.

Nothing top secret, it's really just an Arduino Pro Mini with an NRF24L01+ radio.

I've attempted to show an image of the basic schematic below. To change which identifier goes with which Y device, I just move the breadboard jumper from R1, R2, R3, or R4. The sketch reads the resistance of A0 and assigns it a # 1-4.

This is a black box type device where I will not be able to change this setting via a console. I should have made that clear earlier. It can not be predictably preset from a console app.

I like the idea of the button sequence during setup. I currently have an LED that flashes during startup to indicate the identifier.

I can't help but think though that there is PCB mount Potentiometer that has defined stops. I have not been able to find one though.

I'd use a button and an LED on the slave devices, if it has to be controllable without computer - hold the button down to start ID-set mode, then press the button N times to set to ID = N (with no pause of more than, say, 1 second between presses), and after there's a second with no presses, it'd blink the LED N times, and write the ID to the EEPROM. Something like that.

How do these devices connect to the Arduino.
If they are I2C, then you could ping the I2C address, and only run the code for that device when an acknowledgement was received. Like this:

Wire.beginTransmission(0x41); // ping slave board
slaveBoard = !Wire.endTransmission(); // set to true if detected

Leo..

It is I2C. I will have logic in the 'x' device (controller) that will communicate with the 'y' (slaves/end points) but it (x) needs to know how many 'y' devices exist out there. The numbers can change for a variety of reasons.

The identifier in the slaves just has to be unique. It does not have to be a sequential number. Unfortunately, neither the pro mini or the nrf have a defined unique id (like a MAC address). I suppose that I could just pick a random number between 1 and a million and have the end point register that number with the server. The chances of a device collision would be very low. Periodically, it could check in and let the server know that it's still alive. It would be more of an automated slave registration process.

An I2C scanner returns the number of I2C devices detected.
You could run that code periodically.
Leo..

GranvilleMaker:
I can't help but think though that there is PCB mount Potentiometer that has defined stops. I have not been able to find one though.

It's called a rotary switch :wink:

But the idea of the I2C scanner sounds better.

Thanks for the feedback. Any thoughts on using a shift register like this setup?

At the risk of stating the obvious, you said you have up to ten maximum Y devices. If that's the case, dispense with the shift register and use a four position dip switch wired to four inputs using INPUT_PULLUP. You also don't want to use the SPI hardware pins as you've shown, you need those for the NRF but then you already knew that...