View on GitHub

GreenPonik_OneWire_DS18B20

Read DS18B20 OneWire through Python3 on raspberry pi

Quality Gate Status Maintainability Rating

Lines of Code Duplicated Lines (%)

Reliability Rating Security Rating Vulnerabilities

Upload Python Package

GreenPonik_OneWire_DS18B20.py Library for Raspberry pi


This is the sample code for read temperature with DS18B20 sensor on One Wire bus.

The script auto-detect the 1W file and parse it to find the temperature value.

Table of Contents

Installation

> git clone https://github.com/GreenPonik/GreenPonik_OneWire_DS18B20.git
cd GreenPonik_OneWire_DS18B20
pip3 install -r requirements.txt

or 

> pip3 install greenponik-onewire-ds18b20

from GreenPonik_OneWire_DS18B20 import read_temps

Methods

"""
Get temperatues in celcius and fahrenheit
"""
def read_temps():

Example

from time import sleep
from GreenPonik_OneWire_DS18B20 import read_temps

if __name__ == "__main__":
    try:
        while True:
            # read both celcius and fahrenheit temperatures
            temperatures = read_temps()
            print("celcius temp %.3f" % temperatures[0])
            print("fahrenheit temp %.3f" % temperatures[1])
            sleep(1)
    except Exception as e:
        print("Exception occured", e)

Credits

Write by Mickael Lehoux, from GreenPonik, 2019