Subversion Repositories yaws

Rev

Rev 15 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 ron 1
#!/usr/bin/python3
3 ron 2
# -*- coding: utf-8 -*-
3
#
4
#  sensors/tph.py
5
#
6
#  Copyright 2020 Ron Wellsted <ron@wellsted.org.uk>
7
#
8
#  This program is free software; you can redistribute it and/or modify
9
#  it under the terms of the GNU General Public License as published by
10
#  the Free Software Foundation; either version 2 of the License, or
11
#  (at your option) any later version.
12
#
13
#  This program is distributed in the hope that it will be useful,
14
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
#  GNU General Public License for more details.
17
#
18
#  You should have received a copy of the GNU General Public License
19
#  along with this program; if not, write to the Free Software
20
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
#  MA 02110-1301, USA.
22
#
23
#
24
import smbus2
25
import bme280
15 ron 26
from sensors import i2cbus, bme280_address
16 ron 27
import w1thermsensor
3 ron 28
 
15 ron 29
def __init__():
30
    if bme280_address is not None:
31
        bus = smbus2.SMBus(i2cbus)
32
        calibration_params = bme280.load_calibration_params(bus, bme280_address)
33
        data = bme280.sample(bus, bme280_address, calibration_params)
3 ron 34
 
6 ron 35
def read_tph():
9 ron 36
    if bme280_address is not None:
37
        data = bme280.sample(bus, bme280_address, calibration_params)
38
        air_temp = data.temperature
39
        pressure  = data.pressure/1000.0 # convert to Bar
40
        humidity  = data.humidity
41
    else:
42
        air_temp = None
43
        pressure = None
44
        humidity = None
6 ron 45
    return (air_temp, pressure, humidity)
46