示例#1
0
    def __init__(self):
        self.i2c = board.I2C()

        self.mcp_1 = adafruit_mcp9808.MCP9808(self.i2c, 0x19)
        self.mcp_2 = adafruit_mcp9808.MCP9808(self.i2c, 0x18)
        self.temperature = [self.mcp_1.temperature, self.mcp_2.temperature]

        while not self.i2c.try_lock():
            pass

        self.adress = [
            hex(device_address) for device_address in self.i2c.scan()
        ]
def getData(spi, i2c):
    moisture_level = analogInput(0, spi)
    moisture_level = round((moisture_level / 1023 * 100), 1)
    moisture_string = ("Moisture: " + str(moisture_level) + "%")

    t = adafruit_mcp9808.MCP9808(i2c)
    temp = round(t.temperature, 1)
    temp_string = "Temp: " + str(temp) + chr(223) + "C"

    humidity, AdaFruitTemp = Adafruit_DHT.read_retry(11, 4)
    humidity_string = "Humidity: " + str(round(humidity, 1)) + "% RH"

    LCD_line_1 = moisture_string + "\n" + temp_string
    LCD_line_2 = humidity_string

    # 	print(LCD_line_1 + "\n" + LCD_line_2)
    global LCD_pages
    LCD_pages = [LCD_line_1, LCD_line_2]

    time_stamp = time.strftime("%Y-%m-%d, %H:%M:%S", time.localtime())
    curr_file = open('moisture_level.txt', 'a')
    curr_file.write(time_stamp + "\t" + str(moisture_level) + "\t" +
                    str(temp) + "\t" + str(humidity) + '\n')
    curr_file.close()

    return moisture_level, LCD_pages
示例#3
0
文件: icarus.py 项目: rdt249/icarus
def init_therm():
    i2c = board.I2C()  # init i2c bus
    try:
        therm = adafruit_mcp9808.MCP9808(i2c)  # init thermometer
        return therm
    except:
        print("icarus.init_therm() failed")
        return None
示例#4
0
 def check_for_temperature():
     temperature_sensor = busio.I2C(board.SCL, board.SDA)
     i2c_mutex.acquire()
     try:
         temperature_data = adafruit_mcp9808.MCP9808(temperature_sensor)
     finally:
         i2c_mutex.release()
     print("Current temperature = " + str(temperature_data.temperature) +
           "deg C")
     time.sleep(0.1)
示例#5
0
 def index(self):
     mcp = adafruit_mcp9808.MCP9808(i2c_bus)
     bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c_bus, 0x77)
     return {
         "temperature": mcp.temperature,
         "pressure": bme280.pressure,
         "humidity": bme280.humidity,
         "wind": {
             "speed": 1.06,
             "deg": 17.0003
         },
         "dt": int(time.time()),
         "delta": bme280.temperature - mcp.temperature
     }
示例#6
0
    def read(self, SIO):
        if not self.mcp9808:
            i2c = busio.I2C(board.SCL, board.SDA)
            self.mcp9808 = adafruit_mcp9808.MCP9808(i2c)
            #self.mcp9808.resolution = 3
        try:
            T = self.mcp9808.temperature
        except:
            traceback.print_exc()
            self.mcp9808 = None
            return

        self.t = time.time()
        print("MCP9808 at t =", self.t, ": %.3fC\n" % T)
        SIO.log_readout(self.T_id, T, self.t)
示例#7
0
    def __init__(self, config):
        self.i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
 
        # To initialise using the default address:
        if config.TPsensor == 'MCP9808':
            import adafruit_mcp9808
            self.sensor = adafruit_mcp9808.MCP9808(self.i2c)
            try:
                self.temperature = self.sensor.temperature
            except:
                print("\n T/RH/P SENSOR NOT CONNECTED ")
                self.temperature = 0
            self.pressure = 0
            self.humidity = 0
            self.dewpoint = 0
            self.altitude = 0
            self.sealevel = getBaromPress(config)
            
        elif config.TPsensor == 'BME280':
            import adafruit_bme280
            self.sensor = adafruit_bme280.Adafruit_BME280_I2C(self.i2c)
            try:
                self.sensor.sea_level_pressure = getBaromPress(config)
                self.sensor.mode = adafruit_bme280.MODE_NORMAL
                self.sensor.standby_period = adafruit_bme280.STANDBY_TC_500
                self.sensor.iir_filter = adafruit_bme280.IIR_FILTER_X16
                self.sensor.overscan_pressure = adafruit_bme280.OVERSCAN_X16
                self.sensor.overscan_humidity = adafruit_bme280.OVERSCAN_X1
                self.sensor.overscan_temperature = adafruit_bme280.OVERSCAN_X2
                # The sensor will need a moment to gather initial readings
                time.sleep(1)
                self.temperature = self.sensor.temperature
                self.pressure = self.sensor.pressure
                self.humidity = self.sensor.relative_humidity
                self.altitude = self.sensor.altitude
                self.sealevel = self.sensor.sea_level_pressure
                self.dewpoint = dewPointRH(self.temperature, self.humidity, Pws(self.temperature, self.humidity))
            except:
                print("\n T/RH/P SENSOR NOT CONNECTED ")
                self.temperature = 0
                self.pressure = 0
                self.humidity = 0
                self.dewpoint = 0
                self.altitude = 0
                self.sealevel = getBaromPress(config)
示例#8
0
def Read_data():
    ts = time.strftime("%H%M%S")
    file.write(str(ts) + "\t")

    # Fusion / Gyroscope data
    x, y, z = imu.getFusionData()
    x = round(math.degrees(x),2)
    y = round(math.degrees(y),2)
    z  = round(math.degrees(z),2)
    file.write(str(x) + "\t"+ str(y) + "\t" + str(z)+ "\t")

    #resetfusion
    imu.getGyro

    # Acceleration data, accely is spin, accelz is acceleration,
    accelx, accely, accelz = imu.getAccel()
    accelx = round(accelx,2)
    accely = round(accely,2)
    accelz = round(accelz,2)
    file.write(str(accelx) + "\t" + str(accely) + "\t" + str(accelz) + "\t" )

    # Compass data
    compx, compy, compz = imu.getIMUData()['compass']
    compx = round(compx,2)
    compy = round(compy,2)
    compz = round(compz,2)
    file.write(str(compx) + "\t" + str(compy) + "\t" + str(compz) + "\t")
    #time.sleep(poll_interval*1.0/1000.0)

    
    i2c = busio.I2C(board.SCL, board.SDA)
    bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
    bme680.sea_level_pressure = 1018
    temp = bme680.temperature
    humidity = bme680.humidity
    altitude = bme680.altitude
    pressure = bme680.pressure
    gas = bme680.gas 
    file.write(str(temp) + "\t" + str(humidity) + "\t" + str(altitude) + "\t" + str(pressure) + '\t' + str(gas) + "\t")

    mcp = adafruit_mcp9808.MCP9808(i2c)
    ptemp = mcp.temperature #deg celsius
    file.write(str(ptemp) + "\t")
示例#9
0
 def __init__(self, _parent):
     self.Thread = None
     self.parent = _parent
     self.name = "MCPBMPCPU"
     self.format = {
         "Type": "SR",
         "Sensor": self.name,
         "Time": "",
         "Temp-precise": "",
         "Temperature-rough": "",
         "Pressure": "",
         "Temp-Cpu": ""
     }
     self.i2c_bus = busio.I2C(board.SCL, board.SDA)
     self.bmp = adafruit_bmp3xx.BMP3XX_I2C(self.i2c_bus)
     self.mcp = adafruit_mcp9808.MCP9808(self.i2c_bus)
     self.bmp.pressure_oversampling = 8
     self.bmp.temperature_oversampling = 2
     self.readfreq = 1
     self.threadstart()
示例#10
0
import sys

import board
import busio
import adafruit_mcp9808

import time

i2c = busio.I2C(board.SCL, board.SDA)

mcp_water = adafruit_mcp9808.MCP9808(i2c, address=0x18)
mcp_porch = adafruit_mcp9808.MCP9808(i2c, address=0x19)
mcp_green = adafruit_mcp9808.MCP9808(i2c, address=0x1a)
mcp_inside1 = adafruit_mcp9808.MCP9808(i2c, address=0x1b)
mcp_inside2 = adafruit_mcp9808.MCP9808(i2c, address=0x1c)


def write_to_file(timestamp, temp_data, filehandle):
    temp_format = ("{:0.2f}", )
    time_format = "%Y-%m-%dT%H:%M:%S"
    temp_format_string = ",".join(temp_format * len(temp_data))
    data = time.strftime(
        time_format,
        timestamp) + "," + temp_format_string.format(*temp_data) + "\n"
    filehandle.write(data)
    filehandle.flush()


def main(filename):
    print("{:^52s}".format("Measured Temperatures"))
    print("{:^14s} {:^14s} {:^14s} {:^14s} {:^14s}".format(
示例#11
0
    def __init__(self, master):
        self.master = master
        #setup I2C Bus
        self.i2c_bus = busio.I2C(board.SCL, board.SDA)

        #create the temperature sensor using I2C Buss
        self.mcp = adafruit_mcp9808.MCP9808(self.i2c_bus)

        # Create the ADC object using the I2C bus
        self.ads = ADS.ADS1015(self.i2c_bus)

        # setup serial bus
        self.uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=3000)

        # Create a GPS module instance.
        self.gps = adafruit_gps.GPS(self.uart, debug=False)

        # Turn on the basic GGA and RMC info (what you typically want)
        self.gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')

        # Set GPS update rate
        self.gps.send_command(b'PMTK220,1000')

        #sets value for ADC Gain
        self.GAIN = 1

        #correction factors for voltage dividers
        self.adc0correction = 92.54378
        self.adc1correction = 28.45011379
        self.adc2correction = 1
        self.adc3correction = 1

        #conversion factor for knots to mph
        self.knotsconversion = 1.15078

        #initialize last time
        self.last_print = time.monotonic()

        #initialize amphour
        self.amphour = 100

        #initialize shunt resistance
        self.shuntresistance = .0075

        #opens the connection to the DB
        try:
            self.conn = psycopg2.connect(
                dbname='dd1bpvtvs1alq3',
                user='******',
                password=
                '******',
                host='ec2-54-227-246-152.compute-1.amazonaws.com',
                port='5432')
            print("connected")
            self.cur = self.conn.cursor()
        except:
            print("I am unable to connect to the database.")

        #open the file and retrieve the runnig amp our count

        self.lastamptime = None
示例#12
0
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
CircuitPython U2IF I2C QT2040 Trinkey Example

Reads the temperature every two seconds from an MCP9808 I2C temperature sensor
connected via STEMMA QT.
"""
import time
import board
import adafruit_mcp9808

i2c = board.I2C()  # uses board.SCL and board.SDA
mcp9808 = adafruit_mcp9808.MCP9808(i2c)

while True:
    temperature_celsius = mcp9808.temperature
    temperature_fahrenheit = temperature_celsius * 9 / 5 + 32
    print("Temperature: {:.2f} C {:.2f} F ".format(temperature_celsius, temperature_fahrenheit))
    time.sleep(2)
示例#13
0
import board
import busio
import adafruit_mcp9808
import adafruit_bmp280
import time
import sys




i2c = busio.I2C(board.SCL, board.SDA)
#mcp = adafruit_mcp9808.MCP9808(i2c)
try:
    bmp280 = adafruit_mcp9808.MCP9808(i2c)
except Exception as e:
    sys.stderr.write("Can't read sensor. Error={}".format(e))
    sys.exit(1)

#bmp280.mode = adafruit_bmp280.MODE_NORMAL


while True:
    try:
        temp = bmp280.temperature
        pressure = 0
        print("Temp#1={} Pressure={}".format(temp, pressure))
    except:
        pass
    time.sleep(1)
示例#14
0
appid = ''  # Get APP ID from https://openweathermap.org/api

options = RGBMatrixOptions()
options.rows = 32
options.chain_length = 2  # 2 32x32 Matrices
options.parallel = 1
options.hardware_mapping = 'adafruit-hat'
matrix = RGBMatrix(options=options)

font_numbers = graphics.Font()
font_numbers.LoadFont("fonts/6x9.bdf")

font_text = graphics.Font()
font_text.LoadFont("fonts/5x7.bdf")

t = adafruit_mcp9808.MCP9808(busio.I2C(SCL, SDA))
data = {}
pos = 0  # For scrolling the text

seconds_tick = False
textcolor = graphics.Color(200, 200, 200)


def display_data():

    matrix.Clear()

    global data
    global pos
    global seconds_tick
    global textcolor
示例#15
0
    def __init__(self, i2c):
        """ creates the object 		    
		"""
        super().__init__()

        self._mcp9808 = adafruit_mcp9808.MCP9808(i2c, address=0x18)
示例#16
0
    def setup(self, log_type):
        super().setup(log_type)

        i2c = busio.I2C(board.SCL, board.SDA)
        self.bridge = adafruit_mcp9808.MCP9808(i2c)
示例#17
0
 def read_metric(self):
     from board import SCL, SDA
     with busio.I2C(SCL, SDA) as i2c:
         t = adafruit_mcp9808.MCP9808(i2c)
         return {'tempC': t.temperature}
示例#18
0
import adafruit_mcp9808
import board

i2c = board.I2C()

# Lock the I2C device before we try to scan
while not i2c.try_lock():
    pass
# Print the addresses found once
print("I2C addresses found:",
      [hex(device_address) for device_address in i2c.scan()])

# Unlock I2C now that we're done scanning.
i2c.unlock()

# Create library object on our I2C port
sensor = adafruit_mcp9808.MCP9808(i2c)
示例#19
0
import time
import board
import busio
import adafruit_mcp9808

# This example shows how to get the temperature from a MCP9808 board
i2c_bus = busio.I2C(board.SCL, board.SDA)
mcp = adafruit_mcp9808.MCP9808(i2c_bus)

while True:
    tempC = mcp.temperature
    tempF = tempC * 9 / 5 + 32
    print('Temperature: {} C {} F '.format(tempC, tempF))
    time.sleep(2)
示例#20
0
    def __init__(self, config):
        self.sea_level_pressure = getBaromPress(config)
        self.i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)

        # To initialise using the default address:
        if config.TPsensor == 'MCP9808':
            import adafruit_mcp9808
            self.sensor = adafruit_mcp9808.MCP9808(self.i2c)
            try:
                self.temperature = self.sensor.temperature
                self.pressure = 0
                self.humidity = 1
                self.dewpoint = 0
                self.altitude = 0
                self.success = True
            except:
                self.failSafe()

        elif config.TPsensor == 'BME280':
            import adafruit_bme280
            self.sensor = adafruit_bme280.Adafruit_BME280_I2C(self.i2c)
            try:
                self.sensor.mode = adafruit_bme280.MODE_NORMAL
                self.sensor.standby_period = adafruit_bme280.STANDBY_TC_500
                self.sensor.iir_filter = adafruit_bme280.IIR_FILTER_X16
                self.sensor.overscan_pressure = adafruit_bme280.OVERSCAN_X16
                self.sensor.overscan_humidity = adafruit_bme280.OVERSCAN_X1
                self.sensor.overscan_temperature = adafruit_bme280.OVERSCAN_X2
                # The sensor will need a moment to gather initial readings
                time.sleep(1)
                self.pressure = self.sensor.pressure
                self.temperature = self.sensor.temperature
                self.pressure = self.sensor.pressure
                self.humidity = self.sensor.relative_humidity
                self.altitude = self.sensor.altitude
                self.success = True
            except:
                self.failSafe()

        elif config.TPsensor == 'SCD30':
            import adafruit_scd30
            try:
                self.sensor = adafruit_scd30.SCD30(self.i2c)
                self.pressure = self.sea_level_pressure
                #print(" Temperature offset:", self.sensor.temperature_offset)
                #print(" Measurement interval:", self.sensor.measurement_interval)
                #print(" Self-calibration enabled:", self.sensor.self_calibration_enabled)
                #print(" Ambient Pressure:", self.sensor.ambient_pressure)
                #print(" Altitude:", self.sensor.altitude, "meters above sea level")
                #print(" Forced recalibration reference:", self.sensor.forced_recalibration_reference)
                while True:
                    if self.sensor.data_available:
                        self.temperature = self.sensor.temperature
                        self.pressure = self.sensor.ambient_pressure
                        self.humidity = self.sensor.relative_humidity
                        self.altitude = self.sensor.altitude
                        self.CO2 = self.sensor.CO2
                        break
                    time.sleep(0.5)
                self.success = True
            except:
                self.failSafe()

        elif config.TPsensor == 'BME180':
            import Adafruit_BMP.BMP085 as BMP085
            import RPi.GPIO as GPIO
            try:
                sensor = BMP085.BMP085()
                self.temperature = sensor.read_temperature()
                self.pressure = sensor.read_pressure() / 100
                self.altitude = sensor.read_altitude()
                self.humidity = 1
                self.success = True
            except:
                self.failSafe()

        self.sealevel = self.sea_level_pressure
        self.dewpoint = dewPointRH(self.temperature, self.humidity,
                                   Pws(self.temperature))
        self.absHum = absHumidity(self.temperature, self.humidity,
                                  Pws(self.temperature))
示例#21
0
def temp_round(temp: float, res: int = TEMP_RES):
    return round(temp, res)


def humd_round(humd: float, res: int = HUMD_RES):
    return round(humd, res)


# --- I2C Sensors Initialize ---
# init I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# sensor addresses
# Temperature - MCP9808 (top/bottom, left/right interior array position)
temp_TL_array = Sensor(adafruit_mcp9808.MCP9808(i2c, address=0x18),
                       get_i2c_temp, None)  # pos1, left-upper rail
temp_BL_array = Sensor(adafruit_mcp9808.MCP9808(i2c, address=0x19),
                       get_i2c_temp, None)  # pos2, left-lower rail
temp_TR_array = Sensor(adafruit_mcp9808.MCP9808(i2c, address=0x1A),
                       get_i2c_temp, None)  # pos3, right-upper rail
temp_BR_array = Sensor(adafruit_mcp9808.MCP9808(i2c, address=0x1B),
                       get_i2c_temp, None)  # pos4, right-lower rail
temp_peltier = Sensor(adafruit_mcp9808.MCP9808(i2c, address=0x1C),
                      get_i2c_temp, None)  # pos5, peltier heat sink
# Humidity & Temp - SHT30-D Weatherproof
temp_humd_indoor = Sensor(adafruit_sht31d.SHT31D(i2c), get_i2c_temp,
                          get_i2c_humd)  # pos7, inside gc
# Humidity & Temp - HTS221 Outdoor
temp_humd_outdoor = Sensor(adafruit_hts221.HTS221(i2c), get_i2c_temp,
                           get_i2c_humd)  # pos8, outside gc
示例#22
0
def runAcq():
    config = Configuration()

    file = str(os.path.splitext(config.CSVfile)[0]+ "-Lite_" +\
                    str(datetime.now().strftime('%Y%m%d-%H%M%S'))+".csv")
    i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)

    print("Tsensor:", config.TPsensor)
    print("Gassensor:", config.Gassensor)

    if config.TPsensor == 'BME280':
        TSens = adafruit_bme280.Adafruit_BME280_I2C(i2c)

    elif config.TPsensor == 'MCP9808':
        TSens = adafruit_mcp9808.MCP9808(i2c)
        TSens.pressure = 0
        TSens.relative_humidity = 0
        # To initialise using a specified address:
        # Necessary when, for example, connecting A0 to VDD to make address=0x19
        # TSens = adafruit_mcp9808.MCP9808(i2c_bus, address=0x19)

    elif config.TPsensor == 'SCD30':
        TSens = adafruit_scd30.Adafruit_SGP30(self.i2c)

    if config.Gassensor == 'SGP30':
        # Create library object on our I2C port
        GSens = adafruit_sgp30.Adafruit_SGP30(i2c)
        print("SGP30 serial #", [hex(i) for i in GSens.serial])
        GSens.iaq_init()
        GSens.set_iaq_baseline(config.eCO2_baseline, config.TVOC_baseline)
    elif config.Gassensor == 'SCD30':
        pass
    else:
        print("Gas Sensor not found. Exiting")
        return

    elapsed_sec = 0

    while True:
        if config.TPsensor == 'SCD30':
            data = TSens.data_available
        else:
            data = True

        if data:
            temperature = TSens.temperature
            if config.TPsensor == 'SCD30':
                pressure = TSens.ambient_pressure
            else:
                pressure = TSens.pressure
            humidity = TSens.relative_humidity
            pws = Pws(temperature)
            absHum = absHumidity(TSens.temperature, TSens.relative_humidity,
                                 pws)
            dewpoint = dewPointRH(temperature, humidity, pws)

            if config.Gassensor == 'SGP30':
                GSens.set_iaq_humidity(absHum)
                CO2 = GSens.eCO2
                TVOC = GSens.TVOC
                eCO2_baseline = hex(GSens.baseline_eCO2)
                TVOC_baseline = hex(GSens.baseline_TVOC)

            elif config.Gassensor == 'SGP30':
                CO2 = TSens.CO2
                TVOC = 0
                eCO2_baseline = 0
                TVOC_baseline = 0

            date = time.strftime("%Y%m%d")
            time1 = time.strftime("%H:%M:%S")

            #print("eCO2 = %d ppm \t TVOC = %d ppb" % (sgp30.eCO2, sgp30.TVOC))
            print(
                "eCO2= %d ppm | TVOC= %d ppb | T= %0.1f C | RH= %0.1f | date:%s | time: %s"
                % (CO2, TVOC, temperature, humidity, str(date), str(time1)))
            time.sleep(1)
            elapsed_sec += 1

            sensData = {
                'lab': config.lab,
                'date': date,
                'time': time1,
                'temperature': temperature,
                'pressure': pressure,
                'humidity': humidity,
                'dewpoint': dewpoint,
                'CO2': CO2,
                'TVOC': TVOC,
                'eCO2_baseline': eCO2_baseline,
                'TVOC_baseline': TVOC_baseline,
            }
            df = pd.DataFrame(sensData, index=[0])

            if not os.path.exists(file):
                df.to_csv(file, mode="a", header=True)
            else:
                df.to_csv(file, mode="a", header=False)

            if elapsed_sec > 20:
                elapsed_sec = 0
                eCO2_baseline = GSens.baseline_eCO2
                TVOC_baseline = GSens.baseline_TVOC
                print("**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x" %
                      (eCO2_baseline, TVOC_baseline))
                if config.resetBaseline:
                    GSens.set_iaq_baseline(eCO2_baseline, TVOC_baseline)
 def __init__(self, i2c_bus):
     self.temperature_sensor = adafruit_mcp9808.MCP9808(i2c_bus)