Hello everyone! I'm new here on the forum, I have a problem and would like everyone's help.
I have a project composed of:
1_esp32
4_ds18b20
using the thonny compiler.
with micropython.
my goal is to read the temperature of the sensors, and be able to add or remove the sensors at any time.
I'm using the following code:
* ------------------------------------------------- ------------------------------------
Code: Select all
import time
import machine
from machine import Pin, PWM
import onewire, ds18x20
dat = machine.Pin (4)
ds = ds18x20.DS18X20 (onewire.OneWire (dat))
while True:
time.sleep_ms (750)
roms = ds.scan ()
print ()
# ds.convert_temp ()
print ('temperatures:', end = '')
for rom in roms:
print (ds.read_temp (rom), end = '|')
* ------------------------------------------------- ------------------------------------
makes reading perfect.
when doing a defect simulation of the ds18s20 sensor, the following error occurs:
the error happens when my sensor disconnects from the board.
temperatures: 28.8125 | 29.25 | 29.0625 | 29.25 |
temperatures: 28.8125 | 29.25 |
temperatures: 28.8125 | Traceback (most recent call last):
File "<stdin>", line 27, in <module>
File "ds18x20.py", line 40, in read_temp
File "ds18x20.py", line 30, in read_scratch
Exception: CRC error
I would like you to help me with this error.
thanks!