def update_Dataframe(updated_time, ADC_Value):
    analog_Steam_Sensor_1 = ADC_Value[constants.STEAM_SENSOR1]
    analog_Steam_Sensor_2 = ADC_Value[constants.STEAM_SENSOR2]
    analog_Steam_Sensor_3 = ADC_Value[constants.STEAM_SENSOR3]
    humidity_Steam_Sensor_1 = to_Humidity(analog_Steam_Sensor_1)
    humidity_Steam_Sensor_2 = to_Humidity(analog_Steam_Sensor_2)
    humidity_Steam_Sensor_3 = to_Humidity(analog_Steam_Sensor_3)
    
    RTD1 = adafruit_max31865.MAX31865(constants.RTD_SPI, constants.CS1, rtd_nominal=1000, ref_resistor=4300.0, wires=3)
    RTD2 = adafruit_max31865.MAX31865(constants.RTD_SPI, constants.CS2, rtd_nominal=1000, ref_resistor=4300.0, wires=3)

    temp1 = RTD1.temperature
    temp2 = RTD2.temperature
    if ((temp1 > 200) | (temp2 > 200)):
        temp1, temp2 = np.nan, np.nan
    else:
        temp1, temp2 = temp1, temp2
    
    if not ((humidity_Steam_Sensor_1 >= constants.THRESHOLD) | (humidity_Steam_Sensor_2 >= constants.THRESHOLD) | (humidity_Steam_Sensor_3 >= constants.THRESHOLD)):
        new_row = {'Time (min)':updated_time, 
                'Steam Sensor 1 (Count)':0, 'Humidity 1 (%)':0,
                'Steam Sensor 2 (Count)':0, 'Humidity 2 (%)':0, 
                'Steam Sensor 3 (Count)':0, 'Humidity 3 (%)':0, 
                'Steam Temp. (C)':temp1, 'Surrounding Temp. (C)':temp2}
        constants.df = constants.df.append(new_row, ignore_index = True)
    if ((humidity_Steam_Sensor_1 >= constants.THRESHOLD) | (humidity_Steam_Sensor_2 >= constants.THRESHOLD) | (humidity_Steam_Sensor_3 >= constants.THRESHOLD)):
        new_row = {'Time (min)':updated_time, 
                'Steam Sensor 1 (Count)':analog_Steam_Sensor_1, 'Humidity 1 (%)':humidity_Steam_Sensor_1,
                'Steam Sensor 2 (Count)':analog_Steam_Sensor_2, 'Humidity 2 (%)':humidity_Steam_Sensor_2, 
                'Steam Sensor 3 (Count)':analog_Steam_Sensor_3, 'Humidity 3 (%)':humidity_Steam_Sensor_3, 
                'Steam Temp. (C)':temp1, 'Surrounding Temp. (C)':temp2}
        constants.df = constants.df.append(new_row, ignore_index = True)
Beispiel #2
0
def main():
    # -- PT1000 sensor initialization --
    # Initialize SPI bus and sensor.
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    # Chip select of the MAX31865 board.
    cs = digitalio.DigitalInOut(board.D5)
    # Current setup for pt1000
    sensor = adafruit_max31865.MAX31865(spi, cs, wires=3)

    # -- set parameters --
    #runinfo = open("runinfo.txt", "r")
    #sn = runinfo.read()
    #runinfo.close()

    run_number = input("Run number: ")
    filename = 'run%s_temperature_data.txt' % (run_number)
    start_time = time.time()
    print('Start time: %s' % (time.ctime(start_time)))
    print('Estimated end time: %s' % (time.ctime(start_time + 43200)))
    save_path = '/home/pi/tempstudy/data/'
    file = save_path + filename
    f = open(file,'w')
    f.close()
    data = get_temperatures(sensor, file)
    f.close()
    sync_data(filename)
Beispiel #3
0
    def initialize_input(self):
        import busio
        import board
        import digitalio
        import adafruit_max31865

        bcm_to_board = [
            board.D1, board.D2, board.D3, board.D4, board.D5, board.D6,
            board.D7, board.D8, board.D9, board.D10, board.D11, board.D12,
            board.D13, board.D14, board.D15, board.D16, board.D17, board.D18,
            board.D19, board.D20, board.D21, board.D22, board.D23, board.D24,
            board.D25, board.D26, board.D27
        ]

        self.thermocouple_type = self.input_dev.thermocouple_type
        if self.thermocouple_type == 'PT100':
            self.rtd_nominal = 100
        elif self.thermocouple_type == 'PT1000':
            self.rtd_nominal = 1000

        self.ref_ohm = self.input_dev.ref_ohm

        self.spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
        self.cs = digitalio.DigitalInOut(bcm_to_board[self.cs_pin - 1])

        self.sensor = adafruit_max31865.MAX31865(self.spi,
                                                 self.cs,
                                                 rtd_nominal=self.rtd_nominal,
                                                 ref_resistor=self.ref_ohm,
                                                 wires=int(self.wires))
Beispiel #4
0
    def __init__(self, cspin, nwires, ref_resistor=430.0, **kwargs):
        Spime.__init__(self, **kwargs)

        spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
        cs = digitalio.DigitalInOut(board.pin.Pin(cspin))
        self.sensor = adafruit_max31865.MAX31865(spi,
                                                 cs,
                                                 ref_resistor=ref_resistor,
                                                 wires=nwires)
Beispiel #5
0
 def __init__(self, sck, mosi, miso, cs, wires=2):
     self.spi = busio.SPI(sck, MOSI=mosi, MISO=miso)
     self.cs = digitalio.DigitalInOut(cs)
     self.sensor = adafruit_max31865.MAX31865(
         self.spi,
         self.cs,
         wires=wires,
         rtd_nominal=constants.TEMPERATURE_NOMINAL_RESISTANCE,
         ref_resistor=constants.TEMPERATURE_REF_RESISTANCE,
     )
Beispiel #6
0
    def __init__(self, settings):
        ## Create Software SPI controller.  MAX31865 requires polarity of 0 and phase of 1.
        ## Currently, the micropython on the ESP32 does not support hardware SPI
        sck = Pin(5, Pin.OUT)
        mosi = Pin(18, Pin.IN)
        miso = Pin(19, Pin.OUT)
        spi = SPI(baudrate=50000,
                  sck=sck,
                  mosi=mosi,
                  miso=miso,
                  polarity=0,
                  phase=1)

        ## Create SPI Chip Select pins
        cs1 = Pin(33, Pin.OUT, value=1)
        cs2 = Pin(15, Pin.OUT, value=1)
        cs3 = Pin(32, Pin.OUT, value=1)
        cs4 = Pin(14, Pin.OUT, value=1)
        css = [cs1, cs2, cs3, cs4]

        self.sensors = []
        self.sensor_info = []
        idx = 0

        ## Create array of active RTD sensors and information about them
        for name in settings['device']['sensors']:
            idx += 1

            if name.upper() == "DISABLE":
                continue

            self.sensors.append([
                idx,
                max31865.MAX31865(spi,
                                  css[idx - 1],
                                  wires=4,
                                  rtd_nominal=RTD_NOMINAL,
                                  ref_resistor=RTD_REFERENCE)
            ])

            self.sensor_info.append({
                "id": idx,
                "scale": settings['device']['scale'],
                "type": "temperature",
                "sensor": "RTD1000 -> MAX31865",
                "name": name
            })

        self.scale = settings['device']['scale']
        self.to_int = settings['device']['to_int']
Beispiel #7
0
    def _initialize_hardware(self):
        '''Set up the sensor and relay'''
        spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
        cs = digitalio.DigitalInOut(getattr(board, f'D{self.sensor_pin}'))
        sensor = adafruit_max31865.MAX31865(spi,
                                            cs,
                                            wires=3,
                                            rtd_nominal=1000.0,
                                            ref_resistor=4300.0)

        # set up relay
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.relay_pin, GPIO.OUT)

        return sensor
Beispiel #8
0
def read_temperature(pin, wires=3):
    '''
	Inputs:
		pin - in the format board.D<pin> where <pin> is the pin you want to read the sensor on.
	
	Outputs:
		Sensor temperature in degrees C.
   	'''
    try:
        spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
        cs = digitalio.DigitalInOut(pin)
        sensor = adafruit_max31865.MAX31865(spi, cs, wires=wires)
        return sensor.temperature
    except:
        return -9999
Beispiel #9
0
    def init(self):
        spi = board.SPI()
        cs = digitalio.DigitalInOut(self.CS)
        self.sensor = adafruit_max31865.MAX31865(spi, cs, wires=self.NWires, rtd_nominal=self.R0,
                                                 ref_resistor=self.Rref)
        if self.sensor.resistance == 0.:
            print("MAX31865: unphysical resistance read, assuming SPI communication error")
            sys.exit(1)

        # Provide configuration parameters
        if self.NChannels == 1:
            self.ChanLims = [[-10., 110.]]
            self.ChanNams = ['T']
        else:
            self.ChanLims = [[-10., 110.], [0.9*self.R0, 1.1*self.R0]]
            self.ChanNams = ['T', 'R']
Beispiel #10
0
    def init(self):
        print('initializing RTD...')
        import board
        import busio
        import digitalio
        import adafruit_max31865

        SCK = board.SCK
        MOSI = board.MOSI
        MISO = board.MISO
        CE = board.CE0

        R_NOM = 100.0
        R_REF = 430.0

        spi = busio.SPI(SCK, MOSI=MOSI, MISO=MISO)
        cs = digitalio.DigitalInOut(CE)
        self.rtd = adafruit_max31865.MAX31865(spi,
                                              cs,
                                              rtd_nominal=R_NOM,
                                              ref_resistor=R_REF)
Beispiel #11
0
    def __init__(self,
                 interval=1,
                 host='localhost',
                 port=8080):  # update interval in seconds
        super().__init__()

        self.host, self.port = host, port

        self.interval = interval
        # Initialize SPI bus and sensor.
        spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
        cs = digitalio.DigitalInOut(
            board.D5)  # Chip select of the MAX31865 board.
        self.sensor = adafruit_max31865.MAX31865(spi, cs, ref_resistor=430.0)
        # Note you can optionally provide the thermocouple RTD nominal, the reference
        # resistance, and the number of wires for the sensor (2 the default, 3, or 4)
        # with keyword args:
        # sensor = adafruit_max31865.MAX31865(spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=2)

        # finally , start the tread
        self.start()
Beispiel #12
0
	def __init__(self, port, ch, wires=4):
		self.wires = wires
		self.port = port
		self.ch = ch
		self.cs_pin = self.chip_select_pin(port,ch)
		if not self.cs_pin:
			sys.exit()
		# port 0 parameters
		clk = 11
		mosi = 10
		miso = 9
		if port == 1:
			clk = 21
			mosi = 20
			miso = 19
			
		self.clk = clk
		self.mosi = mosi
		self.miso = miso
		
		self.spi = busio.SPI(self.clk,MOSI=self.mosi, MISO=self.miso)
		self.cs = digitalio.DigitalInOut(self.cs_pin)
		self.sensor = adafruit_max31865.MAX31865(self.spi, self.cs, wires=self.wires)
Beispiel #13
0
cs2 = machine.Pin(15, machine.Pin.OUT, value=1)
cs3 = machine.Pin(32, machine.Pin.OUT, value=1)
cs4 = machine.Pin(14, machine.Pin.OUT, value=1)
css = [cs1, cs2, cs3, cs4]

sensors = []
idx = 0

## Create array of active RTD sensors and information about them
for cs in css:
    idx += 1

    sensors.append(
        max31865.MAX31865(spi,
                          css[idx - 1],
                          wires=4,
                          rtd_nominal=RTD_NOMINAL,
                          ref_resistor=RTD_REFERENCE))


def timestamp():
    return float(time.ticks_ms()) / 1000.0


boot_time = timestamp()

while True:
    data = [timestamp() - boot_time
            ] + [sensor.temperature for sensor in sensors]
    print(','.join(map(str, data)))
Beispiel #14
0
from datetime import datetime
import sys
import board
import busio
import digitalio
import os
import csv
import adafruit_max31865

path = "/home/pi/AWS/Data/"
file_path = os.path.join(path, "ice_temp.csv")

# Initialize SPI bus and sensor.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D17)  # Chip select of the MAX31865 board.
sensor = adafruit_max31865.MAX31865(spi, cs, wires=4)
# Note you can optionally provide the thermocouple RTD nominal, the reference
# resistance, and the number of wires for the sensor (2 the default, 3, or 4)
# with keyword args:
# sensor = adafruit_max31865.MAX31865(spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=2)
file = open(file_path, "a")
if os.stat(file_path).st_size == 0:
    file.write("Datetime,Ice_Temp\n")

counter = 0
temp = 0
samples = 5

while counter < samples:
    # Read temperature.
    temp += sensor.temperature
Beispiel #15
0
import time
import board
import busio
import digitalio
import adafruit_max31865
import sys
import mysql.connector
import threading
import requests
import urllib
import os
from bs4 import BeautifulSoup
'''spi bus and sensor'''
spi1 = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs1 = digitalio.DigitalInOut(board.D5)
sensor1 = adafruit_max31865.MAX31865(spi1, cs1, wires=3)
"""spi2=busio.SPI(board.SCK,MOSI=board.MOSI,MISO=board.MISO)
cs2=digitalio.DigitalInOut(board.D6)
sensor2=adafruit_max31865.MAX31865(spi2,cs2,wires=3)

spi3=busio.SPI(board.SCK,MOSI=board.MOSI,MISO=board.MISO)
cs3=digitalio.DigitalInOut(board.D13)
sensor3=adafruit_max31865.MAX31865(spi3,cs3,wires=3)
"""


def upload2(temp, x):
    data1 = urllib.request.urlopen(
        "https://api.thingspeak.com/update?api_key=Z8R7TVO7N17C5R34&field1={0}&created_at={1}"
        .format(str(float(temp)), str(x)))
    page = data1.read()
Beispiel #16
0
import tkinter as tk
from tkinter.font import BOLD
import board
import digitalio
import adafruit_max31865

# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5)  # Chip select of the MAX31865 board.
#sensor = adafruit_max31865.MAX31865(spi, cs)
# Note you can optionally provide the thermocouple RTD nominal, the reference
# resistance, and the number of wires for the sensor (2 the default, 3, or 4)
# with keyword args:
sensor = adafruit_max31865.MAX31865(spi,
                                    cs,
                                    rtd_nominal=100,
                                    ref_resistor=430.0,
                                    wires=4,
                                    filter_frequency=50)


class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        # Create label
        self.ueberschrift = tk.Label(text="Temperatur [°C]")
        self.ueberschrift.config(font=("Arial", 20), bg="darkred", fg="red")
Beispiel #17
0
#

USAGE = """
usage: rtddemo.py

   Prints out RTD readings continuously.
"""

import time

import board
import digitalio
import busio
import adafruit_max31865 as max3

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D5)
rtd_sensor = max3.MAX31865(spi,
                           cs,
                           wires=3,
                           rtd_nominal=100.0,
                           ref_resistor=430.0)
###############################################################################

while (True):
    T = rtd_sensor.temperature

    print('RTD: T = %.3f' % T)

    time.sleep(0.5)
cs7 = digitalio.DigitalInOut(board.D21)
cs8 = digitalio.DigitalInOut(board.D20)
cs9 = digitalio.DigitalInOut(board.D16)
cs10 = digitalio.DigitalInOut(board.D12)
cs11 = digitalio.DigitalInOut(board.D1)
cs12 = digitalio.DigitalInOut(board.D7)
cs13 = digitalio.DigitalInOut(board.D25)
cs14 = digitalio.DigitalInOut(board.D24)
cs15 = digitalio.DigitalInOut(board.D23)
cs16 = digitalio.DigitalInOut(board.D18)
cs17 = digitalio.DigitalInOut(board.D15)
cs18 = digitalio.DigitalInOut(board.D14)
cs19 = digitalio.DigitalInOut(board.D2)


sensor1 = adafruit_max31865.MAX31865(spi, cs1,  wires=4)
sensor2 = adafruit_max31865.MAX31865(spi, cs2,  wires=4)
sensor3 = adafruit_max31865.MAX31865(spi, cs3,  wires=4)
sensor4 = adafruit_max31865.MAX31865(spi, cs4,  wires=3)
sensor5 = adafruit_max31865.MAX31865(spi, cs5,  wires=4)
sensor6 = adafruit_max31865.MAX31865(spi, cs6,  wires=4)
sensor7 = adafruit_max31865.MAX31865(spi, cs7,  wires=4)
sensor8 = adafruit_max31865.MAX31865(spi, cs8,  wires=3)
sensor9 = adafruit_max31865.MAX31865(spi, cs9,  wires=4)
sensor10 = adafruit_max31865.MAX31865(spi, cs10,  wires=4)
sensor11 = adafruit_max31865.MAX31865(spi, cs11,  wires=4)
sensor12 = adafruit_max31865.MAX31865(spi, cs12,  wires=4)
sensor13 = adafruit_max31865.MAX31865(spi, cs13,  wires=4)
sensor14 = adafruit_max31865.MAX31865(spi, cs14,  wires=4)
sensor15 = adafruit_max31865.MAX31865(spi, cs15,  wires=4)
sensor16 = adafruit_max31865.MAX31865(spi, cs16,  wires=4)
Beispiel #19
0
def pid_loop(dummy, state):
    import sys
    from time import sleep, time
    from math import isnan
    import board
    import busio
    import digitalio
    import adafruit_max31865
    import PID as PID
    import config as conf

    sys.stdout = open("pid.log", "a")
    sys.stderr = open("pid.err.log2", "a")

    def c_to_f(c):
        return c * 9.0 / 5.0 + 32.0

    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    cs = digitalio.DigitalInOut(board.D5)
    sensor = adafruit_max31865.MAX31865(spi, cs)

    print("got sensor:", sensor)

    pid = PID.PID(conf.Pc, conf.Ic, conf.Dc)
    pid.SetPoint = state['settemp']
    pid.setSampleTime(conf.sample_time * 5)

    nanct = 0
    i = 0
    j = 0
    pidhist = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]
    avgpid = 0.
    temphist = [0., 0., 0., 0., 0.]
    avgtemp = 0.
    lastsettemp = state['settemp']
    lasttime = time()
    sleeptime = 0
    iscold = True
    iswarm = False
    lastcold = 0
    lastwarm = 0

    try:
        while True:  # Loops 10x/second
            tempc = sensor.temperature
            if isnan(tempc):
                nanct += 1
                if nanct > 100000:
                    sys.exit
                continue
            else:
                nanct = 0

            tempf = c_to_f(tempc)
            temphist[i % 5] = tempc
            avgtemp = sum(temphist) / len(temphist)

            if avgtemp < 100:
                lastcold = i

            if avgtemp > 200:
                lastwarm = i

            if iscold and (i - lastcold) * conf.sample_time > 60 * 15:
                pid = PID.PID(conf.Pw, conf.Iw, conf.Dw)
                pid.SetPoint = state['settemp']
                pid.setSampleTime(conf.sample_time * 5)
                iscold = False

            if iswarm and (i - lastwarm) * conf.sample_time > 60 * 15:
                pid = PID.PID(conf.Pc, conf.Ic, conf.Dc)
                pid.SetPoint = state['settemp']
                pid.setSampleTime(conf.sample_time * 5)
                iscold = True

            if state['settemp'] != lastsettemp:
                pid.SetPoint = state['settemp']
                lastsettemp = state['settemp']

            if i % 10 == 0:
                pid.update(avgtemp)
                pidout = pid.output
                pidhist[int(i / 10 % 10)] = pidout
                avgpid = sum(pidhist) / len(pidhist)

            state['i'] = i
            state['tempc'] = round(tempc, 2)
            state['avgtemp'] = round(avgtemp, 2)
            state['pidval'] = round(pidout, 2)
            state['avgpid'] = round(avgpid, 2)
            state['pterm'] = round(pid.PTerm, 2)
            if iscold:
                state['iterm'] = round(pid.ITerm * conf.Ic, 2)
                state['dterm'] = round(pid.DTerm * conf.Dc, 2)
            else:
                state['iterm'] = round(pid.ITerm * conf.Iw, 2)
                state['dterm'] = round(pid.DTerm * conf.Dw, 2)
            state['iscold'] = iscold

            print(time(), state)

            sleeptime = lasttime + conf.sample_time - time()
            if sleeptime < 0:
                sleeptime = 0
            sleep(sleeptime)
            i += 1
            lasttime = time()

    finally:
        pid.clear
Beispiel #20
0
# Simple demo of the MAX31865 thermocouple amplifier.
# Will print the temperature every second.
#TRIED AND TESTED BY WWW.THINKROBOTICS.IN
import time

import board
import busio
import digitalio

import adafruit_max31865

# Initialize SPI bus and sensor.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D5)  # Chip select of the MAX31865 board.
sensor = adafruit_max31865.MAX31865(spi, cs)
# Note you can optionally provide the thermocouple RTD nominal, the reference
# resistance, and the number of wires for the sensor (2 the default, 3, or 4)
# with keyword args:
# sensor = adafruit_max31865.MAX31865(spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=2)

# Main loop to print the temperature every second.
while True:
    # Read temperature.
    temp = sensor.temperature
    # Print the value.
    print("Temperature: {0:0.3f}C".format(temp))
    # Delay for a second.
    time.sleep(1.0)
Beispiel #21
0
import constants_old
import numpy as np

import adafruit_max31865

# Initialize SPI bus and sensor.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs1 = digitalio.DigitalInOut(board.D5)  # Chip select of the MAX31865 board.
cs2 = digitalio.DigitalInOut(board.D6)  # Chip select of the MAX31865 board.


#sensor = adafruit_max31865.MAX31865(spi, cs)
# Note you can optionally provide the thermocouple RTD nominal, the reference
# resistance, and the number of wires for the sensor (2 the default, 3, or 4)
# with keyword args:
sensor = adafruit_max31865.MAX31865(spi, cs1, rtd_nominal=1000, ref_resistor=4300.0, wires=3)
sensor2 = adafruit_max31865.MAX31865(spi, cs2, rtd_nominal=1000, ref_resistor=4300.0, wires=3)


# Main loop to print the temperature every second.
def collect_temp():
    while True:
        # Read temperature.
        temp1 = sensor.temperature
        temp2 = sensor2.temperature
        if ((temp1 > 200) | (temp2 > 200)):
            # Print the value
            print(np.nan)
        
        else:
            print("Steam Temp: {0:0.2f}C".format(temp1))
def dataReadOut():
    conn = psycopg2.connect(database="TemaccessToRemoteRp2",
                            user="******",
                            password="******",
                            host="127.0.0.1",
                            port="5432")
    #print ("Opened database successfully")
    c = conn.cursor()
    # Initialize SPI bus and sensor.
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    cs1 = digitalio.DigitalInOut(
        board.D4)  # Chip select of the MAX31865 board.
    cs2 = digitalio.DigitalInOut(
        board.D5)  # Chip select of the MAX31865 board.
    cs3 = digitalio.DigitalInOut(board.D6)
    cs4 = digitalio.DigitalInOut(board.D13)
    cs5 = digitalio.DigitalInOut(board.D19)
    cs6 = digitalio.DigitalInOut(board.D26)
    cs7 = digitalio.DigitalInOut(board.D21)
    cs8 = digitalio.DigitalInOut(board.D20)
    cs9 = digitalio.DigitalInOut(board.D16)
    cs10 = digitalio.DigitalInOut(board.D12)
    cs11 = digitalio.DigitalInOut(board.D1)
    cs12 = digitalio.DigitalInOut(board.D7)
    cs13 = digitalio.DigitalInOut(board.D25)
    cs14 = digitalio.DigitalInOut(board.D24)
    cs15 = digitalio.DigitalInOut(board.D23)
    cs16 = digitalio.DigitalInOut(board.D18)
    cs17 = digitalio.DigitalInOut(board.D15)
    cs18 = digitalio.DigitalInOut(board.D14)
    cs19 = digitalio.DigitalInOut(board.D2)

    sensor1 = adafruit_max31865.MAX31865(spi, cs1, wires=4)
    sensor2 = adafruit_max31865.MAX31865(spi, cs2, wires=4)
    sensor3 = adafruit_max31865.MAX31865(spi, cs3, wires=4)
    sensor4 = adafruit_max31865.MAX31865(spi, cs4, wires=3)
    sensor5 = adafruit_max31865.MAX31865(spi, cs5, wires=4)
    sensor6 = adafruit_max31865.MAX31865(spi, cs6, wires=4)
    sensor7 = adafruit_max31865.MAX31865(spi, cs7, wires=4)
    sensor8 = adafruit_max31865.MAX31865(spi, cs8, wires=3)
    sensor9 = adafruit_max31865.MAX31865(spi, cs9, wires=4)
    sensor10 = adafruit_max31865.MAX31865(spi, cs10, wires=4)
    sensor11 = adafruit_max31865.MAX31865(spi, cs11, wires=4)
    sensor12 = adafruit_max31865.MAX31865(spi, cs12, wires=4)
    sensor13 = adafruit_max31865.MAX31865(spi, cs13, wires=4)
    sensor14 = adafruit_max31865.MAX31865(spi, cs14, wires=4)
    sensor15 = adafruit_max31865.MAX31865(spi, cs15, wires=4)
    sensor16 = adafruit_max31865.MAX31865(spi, cs16, wires=4)
    sensor17 = adafruit_max31865.MAX31865(spi, cs17, wires=4)
    sensor18 = adafruit_max31865.MAX31865(spi, cs18, wires=4)
    sensor19 = adafruit_max31865.MAX31865(spi, cs19, wires=4)
    c.execute('DROP TABLE IF EXISTS "sensors";')
    print('table deleted')

    c.execute(
        'CREATE TABLE sensors(id  SERIAL  PRIMARY KEY, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, Temp1d4 FLOAT, Temp2d5 FLOAT, Temp3d6 FLOAT, \
    Temp4d13 FLOAT,  Temp5d19 FLOAT, Temp6d26 FLOAT, Temp7d21 FLOAT,Temp8d20 FLOAT,Temp9d16 FLOAT, \
    Temp10d12 FLOAT,Temp11d1 FLOAT,Temp12d7 FLOAT, Temp13d8 FLOAT,Temp14d24 FLOAT,\
    Temp15d23 FLOAT, Temp16d18 FLOAT,Temp17d15 FLOAT, Temp18d14 FLOAT,Temp19d2 FLOAT);'
    )
    while True:
        # Read temperature.
        temp1 = sensor1.temperature
        temp2 = sensor2.temperature
        temp3 = sensor3.temperature
        temp4 = sensor4.temperature
        temp5 = sensor5.temperature
        temp6 = sensor6.temperature
        temp7 = sensor7.temperature
        temp8 = sensor8.temperature
        temp9 = sensor9.temperature
        temp10 = sensor10.temperature
        temp11 = sensor11.temperature
        temp12 = sensor12.temperature
        temp13 = sensor13.temperature
        temp14 = sensor14.temperature
        temp15 = sensor15.temperature
        temp16 = sensor16.temperature
        temp17 = sensor17.temperature
        temp18 = sensor18.temperature
        temp19 = sensor19.temperature

        c.execute("INSERT INTO sensors(Temp1d4, Temp2d5, Temp3d6,Temp4d13, \
        Temp5d19, Temp6d26,Temp7d21,Temp8d20, Temp9d16, Temp10d12,Temp11d1,Temp12d7,Temp13d8,Temp14d24, \
        Temp15d23, Temp16d18,Temp17d15, Temp18d14,Temp19d2) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s, %s,%s)"                                                                                                                               ,\
        (temp1, temp2,temp3,temp4,temp5,temp6, temp7, temp8, temp9, temp10, temp11,temp12, temp13, temp14, temp15,temp16, temp17,temp18, temp19))

        conn.commit()
        #print ('Top Source Tank:', temp4)
        #print ('Bottom Source Tank:', temp8)
        #print ('Top Testing HP circuit:', temp2)
        #print ('Bottom Testing HP circuit:', temp3)
        #print ('Top Testing load circuit:', temp6)
        #print ('Bottom Testing load circuit:', temp9)
        #print ('Load Tank tem.:', temp5)
        #print ('Mix tem at load:', temp7)
        #print('--------------------------')
        #print(stdout)
        print('done everything')
        sleep(0.1)
    return
SLEEPTIME = 0.005  # time between measurements
RECORD_FREQUENCY = 5  # how many measurements/second should be recorded

# STIR SPEEDS
STIR_STOP = 0
STIR_SLOW = 1
STIR_FAST = 2

# INITIALIZE PORTS

# setup temperature sensor
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D5)
sensor = adafruit_max31865.MAX31865(spi,
                                    cs,
                                    wires=3,
                                    rtd_nominal=1000.0,
                                    ref_resistor=4300.0)

# Setup I2C bus (for use with pH probe)
bus = smbus2.SMBus(0)
pH_address = 0x60  # TODO run 'sudo i2cdetect -y 0' to get actual address

# Register addresses; not sure why this is needed
reg_pH = 0x00

# Setup Keypad
KEYPAD = [["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"],
          ["*", "0", "#", "D"]]

factory = rpi_gpio.KeypadFactory()
Beispiel #24
0
def get():
    sensor = adafruit_max31865.MAX31865(spi, cs, wires=3)
    return sensor.temperature
Beispiel #25
0
import board
import busio
import digitalio

import adafruit_max31865

# Initialize SPI bus and sensor.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D5)  # Chip select of the MAX31865 board.
#sensor = adafruit_max31865.MAX31865(spi, cs)
# Note you can optionally provide the thermocouple RTD nominal, the reference
# resistance, and the number of wires for the sensor (2 the default, 3, or 4)
# with keyword args:
sensor = adafruit_max31865.MAX31865(spi,
                                    cs,
                                    rtd_nominal=100,
                                    ref_resistor=425.5,
                                    wires=2)


def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc))


# The callback for when a PUBLISH message is received from the server.

client = mqtt.Client()
client.on_connect = on_connect
client.connect("192.168.1.251", 1883, 60)

# Blocking call that processes network traffic, dispatches callbacks and
Beispiel #26
0
def Setup():
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    cs = digitalio.DigitalInOut(board.D5)
    RTD = adafruit_max31865.MAX31865(spi, cs)

    return RTD
Beispiel #27
0
 def RTD_init(self):
     #Initalize RTP100 sensor to GPIO5
     spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
     cs = digitalio.DigitalInOut(board.D5)
     rtdsensor = adafruit_max31865.MAX31865(spi, cs, wires=4)
     return rtdsensor
Beispiel #28
0
conexion1 = psycopg2.connect(database="boya",
                             user="******",
                             password="******")
cursor1 = conexion1.cursor()
sql = "insert into api_temperatura(temperatura, fecha, unidad, flag, latitud, longitud) values (%s,%s,%s,%s, %s,%s)"
conexion1.commit()

# Se asignan los pines encargados del protocolo SPI
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# Se selecciona el pin donde está conectado el sensor o plata MAX31865
# En este caso se asigna el pin 5
cs = digitalio.DigitalInOut(board.D5)
# Se llama a la librería MAX31865 asignandole los pines spi, cs
# e indicandole que es una PT100 y de 3 cables
sensor = adafruit_max31865.MAX31865(spi, cs, rtd_nominal=100.0, wires=3)

# Se crea un bucle infinito
while True:
    now = datetime.now()
    fecha = str(now).split(".")
    # Lee la temperatura
    temp = sensor.temperature
    # Imprime el valor de la temperatura en °C
    print('Temperatura: {0:0.3f} °C'.format(temp))
    # Se imprime el valor que está leyendo la resistencia
    print('Resistencia: {0:0.3f} Ohms'.format(sensor.resistance))
    datos = (round(sensor.temperature,
                   3), fecha[0], "°C", 4, "11.229602", "-74.163671")
    print(fecha[0])
    cursor1.execute(sql, datos)
Beispiel #29
0
mosi = machine.Pin(23, machine.Pin.IN)
miso = machine.Pin(19, machine.Pin.OUT)
# Create SPI Chip Select pins
cs1 = machine.Pin(5, machine.Pin.OUT, value=1)

spi = machine.SPI(baudrate=115200,
                  sck=sck,
                  mosi=mosi,
                  miso=miso,
                  polarity=0,
                  phase=1)

#sensor = max31865.MAX31865(spi, cs1, rtd_nominal=100, ref_resistor=430.0, wires=3)
rtd = max31865.MAX31865(spi,
                        cs=cs1,
                        wires=RTD_WIRES,
                        rtd_nominal=RTD_NOMINAL,
                        ref_resistor=RTD_REFERENCE)
'''
css = [cs1]
idx         = 0
sensors     = []

for cs in css:
    idx += 1

    sensors.append(
            max31865.MAX31865(
                spi, css[idx-1],
                wires        = RTD_WIRES,
                rtd_nominal  = RTD_NOMINAL,