Code Monkey home page Code Monkey logo

python-i2c-sht3x's Introduction

Python I2C Driver for Sensirion SHT3X

This repository contains the Python driver to communicate with a Sensirion sensor of the SHT3X family over I2C.

SHT3X picture

Click here to learn more about the Sensirion SHT3X sensor family.

Not all sensors of this driver family support all measurements. In case a measurement is not supported by all sensors, the products that support it are listed in the API description.

Supported sensor types

Sensor name I²C Addresses
SHT30A 0x44, 0x45
SHT30 0x44, 0x45
SHT31A 0x44, 0x45
SHT31 0x44, 0x45
SHT33 0x44, 0x45
SHT35A 0x44, 0x45
SHT35 0x44, 0x45
SHT85 0x44

The following instructions and examples use a SHT30.

Connect the sensor

You can connect your sensor over a SEK-SensorBridge. For special setups you find the sensor pinout in the section below.

Sensor pinout

sensor wiring picture

Pin Cable Color Name Description Comments
1 green SDA I2C: Serial data input / output
2 black GND Ground
3 yellow SCL I2C: Serial clock input
4 red VDD Supply Voltage 2.15V to 5.5V

Documentation & Quickstart

See the documentation page for an API description and a quickstart example.

Contributing

We develop and test this driver using our company internal tools (version control, continuous integration, code review etc.) and automatically synchronize the master branch with GitHub. But this doesn't mean that we don't respond to issues or don't accept pull requests on GitHub. In fact, you're very welcome to open issues or create pull requests :-)

Check coding style

The coding style can be checked with flake8:

pip install -e .[test]  # Install requirements
flake8                  # Run style check

In addition, we check the formatting of files with editorconfig-checker:

pip install editorconfig-checker==2.0.3   # Install requirements
editorconfig-checker                      # Run check

License

See LICENSE.

python-i2c-sht3x's People

Contributors

leoniefierz avatar sdmueller avatar

Watchers

 avatar  avatar  avatar

python-i2c-sht3x's Issues

measure_single_shot() doesn't work

When running this with a SHT30-D sensor connected via i2c to a raspberry pi, I can't use the method measure_single_shot() without getting an exception.
start_periodic_measurement() and blocking_read_measurement() methods work.

Here is the error I get:

Exception has occurred: TypeError
argument must be an int, or have a fileno() method.
  File "/home/admin/vext_python/input/humiditysensor.py", line 29, in readTempHumidity
    (a_temperature, a_humidity) = self.sensor.measure_single_shot(
  File "/home/admin/vext_python/main.py", line 25, in <module>
    tempHumiditySensorHelper.readTempHumidity()
TypeError: argument must be an int, or have a fileno() method.

The relevant code section looks like this:

def readTempHumidity(self):
    (a_temperature, a_humidity) = self.sensor.measure_single_shot(
        Repeatability.MEDIUM, False
    )
    print(f"a_temperature: {a_temperature}; " f"a_humidity: {a_humidity}; ")

Line 29 of the error corresponds to (a_temperature, a_humidity) = ....

Doing the following yields the same result:

def readTempHumidity(self):
        # try:
        (raw_temp, raw_humi) = self.sensor.sht3x.measure_single_shot_high_repeatability()
        print(f"a_temperature: {SignalTemperature(raw_temp)}; " f"a_humidity: {SignalHumidity(raw_humi)}; ")

Any help would be gratly appreciated, I've been trying to debug this for 2 hours :D

EDIT: here is the whole file:

import time
from sensirion_i2c_driver import LinuxI2cTransceiver, I2cConnection, CrcCalculator
from sensirion_driver_adapters.i2c_adapter.i2c_channel import I2cChannel
from sensirion_i2c_sht3x.device import Sht3xDevice
from sensirion_i2c_sht3x.commands import Repeatability

from abstract.thingsboard import client


class TempHumiditySensorHelper:
    i2cPort = "/dev/i2c-1"

    def init(self):
        with LinuxI2cTransceiver(self.i2cPort) as i2c_transceiver:
            channel = I2cChannel(
                I2cConnection(i2c_transceiver),
                slave_address=0x44,
                crc=CrcCalculator(8, 0x31, 0xFF, 0x0),
            )
            self.sensor = Sht3xDevice(channel)
            self.sensor.stop_measurement()
            time.sleep(0.001)
            self.sensor.soft_reset()
            time.sleep(0.1)
            status_register = self.sensor.read_status_register()
            print(f"status_register: {status_register}; ")

    def readTempHumidity(self):
        (a_temperature, a_humidity) = self.sensor.measure_single_shot(
        Repeatability.MEDIUM, False
        )
        print(f"a_temperature: {a_temperature}; " f"a_humidity: {a_humidity}; ")

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.