Issue setting DS18B20 resolution (Onewire_DS18X20) #17281
Replies: 5 comments 5 replies
-
Not sure if this helps but ... import onewire, ds18x20
from machine import Pin
import time
ow1 = onewire.OneWire(Pin(18)) # create a OneWire bus on GPIO18
ow2 = onewire.OneWire(Pin(19)) # create a OneWire bus on GPIO19
ds1 = ds18x20.DS18X20(ow1) # room temp
ds2 = ds18x20.DS18X20(ow2) # hot water tank temp
def one_wire_init():
# scan for DS18X20B device on bus 1
roms1 = ds1.scan()
# to display 1-wire IDs
print (roms1)
def room_temp():
# read 1-wire room temperature
try:
ds1.convert_temp()
except onewire.OneWireError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write('room temp ' + str(error) + '\n')
except OSError:
pass
time.sleep_ms(1000) # min of 750ms for 1wire conversion
try:
room_temp = ds1.read_temp(bytearray(b'(\xe7q\xee\x04\x00\x00\xd0'))
except Exception as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write('room temp ' + str(error) + '\n')
except OSError:
pass
print ('Room temp = ', str(room_temp))
return room_temp I wonder if the 1 second delay helps? |
Beta Was this translation helpful? Give feedback.
-
Check and change the wiring to match Roberts recommended connection, 3.3v and an additional pull-up
|
Beta Was this translation helpful? Give feedback.
-
If the 'Resolution' printed is 12-bits while you selected 9-bits, you most likely have a 'fake' DS18B20. |
Beta Was this translation helpful? Give feedback.
-
I hooked up a known genuine DS18x20 with that code and it works as expected.
A nice reading about fake DS18B20 is here: https://github.com/cpetrich/counterfeit_DS18B20 |
Beta Was this translation helpful? Give feedback.
-
The OneWire_DS18X20 MicroPython library often does not support resolution change unless it’s explicitly implemented. The standard ds18x20 driver used in MicroPython only supports temperature conversion and reading. Even if your sensor supports variable resolution, the driver may not write to the configuration register. ROM codes vary. The bytes 00-00 in the middle are not mandatory. Your sensor has a legitimate-looking CRC (e7). Clones/fakes may not support configuration changes or may ignore them. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I use the AZ-Delivery 1M cable DS18B20 digital stainless steel temperature sensor with the Onewire_DS18X20 library on an ESP32-WROOM-32.
Converting and reading temperature works fine, but I'm trying to change the resolution for faster conversation times without luck.
VCC of the DS18B20 is connected to Vin, so 5V.
My code is a slightly modified example from the library, and the result printed is 12 bit resolution, not the anticipated 9 bit.
I don't know where to start looking., so any help with ideas for troubleshooting would be welcome!
Edit: checked the ROM number, 28-ff-64-1f-41-b6-9b-e7, which does not follow the expected pattern 28-xx-xx-xx-xx-00-00-crc. Perhaps it's a hardware issue with the (fake) sensor?
Beta Was this translation helpful? Give feedback.
All reactions