Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Sensor #34

Open
WirthmU opened this issue May 21, 2020 · 0 comments
Open

Custom Sensor #34

WirthmU opened this issue May 21, 2020 · 0 comments

Comments

@WirthmU
Copy link

WirthmU commented May 21, 2020

I am not sure if you still are using the AirPi?!

I try to add a new sensor based on your template (SHT31 temperature and humidity sensor) with no luck so far.

Could you please give some advice?

`#!/usr/bin/python

import sensor
import time
import smbus

class SHT31(sensor.Sensor):
requiredData = []
optionalData = []

def __init__(self,data):
    """
    Initialisation.
    Any initialisation code goes here.
    """
    self.readingtype = "temperature"
    self.sensorname = "SHT31"
    self.valname = "Temperature"
    self.valunit = "Degrees Celsius"
    self.valsymbol = "C"
    self.description = "SHT31 Sensor for Temperature and Humidity."
    return

def getval(self):
    try:
        bus = smbus.SMBus(1)
        bus.write_i2c_block_data(0x44, 0x2C, [0x06])
        time.sleep(0.5)
        data = bus.read_i2c_block_data(0x44, 0x00, 6)
        ctemp = data[0] * 256 + data[1]
        temp = -45 + (175 * ctemp / 65535.0)
    except TypeError as terr:
        pass
    return temp`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant