Changing or give the slave adress via master arduino in i2c

hi!

i will try to show my problem the best i can, if isn't please tell me, English isn't my mother language (and also is my first post hehe).

in my actual project i want to establish a Bluetooth connection from the master arduino to the PC, but the information that i want to send is given by a consecutive arduinos connected in i2c.

So, each slave arduino it will send to the master only two ints, that then the master will be sending to the PC, the problem is that not all the slaves are connected at the beginning, they will be constantly plugged and unplugged from the chain, and to complicate more the things, there is no order, so in one interaction the slave number 1, can be the 4 in other interaction, so programing only one address to each arduino does not fix my problem.

there is any form that the address of the slave is given by the master when this recognizes the existence of another slave? or other solution that when the slave is connected he knows what it is his address?

here i leave a video that represents what i want to accomplished, (the difference is that i will not use sensors, only digital pines to the slave and sending receiving ints).

littleBits

thank you very much :smiley:

It sounds like you want the new device to work as a multi-master setup since a slave can't start a transaction. A master could scan until it found an address that was not acknowledged and then use that address to respond to other masters. The problem is Wire has a reputation of being fragile with multi-master, I suspect this sort of thing can be done with AVR but you need to explore the I2C libraries well, there are other implementations on Github, and Atmel Studio has some, this is not a simple problem.

So, each slave arduino it will send to the master only two ints, that then the master will be sending to the PC, the problem is that not all the slaves are connected at the beginning, they will be constantly plugged and unplugged from the chain, and to complicate more the things, there is no order, so in one interaction the slave number 1, can be the 4 in other interaction, so programing only one address to each arduino does not fix my problem.

I2C is the wrong choice for this communication. You'll get all the problems related to a multi-master setup as ron_sutherland already explained. Additionally you'll get the problem that the I2C bus will have a constantly changing bus capacitance, so you either have to adapt the pull-ups with every sensor connected to the bus or you have to adapt the overall capacitance automatically. For both I see no solution (there might be one but I'm not experienced enough in such circuits) so you have to change the bus system for this.

I don't understand your problems with the addressing. Let's say you have 30 slave arduinos available. Assign each an individual ID and make that the bus address (for whatever bus system you will use in the end). What's the problem if slave #5 is connected before slave #1 is connected? Both will be addressable and if you constantly monitor the members on the bus you can have an ordered list of the slaves in the order they appeared on the bus. So explain why this isn't possible.

they will be constantly plugged and unplugged from the chain

welp... as usual it is a good thing I did not quote the job. Hot swapping is a thing and I think there are even some chips to help with it for I2C but...

I2C is probably the wrong sort of bus, you probably want a transmission line that can have a uniform impedance (more or less) along its run (e.g. RS485 cable, or CAT5 cable). Having the same impedance everywhere does a lot of things which I don't feel like explaining so let's refer to is as JFM. Basically, it allows a circuit to be done that expects to be connected to a known impedance, and it will magically work. Some of the JFM involves having a proper termination at the end of the transmission line (differential pair).

As it turns out I am working on a RS485 circuit that should deal with being plugged into an active data pair, but it requires power. I plan to test it next month, so it could have errors at this time.

pylon:
I2C is the wrong choice for this communication. You'll get all the problems related to a multi-master setup as ron_sutherland already explained. Additionally you'll get the problem that the I2C bus will have a constantly changing bus capacitance, so you either have to adapt the pull-ups with every sensor connected to the bus or you have to adapt the overall capacitance automatically. For both I see no solution (there might be one but I'm not experienced enough in such circuits) so you have to change the bus system for this.

I don't understand your problems with the addressing. Let's say you have 30 slave arduinos available. Assign each an individual ID and make that the bus address (for whatever bus system you will use in the end). What's the problem if slave #5 is connected before slave #1 is connected? Both will be addressable and if you constantly monitor the members on the bus you can have an ordered list of the slaves in the order they appeared on the bus. So explain why this isn't possible.

i find that in some point i2c the best solution, but it seems actually isn't, im still searching for protocols of communication, but if you have one that can be a solution, please tell me haha.

in the other way, the problem of the order of slaves is that in theory the project will not have a limit of arduinos o AVR's (i explore the solution with AVR but im not so familiar with it, and also for the ARV i will need a protocol of communication), so not having a maximum of slaves will allow me to play with 5, or 10 depending of the time, and expand the uses (no more than 112, actually no more than 20)

i find that in some point i2c the best solution, but it seems actually isn't, im still searching for protocols of communication, but if you have one that can be a solution, please tell me haha.

For the moment I ignore the protocols and concentrate on the physical hardware layer. I2C is definitely the wrong choice. From what you told us yet (not so much!) it sounds like a CAN bus would do the job.

I still don't understand why the order of the plugging of the slaves is relevant in your project. Please describe that in more detail. Just because you need up to 20 slaves doesn't mean you have to know the order they were plugged in.

This hot-swap I2C chip from Diodes is new.

Maybe with stuff like that I2C could work, a common node and a buffer between each device and the common node. The power supply needs soft start during the hot swap. I think this is the sort of stuff found in big server racks that do IPMI (e.g. SMBus stuff).

The common bus capacitance probably needs to stay below 400pF on each wire so that limits the wire length for the common segment.