Code Monkey home page Code Monkey logo

temp_sensor's Introduction

sht21_python

Python library for reading data over i2c for a Sensirion SHT21 (tested on Raspberry Pi).

This is a python port of the c version found here: http://www.emsystech.de/raspi-sht21/

I have only tried it on my first generation Raspberry Pi, but there have been reports of this working on newer Raspberry Pis. This code should also work with all sensors in the SHT2x series; there have been report of it working with a SHT25.

Requirements

  • i2c must be enabled
  • you must run the script as root

To enable i2c check http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

Depending on your raspberry pi model, you may need to use /dev/i2c-0 or /dev/i2c-1

Usage

import sht21
with sht21.SHT21(0) as sht21:
    print "Temperature: %s"%sht21.read_temperature()
    print "Humidity: %s"%sht21.read_humidity()

Note that the 0 represents the i2c bus number (as discussed), to use /dev/i2c-1 on a newer Raspberry Pi you need to update the device number:

If you are not root, this is likely to throw IOErrors. Also the calls to read_xxx() may also return None if the checksum fails

sht31_python

Thanks to the kind contribution of an initial version by @nadanks7 and some testing by @jimbowarrior there is now also a basic implementation for the sht31 sensor. More work is required here to support all features of the sensor, but the initial framework is in place.

Usage is similar, but as reading temerature and humidity is now a single operation there is single call to do that.

Note that in this example we are using /dev/i2c-1.

import sht31
with sht31.SHT31(1) as sht31:
    print sht31.check_heater_status()
    sht31.turn_heater_on()
    print sht31.check_heater_status()
    sht31.turn_heater_off()
    print sht31.check_heater_status()
    temperature, humidity = sht31.get_temp_and_humidity()
    print "Temperature: %s" % temperature
    print "Humidity: %s" % humidity

temp_sensor's People

Contributors

jaques avatar king-dopey avatar kscheff avatar mmilata avatar seppestas avatar

Watchers

 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.