[OpenTRV-dev] Multiple DS18B20 sensors

Damon Hart-Davis dhd at exnet.com
Sun Mar 6 15:15:13 GMT 2016

> On 6 Mar 2016, at 12:49, Jeremy Poulter <jeremy at bigjungle.net> wrote:
> Hi,
> I have just started adding the code to support multiple DS18B20 external temperature sensors (see https://github.com/opentrv/OTRadioLink/pull/44) but I have some queries regarding the sensor API before moving forward.
> Currently an instance of the TemperatureC16_DS18B20 class is needed for each DS18B20 sensor and at 17 bytes each this could limit the number of sensors that can be used. The API could be changed to pass an address to the read method dropping the memory usage down to 8 bytes (or even 7 bytes as the first byte is always 0x28) per sensor or even just an index that would require no additional bytes per sensor, but probably a little slower to read the sensor. As an aside, I am not sure what determines the order on the bus so there may be a possibility of the sensors being in a different order per read or per power-cycle. 

The order should be consistent by serial number.

> The obvious down side to changing the API is that you loose the nice consistent API that all the sensors have and will have to start adding a bunch of special cases to read the DS18B20 which I would think is probably not a critical use case so may not warrant polluting the code base, that being said are there other sensors that you may have multiple instances of and thus is it worth changing the base class to support indexed/addressed reads of a single sensor type?

My view is not, unless we have a very special use case.

One possibility is to have the DS18B20 implement two interfaces; one for the int16_t sensor for the first instance, the other would be an array of int18_t to get at the whole lot in one go.

> The other question I have is how important would hot swapping the temp sensors be, or is it ok to expect a power cycle after adding/removing/changing a sensor?

I think a power cycle is fine.



More information about the OpenTRV-dev mailing list