Hello
I made a litttle program wich read two DS18B20 sensor. I had to search their address before to receive data i2c. BUT my question is : How can I replace any sensor I2C if it is broken ? without to change the program and these address ?
thanks for your help.
If you added the address to your code, then you cannot change the device unless you change the address in code. If your code finds the address by actively searching and storing found addresses, then the program will find the new address on reset.
The address is etched into each device individually and the device will only respond to its own address.
You could store the device addresses in EEPROM. At startup, read the current addresses and then find the addresses of the sensors you see on the bus. If one of them has changed (because you replaced it), overwrite the EEPROM data with it. This way, you can ensure that the system maintains knowledge of which is which.
Of course, if both of the sensors fail at the same time, this won't help.
DS18B20 is not an I2C device. It uses a 1-wire interface.