I'm relatively new to microcontroller programming, so please excuse me if my question is dumb.
I've created a simple device that allows me to control 4 relays based on temperature.
I bought four DS18B20 sensors, 4 relay board and Wemos D1. Everything works fine - I'm able to read the temperature or each sensor based on their address.
But I started wondering how can I replace single DS18B20 without recompiling the code, currently this isn't possible.
After searching a bit I found a couple of questions about the order of 1Wire sensors, for example, this one. I have no control over the order in which sensors are detected.
My question is:
Is there a best practice when it comes to configuring DS18B20 sensors? I would like to setup my device. By setup, I mean that I would like to assign specific DS18B20 to specific relay.
I imagine it like so:
- take new DS18B20, connect it to device and power the device
- the device should scan for DS18B20 sensors, if it finds one then it should assign it to relay 1 and store its address in EEPROM.
- the unplug device from power, plug the second DS18B20 and power the device again.
- the device again scans for DS18B20 sensors, it finds 2 devices. The first one is known (address was stored in EEPROM) so it is skipped, the second is assigned to relay 2 and address is stored in EEPROM.
- the same procedure is applied to the third and fourth sensor.
- if four sensors are connected (addresses are from EEPROM) then the device can run.
- when the user wants to replace the non-functioning sensor, the same procedure can be used
As I wrote I'm new to microcontroller programming so if there is a better way please let me know.
I'm mostly learning by following examples and tutorials so if anyone knows of an example showing such configuration procedure I'll be grateful for any materials.