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:
I have arduino.
I have a 2 long wires from SDA, SCL
I want to connect 50+ devices at any time to that 2 wires, so they will be detected by arduino.
"Detected" means following:
Arduino somehow (continuously scanning or by even) get to know that new device appeared
Device must be assigned dynamic address to work with it later and added to array of devices.
Having the array of connected devices, I need to read some basic information about the type of the device.
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.
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
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:
what chip's I can use to communicate through I2C
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.
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).
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.
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?