DS18x20 -> ds.convert_temp() Question

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Armen
Posts: 8
Joined: Tue Mar 24, 2020 3:11 pm

DS18x20 -> ds.convert_temp() Question

Post by Armen » Mon May 04, 2020 5:58 pm

Hello PyLovers

Can anyone describe me about

ds.convert_temp() module ?

Code: Select all

# https://github.com/micropython/micropython/blob/master/drivers/onewire/ds18x20.py

_CONVERT = const(0x44)
def convert_temp(self):
        self.ow.reset(True)
        self.ow.writebyte(self.ow.SKIP_ROM)
        self.ow.writebyte(_CONVERT)
What happen if I don't use it in this sample?

Code: Select all

import time, ds18x20
ds = ds18x20.DS18X20(ow)
roms = ds.scan()
ds.convert_temp()
time.sleep_ms(750)
for rom in roms:
    print(ds.read_temp(rom))

# http://docs.micropython.org/en/latest/esp8266/quickref.html
Thanks
Armen

fe2o3
Posts: 10
Joined: Fri Oct 23, 2015 4:47 pm

Re: DS18x20 -> ds.convert_temp() Question

Post by fe2o3 » Sat May 09, 2020 8:43 am

That's fine. convert_temp() is for when there is only ONE 1-wire temperature device
on the bus. Notice the SKIP_ROM command? It doesn't address any particular device.
Using it when there are multiple devices will cause some confusion.

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

Re: DS18x20 -> ds.convert_temp() Question

Post by kevinkk525 » Sat May 09, 2020 4:17 pm

AFAIK convert_temp() instructs all ds18 on the bus to start the temperature conversion and is need before attempting to read from any sensor. But you don't need to call it before reading every single sensor, just before you start to read all sensors.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply