![Gitter](https://badges.gitter.im/Join Chat.svg)
This little pure python module provides a single class to get the temperature of a w1 therm sensor
It can be easily used on are Rasperry Pi, Beagle Bone etc. over the GPIO interface.
Author: Timo Furrer [email protected]
Version: 0.2.2
License: MIT
The following w1 therm sensor devices are supported:
- DS18S20
- DS1822
- DS18B20
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.
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
For python 2:
python setup.py --command-packages=stdeb.command bdist_deb
For python 3:
python3 setup.py --command-packages=stdeb.command bdist_deb
git clone https://github.com/timofurrer/w1thermsensor.git && cd w1thermsensor
python setup.py install
Note: maybe root privileges are required
This possibility is supported on all distribution:
pip install w1thermsensor
Note: maybe root privileges are required
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.
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
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()
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()))
Feel free to contribute!
If you have made any changes and you want to make a pull request
:
- You are a pro to contribute to this repo!
- Please make the tests pass by
make tests
- Now you can make the
pull request
- Catch my thank!