Page 1 of 1

DS18B20 wrong serial code/adress/roms

Posted: Thu May 28, 2020 5:49 pm
by BigStupidBeast
Hi.
I have ESP23 dev kit with micropython firmware XX.
I also have ds18b20 waterproof sensor (datasheet link: https://datasheets.maximintegrated.com/ ... S18B20.pdf

I wrote this code for it:

Code: Select all

import time, onewire, ds18x20, machine
from machine import Pin

ds_pin=Pin(19)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))

roms = ds_sensor.scan()

for rom in roms:
    print(rom)
It returns this info:

Code: Select all

bytearray(b'(\xbcN6\x14\x19\x01\xba')
Before reading temp data from sensor, we first need to use the scan() function to scan for DS18B20 sensors. The addresses found are saved on the roms variable (the roms variable is of type list). scan() function sends request and sensor returns its unique 64-bit serial code.

I used manual here https://randomnerdtutorials.com/micropy ... 2-esp8266/

Today I bought two more ds18x20 waterproof sensors (I don’t know what type of sensor - ds18a20/ds18b20 or else - are they, ‘cause eager chinese manufacturers sealed sensors inside metal bullet too good, so I can’t just look inside).
I tried to run the same code with them, but it returned the following:

Code: Select all

bytearray(b'(\xff\xff\xff\xff\xff\xff\xff')
bytearray(b'(\xfe\xff\xff\xff\xff\xff\xff')
bytearray(b'(\xfc\xff\xff\xff\xff\xff\xff')
bytearray(b'(\xf8\xff\xff\xff\xff\xff\xff')
bytearray(b'(\xf0\xff\xff\xff\xff\xff\xff')
bytearray(b'(\xd0\xff\xff\xff\xff\xff\xff')
bytearray(b'(\x90\xff\xff\xff\xff\xff\xff')
bytearray(b'(\x90\xfe\xff\xff\xff\xff\xff')
bytearray(b'(\x90\xf6\xff\xff\xff\xff\xff')
bytearray(b'(\x90\xe6\xff\xff\xff\xff\xff')
bytearray(b'(\x90\xc6\xff\xff\xff\xff\xff')
bytearray(b'(\x90\x86\xff\xff\xff\xff\xff')
bytearray(b'(\x90\x86\xfd\xff\xff\xff\xff')
bytearray(b'(\x90\x86\xf9\xff\xff\xff\xff')
bytearray(b'(\x90\x86y\xff\xff\xff\xff')
bytearray(b'(\x90\x86y\xfe\xff\xff\xff')
bytearray(b'(\x90\x86y\xfa\xff\xff\xff')
bytearray(b'(\x90\x86y\xf2\xff\xff\xff')
bytearray(b'(\x90\x86y\xe2\xff\xff\xff')
bytearray(b'(\x90\x86y\xa2\xff\xff\xff')
bytearray(b'(\x90\x86y\xa2\xfd\xff\xff')
bytearray(b'(\x90\x86y\xa2\xf9\xff\xff')
bytearray(b'(\x90\x86y\xa2\xf1\xff\xff')
bytearray(b'(\x90\x86y\xa2\xe1\xff\xff')
bytearray(b'(\x90\x86y\xa2\xc1\xff\xff')
bytearray(b'(\x90\x86y\xa2\x81\xff\xff')
bytearray(b'(\x90\x86y\xa2\x01\xff\xff')
bytearray(b'(\x90\x86y\xa2\x01\xfb\xff')
bytearray(b'(\x90\x86y\xa2\x01\xf3\xff')
bytearray(b'(\x90\x86y\xa2\x01\xe3\xff')
bytearray(b'(\x90\x86y\xa2\x01\xc3\xff')
bytearray(b'(\x90\x86y\xa2\x01\x83\xff')
bytearray(b'(\x90\x86y\xa2\x01\x03\xff')
bytearray(b'(\x90\x86y\xa2\x01\x03\xfe')
bytearray(b'(\x90\x86y\xa2\x01\x03\xfc')
bytearray(b'(\x90\x86y\xa2\x01\x03\xdc')
bytearray(b'(\x90\x86y\xa2\x01\x03\\')
When I try to read temperature using this values it returns ‘CRC error’.

What can be done? Is the problem with code, or the sensors are failed somehow?

Re: DS18B20 wrong serial code/adress/roms

Posted: Thu May 28, 2020 6:04 pm
by Roberthh
It may be a fake sensor. See also https://github.com/cpetrich/counterfeit_DS18B20

Re: DS18B20 wrong serial code/adress/roms

Posted: Thu May 28, 2020 6:17 pm
by kevinkk525

Re: DS18B20 wrong serial code/adress/roms

Posted: Sat May 30, 2020 8:46 am
by BigStupidBeast
kevinkk525 wrote:
Thu May 28, 2020 6:17 pm
viewtopic.php?f=2&t=8180&p=46521&hilit=ds18b20#p46528 maybe too many units on one bus?
one sensor wired in normal mode (not parasite). positive power connected to 3.3V. the first sensor work with out pull up resistor. But China so diffrent China... I try to use inner pull up mode (Pin.PULL_UP) but it didn't help.
Roberthh wrote:
Thu May 28, 2020 6:04 pm
It may be a fake sensor. See also https://github.com/cpetrich/counterfeit_DS18B20
My first thought it was.

Thanks. will go to store for new sensors

Re: DS18B20 wrong serial code/adress/roms

Posted: Fri Jun 05, 2020 11:45 pm
by SirN Check
Don't forget to also pick up some pull-up resistors!
Internal pull-up are much too weak.
At 3v3: 1k5, 1k8 or 2k2 will do the trick.
Especially when using long cables & multiple sensors!

Re: DS18B20 wrong serial code/adress/roms

Posted: Sun Jun 07, 2020 3:06 pm
by BigStupidBeast
Looks like i'm a fool)) Yes. One 4.7K pull up resistor and it's alive! IT'S ALIVE!! Aaaand whats'up doc? then we use internal PULL_UP mode we pull up signal only for ESP. BUT! DS18B20 is microchip too. And the wire for little DS18B20 is like giant radio aerial. Maybe in my first sensor this problem was solved on hard level.