DS18B20 wrong serial code/adress/roms

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
BigStupidBeast
Posts: 9
Joined: Thu May 28, 2020 5:40 pm
Location: sorry for my English)

DS18B20 wrong serial code/adress/roms

Post by BigStupidBeast » Thu May 28, 2020 5:49 pm

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?

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

Re: DS18B20 wrong serial code/adress/roms

Post by Roberthh » Thu May 28, 2020 6:04 pm

It may be a fake sensor. See also https://github.com/cpetrich/counterfeit_DS18B20

kevinkk525
Posts: 925
Joined: Sat Feb 03, 2018 7:02 pm

Re: DS18B20 wrong serial code/adress/roms

Post by kevinkk525 » Thu May 28, 2020 6:17 pm

Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

BigStupidBeast
Posts: 9
Joined: Thu May 28, 2020 5:40 pm
Location: sorry for my English)

Re: DS18B20 wrong serial code/adress/roms

Post by BigStupidBeast » Sat May 30, 2020 8:46 am

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

SirN Check
Posts: 10
Joined: Fri Dec 15, 2017 11:11 am

Re: DS18B20 wrong serial code/adress/roms

Post by SirN Check » Fri Jun 05, 2020 11:45 pm

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!
Last edited by SirN Check on Tue Jun 09, 2020 10:22 am, edited 1 time in total.

BigStupidBeast
Posts: 9
Joined: Thu May 28, 2020 5:40 pm
Location: sorry for my English)

Re: DS18B20 wrong serial code/adress/roms

Post by BigStupidBeast » Sun Jun 07, 2020 3:06 pm

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.

Post Reply