Exemplo n.º 1
0
#!/usr/bin/python
# Example using a character LCD plate.
import time
import Adafruit_CharLCD as LCD

from ina219 import INA219
from ina219 import DeviceRangeError

import time
import Adafruit_MCP9808.MCP9808 as MCP9808

SHUNT_OHMS = 0.1
sensor1 = MCP9808.MCP9808()
sensor1.begin()
sensor2 = MCP9808.MCP9808(address=0x19)
sensor2.begin()

ina1 = INA219(SHUNT_OHMS)
ina1.configure()
ina2 = INA219(SHUNT_OHMS, address=0x41)
ina2.configure()


def display_data():
    temp1 = sensor1.readTempC()
    temp2 = sensor2.readTempC()
    lcd.clear()
    lcd.message('P:{0:0.0F}C'.format(temp1))
    lcd.message(' %.1fV' % ina1.voltage())
    lcd.message(' %.0fmA' % ina1.current())
    lcd.message('\n')
Exemplo n.º 2
0
from datetime import datetime, timedelta
import itertools
import csv

#***************************************
#********* FREEZER MONITOR  ************
#***************************************

# Script created using scripts from:
# http://www.billconnelly.net/?p=375
# AND
# https://www.raspberrypi.org/magpi/raspberry-pi-fridge-monitor/
#   ( https://github.com/simonmonk/pi_magazine/blob/master/07_fridge_monitor/fridge_monitor.py )

# Connect to i2c sensor with default pins (SCL=P9_19, SDA = P9_20)
sensor = MCP9808.MCP9808()

# Initialize sensor
sensor.begin()

short_temp_buffer = deque(
    maxlen=3)  # 3 position buffer for the last 3 mins of temperature
long_temp_buffer = deque(
    maxlen=35)  # 35 position buffer to average previous 35 mins of temperature

for i in range(0, 35):
    long_temp_buffer.append(0)

mins_since_post = 15
last_post_selection = -1
Exemplo n.º 3
0
    def detect(self):
        """
        Detects and internally records the number of
        MCP9808 connected to the system via i2c.
        Initializes each sensor for reading data.
        The code naively assumes that each i2c device
        is a sensor object; thus, ensure that the class
        list reserved has addresses that are used
        by i2c devices other than the MCP9808s.
        """

        # Command to detect the I2C bus connetions
        op = ("sudo i2cdetect -y 1 "
              "| sed 's/--//g' | tail -n +2 | "
              "sed 's/^.0://g' | sed 's/UU//g'")

        # Poll the number of sensors via text manipulation from the I2C bus.
        # raw_sensors = subprocess.check_output(op, shell=True)
        process = subprocess.Popen(op, stdout=subprocess.PIPE, shell=True)
        raw_sensors, _ = process.communicate()

        # Close the process/file
        # In this case, we ignore if it's already terminated/closed.
        try:
            process.terminate()
        except OSError:
            pass

        # Hexcode of an individual sensor
        sensor_name = ''
        temp_addr_list = []

        # Create the sensor objects.
        maxim = len(raw_sensors)
        for i in range(0, maxim):
            if raw_sensors[i] != ' ' and raw_sensors[i] != '\n':
                sensor_name += raw_sensors[i]
                if len(sensor_name) == 2 and sensor_name not in self.reserved:
                    # Hexadecimal addresses are two digits long
                    temp_addr_list.append(sensor_name)
                    sensor_name = ''

        # If a different number of sensors has been detected, update
        if (len(temp_addr_list) != len(self.addr_list)):
            for address in self.addr_list:
                del address
            for sensor in self.sensor_list:
                try:
                    del sensor
                except IndexError:
                    break
            del self.addr_list
            self.addr_list = list(temp_addr_list)
            self.changed_sensors = True

        self.sensor_cnt = len(self.addr_list)
        # Begin communication with each sensor
        # and add it to the list.
        i = 0
        for addr in self.addr_list:
            if self.changed_sensors:
               	if addr == self.control_addr:
			try:
                        	self.control_sensor = mcp9808.MCP9808((int(self.control_addr, 16)))
                		self.control_sensor.begin()
			except:
				print "Error in  control sensor init"
		else:
			try:
                        	self.sensor_list.append(mcp9808.MCP9808((int(addr, 16))))
	                	self.sensor_list[i].begin()
                	except:
                    		self.sensor_list.remove(self.sensor_list[i])
                    		self.sensor_cnt -= 1
                   		continue  # don't increment i
                	i += 1

        self.changed_sensors = False
Exemplo n.º 4
0
# ************************** CONFIGS **************************
with open('config/config.json') as jsonConfig:
    configData = json.load(jsonConfig)
    host = configData['service']['host']
    # port = configData['service']['port']
    route = configData['service']['route']

    slack_url = configData['slack']['slack_url']

    log_path = configData['logger']['path']
    log_when = configData['logger']['when']
    log_int = configData['logger']['interval']

# ************************** SENSOR INIT **************************
# Initialize the sensor
temp_sensor = MCP9808.MCP9808()
temp_sensor.begin()

# ************************** CONSTANTS **************************
location = [36.1388, -86.8426]  # Location
interval = 300  # Reading frequency, in seconds

# ************************** FUNCTIONS **************************


# Convert celcius to fahrenheit
def c_to_f(c):
    return c * 9.0 / 5.0 + 32.0


def post_to_slack(url, msg):
Exemplo n.º 5
0
import time

import Adafruit_MCP9808.MCP9808 as MCP9808


# Define a function to convert celsius to fahrenheit.
def c_to_f(c):
    return c * 9.0 / 5.0 + 32.0


#
# For the Raspberry Pi this means you should hook up to the only exposed I2C bus
# from the main GPIO header and the library will figure out the bus number based
# on the Pi's revision.

# Default constructor will use the default I2C address (0x18) and pick a default I2C bus.
#sensor = MCP9808.MCP9808()

# Optionally you can override the address and/or bus number:
sensor = MCP9808.MCP9808(address=0x18, busnum=1)

# Initialize communication with the sensor.
sensor.begin()

# Loop printing measurements every second.
print('Press Ctrl-C to quit.')
while True:
    temp = sensor.readTempC()
    print('Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(temp, c_to_f(temp)))
    time.sleep(1.0)
Exemplo n.º 6
0
                    type=int,
                    required=False,
                    help="allowable error in temp in Celcius")

sensor_delay = 300  #sense every 5 minutes by default
if args.delay == True:
    sensor_delay = args.delay

sensor_error = 10
if args.error == True:
    sensor_error = args.error

exp_start = args.start
exp_dur = args.duration

sensor = tempLib.MCP9808()
sensor.begin()

while time.time() < exp_start:
    time.sleep(1)

base_temp = sensor.readTempC()
cur_time = time.time() - exp_start
while cur_time < exp_dur:
    if cur_time % sensor_delay == 0:
        cur_temp = sensor.readTempC()
        if abs(cur_temp - base_temp) > sensor_error:
            #TODO:Make error message/export to file
            print("Temp value out of range")

    cur_time = time.time() - exp_start
Exemplo n.º 7
0
num_file_1 = len([f for f in os.listdir(folder_name_1)]) + 1
file_name_1 = folder_name_1 + "DataFile" + str(num_file_1) + ".csv"

try:
    with open(file_name_1, "a") as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()
        print('Readings at: ' + file_name_1)
except:
    print('No USB drive found. File cannot be written')
    pass

## Internal Temperature Sensor Initialize
try:
    int_temp_sensor = int_temp.MCP9808()
    int_temp_sensor.begin()
except:
    pass


## Sensor Data Acquisition functions
# Check if the ble_path is recognized
def known_sensor(ble_path):
    for dev_addr in dev_addrs:
        if dev_addr == ble_path:
            return True
    return False


# Checks and fixes the readings, replaces None with -1
        tsl2591 = tsl2591.Tsl2591()
except ImportError:
    install(
        'https://github.com/adafruit/Adafruit_Python_MCP9808/archive/master.zip'
    )
    if device == 'OrangePiZero':
        import tsl2591
        tsl2591 = tsl2591.Tsl2591()
    print("Installing lux sensor")
except Exception as error:
    print(error)

try:
    if device == 'OrangePiZero':
        import Adafruit_MCP9808.MCP9808 as MCP9808
        mcp9808 = MCP9808.MCP9808(busnum=0)
        mcp9808.begin()
except ImportError:
    install('https://github.com/maxlklaxl/python-tsl2591/archive/master.zip')
    print("Installed temp sensor")
    if device == 'OrangePiZero':
        import Adafruit_MCP9808.MCP9808 as MCP9808
        mcp9808 = MCP9808.MCP9808(busnum=0)
        mcp9808.begin()
except Exception as error:
    print(error)

try:
    if device == 'RaspberryPiZero':
        import board
        import busio
Exemplo n.º 9
0
 def init_i2c(self):
     self.sensor_mcp = MCP9808.MCP9808()
     self.sensor_mcp.begin()
     self.sensor_bmp = BMP085.BMP085()
Exemplo n.º 10
0
import Adafruit_MCP9808.MCP9808 as MCP9808
mcp9808 = MCP9808.MCP9808()
temp = mcp9808.readTempC()

for i in range (0,1):
    # print temp - comment out later
    print("temp: " + str(temp))
Exemplo n.º 11
0
def MCP9008_get_data():
    sensor = MCP9808.MCP9808()
    sensor.begin()
    temp = c_to_f(sensor.readTempC())
    return {'time': time.time(), 'temp': temp}
Exemplo n.º 12
0
 def __init__(self):
     try:
         self.sensor = MCP9808.MCP9808()  # Start Temp Sensor
         self.sensor.begin()  # Initialize
     except:
         print("failed to initialize temp sensor")
Exemplo n.º 13
0
dbname = "sensor_data"

# Create the InfluxDB client object
client = InfluxDBClient(host, port, user, password, dbname)
measurement = "rpi2"

# SenseAir S8 | co2
ser = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=.5)
ser.flushInput()

# BME280 | humidity, pressure, altitiude
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# MCP9808 | high accuracy temperature
mcp = MCP9808.MCP9808()
mcp.begin()

# SGP30 | voc, co2
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
sgp30.iaq_init()

# SGP30 set saved calibration
store = open(storeFile, 'r')
cBase = int(store.readline())
vBase = int(store.readline())
store.close()
sgp30.set_iaq_baseline(cBase, vBase)


def getCO2():