Code Monkey home page Code Monkey logo

w1thermsensor's Introduction

W1ThermSensor

![Gitter](https://badges.gitter.im/Join Chat.svg)

Get the temperature from your w1 therm sensor in a single line of code!
It's designed to be used with the Rasperry Pi hardware but also works on a Beagle Bone and others.


Build Status codecov.io Code Climate Code Health PyPI version

New: use w1thermsensor as a CLI tool! - Since version 0.3.0

Supported devices

The following w1 therm sensor devices are supported:

  • DS18S20
  • DS1822
  • DS18B20
  • DS28EA00
  • DS1825/MAX31850K

Setup

You just need a w1 therm sensor.
Some of them can be bought here: Adafruit: DS18B20
I've used a Raspberry Pi with an GPIO Breakout (Pi Cobbler). Other hardware like the Beagle Bone are supported, too.

Installation

From PIP

This possibility is supported on all distribution:

pip install w1thermsensor

Note: maybe root privileges are required

On Raspbian using apt-get

If you are using the w1thermsensor module on a Rasperry Pi running raspbian you can install it from the offical repository:

sudo apt-get install python-w1thermsensor

Or if you are using python 3:

sudo apt-get install python3-w1thermsensor

Create debian packages

debuild -us -uc

Usage as python package

The usage is very simple and the interface clean.. All examples are with the DS18B20 sensor - It works the same way for the other supported devices.

Basic usage with one sensor (implicit)

from w1thermsensor import W1ThermSensor

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

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

The first found sensor will be taken

Basic usage with one sensor (explicit)

The DS18B20 sensor with the ID 00000588806a will be taken.

from w1thermsensor import W1ThermSensor

sensor = W1ThermSensor(W1ThermSensor.THERM_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 w1thermsensor import W1ThermSensor

for sensor in W1ThermSensor.get_available_sensors():
    print("Sensor %s has temperature %.2f" % (sensor.id, sensor.get_temperature()))

Only sensors of a specific therm sensor type:

from w1thermsensor import W1ThermSensor

for sensor in W1ThermSensor.get_available_sensors([W1ThermSensor.THERM_SENSOR_DS18B20]):
    print("Sensor %s has temperature %.2f" % (sensor.id, sensor.get_temperature()))

Usage as CLI tool

The w1thermsensor module can be used as CLI tool since version 0.3.0.
Please note that the CLI tool will only get installed with the Raspbian Python 3 package (sudo apt-get install python3-w1thermsensor)

List sensors

List all available sensors:

$ w1thermsensor ls
$ w1thermsensor ls --json  # show results in JSON format

List only sensors of a specific type:

$ w1thermsensor ls --type DS1822
$ w1thermsensor ls --type DS1822 --type MAX31850K  # specify multiple sensor types
$ w1thermsensor ls --type DS1822 --json  # show results in JSON format

Show temperatures

Show temperature of all available sensors: (Same synopsis as ls)

$ w1thermsensor all --type DS1822
$ w1thermsensor all --type DS1822 --type MAX31850K  # specify multiple sensor types
$ w1thermsensor all --type DS1822 --json  # show results in JSON format

Show temperature of a single sensor:

$ w1thermsensor get 1  # 1 is the id obtained by the ls command
$ w1thermsensor get --hwid 00000588806a --type DS18B20
$ w1thermsensor get 1  # show results in JSON format

Contribution

I'm happy about all types of contributions to this project! ๐Ÿป

w1thermsensor's People

Contributors

timofurrer avatar jamesmyatt avatar rcpeters avatar claws avatar payne92 avatar rgbkrk avatar xecdesign avatar senden9 avatar gitter-badger avatar ianmtaylor1 avatar

Watchers

Msayuki Ariki avatar James Cloos 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.