Ds18b20 and emonTX3CM firmware

I was never good with bits and bytes!

Address I get is

28 C8 8E 79 A2 1 3 ED

I wondered if it was a different command for the UID.

Looks like a 0x03 sensor which explains everything!

One in the sameā€¦ 8 bytesā€¦ mine is just backwards from yoursā€¦ your ā€˜3ā€™ is the same as my 0x03 that I notice in my two worst-case sensors.

It is possible to make code that works with those sensors, once you know their quirks.

Ah serves me right for going for very cheap Chinese ones!

You and thousands of others, and in most cases thereā€™s really no way to know what youā€™re buying. My first approach was: if they donā€™t comply with the datasheet just ignore them, but thereā€™s enough of them out there (and nobody knows if theyā€™ve got them) that I figure you kindaā€™ have to support them, or spend the rest of your life answering queries about strange readings. If the 0x03 was an adequate test I guess you could just ignore them and print a warning, but weā€™ve no way of knowing if this is adequateā€¦ so far just 3 examplesā€¦ 2 of mine and one of yours.

Well I did buy a batch of 10! What sketch/program/HW are you using to get these test results?

Iā€™ll stick one on a Tasmota WmosD1 and see what it gives meā€¦

Itā€™s some ā€œextreme 1wireā€ testing Iā€™ve been doing on an stm32f207ā€¦ dual 1-wire buses, 400m of cat5, 100 devices per bus with adaptive bus load measuring. Iā€™m currently working on a full blown enviro-monitor rather than just a ds18b20. Will hopefully open-source it all eventually, but itā€™s early days.

Iā€™m interested in hearing the results!

Thatā€™s really very informative, thanks @dBC.

Iā€™m very tempted to check for the ā€œ03ā€ sensors and simply report ā€œbad sensorā€, rather than try to work around it.

It would be nice, alas probably unnecessary, to adjust the library to accommodate the ā€œ80ā€ sort too - those could then work down to something like 5 readings per second if you didnā€™t have too many of them. :grin:

Iā€™m going to copy all of your post and keep it with my DS18B20 data.

@Gwil, @glyn.hudson, @TrystanLea

I think you need to be aware of @dBCā€™s findings in post 78 above.

Actually, I recently throttled mine back to no more frequently than 2 seconds to avoid the self-heating I reported here.

1 Like

As I wrote - ā€œprobably unnecessaryā€, so Iā€™ve no real intention of doing it. Although, if in a moving fluid, self-heating is likely to be a lot less significant than it is in still air.

The library declines to process the sensors when itā€™s asked to run faster than 0.2 s - that was to protect the power readings, nothing to do with the temperature sensors.

I shall include a warning to be printed alongside the list of sensor addresses.

If the sensor is an ā€œ03ā€ one, you will see :

28 C8 8E 79 A2 01 03 ED Sensor may not be reliable

Thatā€™s the best way I can think of to handle the problem.

1 Like

From what Brian reported, I presume applying power rather earlier that you need to (assuming itā€™s decided we still need to switch it) is part of the answer. Given that sensors that use the RJ45 socket on our emonTx and emonPi get a constant (not switched) power supply anyway, itā€™s use is at best questionable.

My bus is permanently powered, so Iā€™m not well set up to test the effects of power cycling. But I did leave mine unpowered overnight and this morning the 0x03 sensor reads 25.000C. Iā€™m almost certain 25C wasnā€™t the last measurement it made yesterday, and if it was itā€™d be a helluvaā€™ coincidence with Brianā€™s 25C. So it looks like it remembers the last conversion for a while without power, and when that eventually fades away it replaces it with 25C.

Iā€™ll do some more tests to see if I can narrow down ā€œfor a whileā€ and update the post above when I have.

1 Like

This has, as you suggested earlier, got the scent of a fiddle/cover-up. Isnā€™t the honest way to report by some means that it hasnā€™t got a credible reading, then let whatever is receiving the data decide what to do? I donā€™t think Iā€™d like to trust one of those.

What Iā€™ve got to do is write @borpin a test sketch that varies the time between applying power and resetting/calling to convert, and/or between resetting and calling to convert, and ask him to try it and see what happens.

Its one saving grace is that it correctly implements this part of the spec:

If the DS18B20 is
powered by an external supply, the master can issue read
time slots after the Convert T command and the DS18B20
will respond by transmitting a 0 while the temperature
conversion is in progress and a 1 when the conversion is
done.

I use that approach for all sensors and then I donā€™t need any special code to handle the weird ones. I suspect thatā€™s not going to work in easily with your timing constraints and broadcast conversions though. Iā€™ve got the luxury of being able to wait until the device is finished, you mightnā€™t.

Before clearing the bench, I thought Iā€™d capture some shots of that approach in action. In all these Blue is the 1wire bus, and Yellow is the bus current draw so you can tell when a conversion is in progress.


The big picture. A directed ConvertT command followed by 10msec polling to see when itā€™s done, followed by a ReadScratch command. The resolution was set to 9-bits for this one so it demonstrates an out-of-spec conversion on a 0x03 device (520 msecs Vs 93.75 msecs)


Zoomed in on the ConvertT command. As the final bit of that command arrives at the device it starts drawing current. I immediately follow up with a read slot (the final Blue pulse) and it replies with a ā€˜0ā€™ to tell me a conversion is in progress. If that immediate read ever comes back as a ā€˜1ā€™, I count an ftc soft error and resend the command. Otherwise I know the device received it and acted on it, and I start the 10 msec read slot polling.


Zoomed in on the end-of-conversion. Eventually, a 10 msec read slot poll returns ā€˜1ā€™ and I know the device has a fresh conversion ready to be read so launch the ReadScratch command.

In emonLibCM, I do more-or-less the opposite: I broadcast a Convert T a calculated number of sample sets before the next logging report is due, so that the sensors should have finished converting and the temperatures are ready to retrieve after the power and energy values have been averaged and scaled, so that the most recent temperatures can be reported without waiting while the conversion takes place.

It wouldnā€™t be impossible to employ the technique you describe - it would mean doing and timing a test conversion at setup time, then using that instead of the data sheet value. It would come into its own if all the sensors on the bus happened to be from the ā€œ80ā€ family and a very fast logging period was required.

Am I therefore currently seeing the previous reading if the conversion is too slow? TBH, at 10s intervals it makes no practical difference to most people.

As youā€™re permanently powering your sensors, that looks as if it is probably the case. If you set the resolution to 12 bits, that will give the maximum conversion time and your ā€˜cloneā€™ sensors (according to dBC) will report in less than that, so you should get the present reading from 500 ms earlier.

But I have to stress that it is unrealistic to ask for the library to accommodate a device that fails to conform to the published specification.

1 Like

Yes that is fine and perfectly reasonable. I was just checking my understanding of the end result.

Just thinking about the warning if a ā€˜3ā€™ - perhaps

This DS18B20 clone may be unreliable and must be wired to RJ45 or Terminal 2 for constant power.

That doesnā€™t cover the case for you and 11-bit resolution (the default). If the temperature is changing rapidly, or even not so rapidly, because the library is good to at least a 5 minute reporting interval. That last reading might still be OK some of the time, but Iā€™d still call it unreliable.

And besides, are you sure thatā€™s the only fault those ā€œ03ā€ sensors have?

That definitely sounds more robust than basing anything on the MSB of the UID, but then againā€¦

Thatā€™s the approach I take. In fact on my crazy dense buses with my slow plodding one-sensor-at-a-time approach, readings can get seriously oldā€¦ ~ 100 x 700 msecs = 70 secs, worst case. I just report the age with the reading. In this case Iā€™ve got ~50 sensors on the bus and you can see the conversion as it sweeps through the sensorsā€¦ oldest is 33 seconds and newest is 0 seconds:

To avoid self-heating I already limit sampling frequency to no more frequently than 2 seconds, so theyā€™ll hit that limit when theyā€™ve got just a few sensors. And if the readings really are time critical to someone, I give them a mechanism to force the scan to a specified sensor, making it the next in the sequence and continuing on from there.

With your broadcast approach a lot of those problems go away, but I guess get replaced with another problem: you need to know theyā€™re all finished converting when you go to read the results. Maybe you could assume theyā€™re all going to take 750 msecs all the time, and never take advantage of the faster sampling times? How critical is timely temperature data?