Coder Social home page Coder Social logo

m8ttyb / ds18b20 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timofurrer/w1thermsensor

0.0 2.0 0.0 82 KB

This little pure python module provides a single class to get the temperature of a DS18B20 sensor

License: GNU General Public License v2.0

ds18b20's Introduction

DS18B20

This little pure python module provides a single class to get the temperature of a DS18B20 sensor
It can be easily used on are Rasperry Pi over the GPIO interface.


Author: Timo Furrer [email protected]
Version: 0.01.02

Setup

You just need a DS18B20 temperature sensor.
Some of them can be bought here: Adafruit: DS18B20
I've used a Raspberry Pi with an GPIO Breakout (Pi Cobbler)

Installation

From Source

python setup.py install

Note: maybe root privileges are required

From PIP

pip install ds18b20

Note: maybe root privileges are required

Usage

The usage is very simple and the interface clean..

Basic usage with one sensor (implicit)

from ds18b20 import DS18B20

sensor = DS18B20()
temperature_in_celsius = sensor.get_temperature()
temperature_in_fahrenheit = sensor.get_temperature(DS18B20.DEGREES_F)
temperature_in_all_units = sensor.get_temperatures([DS18B20.DEGREES_C, DS18B20.DEGREES_F, DS18B20.KELVIN])

The need kernel modules will be automatically loaded in the constructor of the DS18B20 class.
If something went wrong an exception is raised.

The first found sensor will be taken

Basic usage with one sensor (explicit)

The sensor with the ID 00000588806a will be taken.

from ds18b20 import DS18B20

sensor = DS18B20("00000588806a")
temperature_in_celsius = sensor.get_temperature()

Multiple sensors

With the get_available_sensors class-method you can get the ids of all available sensors.

from ds18b20 import DS18B20

sensors = []
for sensor_id in DS18B20.get_available_sensors():
    sensors.append(DS18B20(sensor_id))

for sensor in sensors:
    print("Sensor %s has temperature %.2f" % (sensor.get_id(), sensor.get_temperature()))

The first path of the above code can be replaced by the get_all_sensors method:

from ds18b20 import DS18B20

sensors = DS18B20.get_all_sensors()
...

Sample program

There is a little sample program in the tests directory. Just execute it and you will get the temperatures in Kelvin, Degrees Celsius and Degrees Fahrenheit.

  $ python example.py
  Kelvin: 295.275000
  Degress Celsius: 23.125000
  Degress Fahrenheit: 73.625000
  =====================================
  Kelvin: 296.025000
  Degress Celsius: 23.875000
  Degress Fahrenheit: 74.975000
  =====================================
  ...

ds18b20's People

Contributors

timofurrer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.