DS18B20 CRC error

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: DS18B20 CRC error

Post by davef » Thu Dec 09, 2021 9:19 am

Thank you for explaining this.

The only part that I still do not understand is:
The text with the AssertionError is given in the assert statetment
The assert statement has the text 'CRC error' and the except statement said

Code: Select all

except CRCError
I can see that the message returned by the assert statement is 'CRC error' but how does one know what keywords have to be used in the except statement ... or maybe it doesn't matter what you say?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: DS18B20 CRC error

Post by Roberthh » Thu Dec 09, 2021 9:46 am

The text of an assert statement is not related to the Exception type at all. It is an arbitrary text, could be "Oops! Wrong CRC again". An assert statement will raise an AssertionError, if the expression in the statement is False. It will NOT raise an CRCError. It is a statement like "raise CRCError" which causes a CRCError exception.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: DS18B20 CRC error

Post by davef » Thu Dec 09, 2021 6:01 pm

Thank you for persisting, your explanation has helped. After using "except OSError" several times in scripts I thought that the term OSError was a keyword.

I confused things at the start by not stating that I was using the standard ESP32 image. I wasn't aware that there was another One wire implementation that appears to be more useful/robust/?

After reading

Code: Select all

https://github.com/cpetrich/counterfeit_DS18B20
the chances of me having good DS18B20 waterproof probes from China is about 0%.

The replacement probe has worked for a whole day using your code.

Thanks again.

Post Reply