I2C chip to communicate with 50+ devices (hot plug)

Hi,

First of all excuse me for my English, I am not English native speaker, but I hope I will explain my problem well.

I do understand the basics of electronic and good enough in programming. But I do not understand a way to make Arduino communicate with lot's of devices by serial protocol. Here is what I need:

  1. I have arduino.
  2. I have a 2 long wires from SDA, SCL
  3. I want to connect 50+ devices at any time to that 2 wires, so they will be detected by arduino.

"Detected" means following:

  1. Arduino somehow (continuously scanning or by even) get to know that new device appeared
  2. Device must be assigned dynamic address to work with it later and added to array of devices.
  3. Having the array of connected devices, I need to read some basic information about the type of the device.
  4. Based on Device type I will apply other logic further.

Here is an example.

Arduino detected new device, let say push button, connected and assign to it address 0xF1. I reading some memory position on EEPROM where I stored device type. So, I read this and see that the type is "push button". Next, I connected another device, let's say it variable resistor. Arduino assign to it address 0xF2 and read the same memory position on EEPROM. Type is "variable resistor". Finally I connected another push button device with address 0xF3.

As a result I have an array of 3 devices, one of them is "variable resistor" type, two of them is "push button" types. Now arduino, based on device type must be able to read state "pressed/unpressed" from button devices, and current voltage from "variable resistor" devices.

  1. I suggest to use this library Arduino - Wire
  2. I do understand code to access device by address and read some memory value like this:
    Wire.beginTransmission(8); // transmit to device #8
    Wire.write("x is "); // sends five bytes
    Wire.write(x); // sends one byte
    Wire.endTransmission(); // stop transmitting
  3. I do understand that there is a ton's of sensors, including buttons and potentiometers to do the same, but I want to build my own kinda sensor.

But I do not understand:

  1. what chip's I can use to communicate through I2C
  2. how to build a circuit and wire it with I2C and button or I2C and resistor or I2C and let's say 3 led in a row to light them up individually.
  3. how memory value on "device" changed because of user action's, like pushed button by human.

another example of custom "sensor", hopefully will not confuse you more is this:

I have device communicating with arduino via I2C - the same button again, but in this case with some logic.
When I push button once, device must store value 1, push again - will store value 2, push again - value 3, push again - will reset value to 0. The rest of the logic the same: I need via I2C access device and catch that button was pushed and read current value of pushes (1,2,3 or 0).

I am appreciate any advices, thank you!

SDA & SCL (and Gnd) are the I2C bus signals.
They don't work the way you describe.
In your scenario, Arduino is the Master, and the other devices Slaves.
The Slaves can only respond to a request from a Master, and they must have some smarts to recognize their address sent by the master and respond to it.

What you could do is have each device create a common interrupt when it is plugged in, and have a unique address, say 126 (of the 128 available). When the Master sees the interrupt, it can scan all the addresses, updating a list of all the ones it sees below 126. If there is a response at 126, it can tell that device which address it should start using instead.

When a known device needs attention, it can use a different common interrupt, the Master can scan the devices to find who needed attention, and then run the appropriate query for that particular device to get it's attention.

Hope those concepts help. You will need some smarts at each device, can be a smaller Atmega part that supports I2C.
Take a look at some of these, this can be added to your IDE and the parts run like regular Arduino parts. You may need a Programmer to set them up (not just a USB/Serial interface adapter)

CrossRoads:
The Slaves can only respond to a request from a Master, and they must have some smarts to recognize their address sent by the master and respond to it.

Thank you for reply.

What about this http://www.microchip.com/wwwproducts/en/24LC256
Looks like it has I/O pins and support I2C.

About "smart to recognize their address" - what if I pre-write this devices with UUID (unique identifier)?

During the research this is probably a solution?

  1. Daisy chain shift registers

  2. Chain ADC/DAC chip's https://www.maximintegrated.com/en/products/analog/data-converters/digital-to-analog-converters/MAX5233.html/tb_tab0

or https://www.eeweb.com/app-notes/download/2359

  1. Have mutiple I2C buses with TCA9548A 1-to-8 I2C multiplexer

What do you think?

noiasca:
I2C is "Inter-Integrated Circuit" - more ore less all components on one PCB. So I just wonder, if your 50 sensors are on one PCB or have to be connected via long cables ... which distance to you want to achieve?

It on the same PCB. Rougthly 2 ft by 2 ft size

noiasca:
if it is on one PCB, why do you need "hot plug"- and arduino "get to know that new device appeared" ...

Because it will be something like constructor/learning board when device will communicate depending on what plugged in.

Is not the Arduino implementation of I2C known for its ability to hang the processor if there is dodgy stuff happening to the I2C bus ?

So, to whom it may be interested:

There is actually a way to do communication via 1 or 2 wires, like I2c with DHCP-like addresses and collision resolving. This is unbelievably amazing library GitHub - gioblu/PJON: PJON® (Padded Jittering Operative Network) is an experimental, arduino-compatible, multi-master, multi-media network protocol. which I even already donate.

They are support even smallest arduinos.

I taken notice from the first answer that I need something smart to obtain address and then manipulate leds and e.t.c with PINs.