Modified Class to allow DS18B20 reading with different resolutions



  • I added write_scratch and read_temp to class.
    read_temp uses the bit resolution values of 9 - 12 and incorporates the correct delay for data acquisition.

    How to use:

    from machine import Pin
    from onewire import DS18X20
    from onewire import OneWire
    
    ow = OneWire(Pin('P8'))
    temp = DS18X20(ow)
    while True:
        print(temp.read_temp(9))
        print(temp.read_temp(10))
        print(temp.read_temp(11))
        print(temp.read_temp(12))
        print("----------------")
    

    Output:

    23.5
    23.25
    23.125
    22.9375
    ----------------
    

    The temperature was dropping hence the last reading is lower.

    onewire.py


Log in to reply
 

Pycom on Twitter