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 of each sensor based on their address.
But I started wondering how I can replace a 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.
Is there a best practice when it comes to configuring DS18B20 sensors? I would like to set up my device. By set up, I mean that I would like to assign a specific DS18B20 to a specific relay.
I imagine it like so:
- Take a new DS18B20, connect it to a 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.
- Then unplug the 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 (the address was stored in EEPROM) so it is skipped. The second is assigned to relay 2 and the address is stored in EEPROM.
- The same procedure is applied to the third and fourth sensors.
- If four sensors are connected (the addresses are from EEPROM), then the device can run.
- When the user wants to replace a 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 a configuration procedure I'll be grateful for any materials.