Пример #1
0
 def __init__(self):
     self.screen = screen.Screen(180)
     self.last_ready = time.time()
     self.last_temp = 0
     self.thermocouple = MAX31856(software_spi=SOFTWARE_SPI)
     self.status_url = os.environ["COFFEE_STATUS_URL"]
     atexit.register(self.screen.clear)
Пример #2
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "hi:s:", ["runid=", "seconds="])
    except getopt.GetoptError:
        print('logger.py -i <RunID> -s <seconds>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h' or (opt != '-i' and opt != '-s'):
            print('logger.py -i <RunID> -s <seconds>')
            sys.exit()
        elif opt in ("-i", "--RunID="):
            RunID = arg
            print('RunID is ', RunID)
        elif opt in ("-s", "--seconds="):
            interval_seconds = int(arg)
            print('interval_seconds is ', interval_seconds)

    # 3 lcd lines comment out to disable, on is in the while True loop
    lcd = display()
    lcd.clear()

    SQLDB = '/home/pi/kilnlog.sqlite3'
    SQLConn = sqlite3.connect(SQLDB)
    SQLConn.row_factory = sqlite3.Row
    SQLCur = SQLConn.cursor()

    sql = "INSERT INTO firelog(RunID, datime, t)VALUES(?,?,?);"

    SPI_PORT = 0
    SPI_DEVICE = 0
    sensor = MAX31856(hardware_spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
    t_now = sensor.read_temp_c()
    print('TC: {0:0.3F}*C'.format(t_now))
    temps = [t_now, t_now, t_now]
    starttime = time.time()
    lastTime = starttime - interval_seconds

    while True:
        datime = time.time()
        if lastTime + interval_seconds <= datime:
            t_now = sensor.read_temp_c()
            if temps.insert(0, t_now):
                temps.pop()
            p = (RunID, time.strftime('%Y-%m-%d %H:%M:%S'), t_now)
            # 3rd lcd line
            lcd.writeLog(RunID, ts(time.time() - starttime), temps[0],
                         temps[1], temps[2])
            print('TC: {0:0.3F}*C'.format(t_now))
            try:
                SQLCur.execute(sql, p)
                SQLConn.commit()
            except:
                SQLConn.rollback()
                print("DB Update failed!")
            lastTime = datime
            time.sleep(interval_seconds - 1)
Пример #3
0
def getTC3Data():
    SPI_PORT = 0
    SPI_DEVICE = 0
    sensor = MAX31856(
        hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE))
    temp = sensor.read_temp_c()
    internal = sensor.read_internal_temp_c()
    tempf = c_to_f(temp)
    internalf = c_to_f(internal)

    return tempf, internalf
Пример #4
0
                            analog1Val = (adc.read_adc(0, gain=GAIN)) * m1 + b1
                            analog2Val = (adc.read_adc(1, gain=GAIN)) * m2 + b2
                        else:
                            if (numAnalog == 1):
                                analog1Val = (adc.read_adc(
                                    0, gain=GAIN)) * m1 + b1
            else:
                GPIO.output(20, GPIO.LOW)
                analog1Val = 'NULL'
                analog2Val = 'NULL'
                analog3Val = 'NULL'
                analog4Val = 'NULL'

            if (numThermocouple > 0):
                if (numThermocouple == 4):
                    therm1 = MAX31856(software_spi=software_spi1)
                    therm2 = MAX31856(software_spi=software_spi2)
                    therm3 = MAX31856(software_spi=software_spi3)
                    therm4 = MAX31856(software_spi=software_spi3)
                    thermocouple1Val = therm1.read_temp_c()
                    if (u1 == 'F'):
                        thermocouple1Val = cToF(thermocouple1Val)
                    thermocouple2Val = therm2.read_temp_c()
                    if (u2 == 'F'):
                        thermocouple2Val = cToF(thermocouple2Val)
                    thermocouple3Val = therm3.read_temp_c()
                    if (u3 == 'F'):
                        thermocouple3Val = cToF(thermocouple3Val)
                    thermocouple4Val = therm4.read_temp_c()
                    if (u4 == 'F'):
                        thermocouple4Val = cToF(thermocouple4Val)
Пример #5
0
logging.basicConfig(
    filename='logs/simpletest.log',
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
_logger = logging.getLogger(__name__)

# Uncomment one of the blocks of code below to configure your Pi to use software or hardware SPI.

## Raspberry Pi software SPI configuration.
#software_spi = {"clk": 25, "cs": 8, "do": 9, "di": 10}
#sensor = MAX31856(software_spi=software_spi)

# Raspberry Pi hardware SPI configuration.
SPI_PORT = 0
SPI_DEVICE = 1
sensor = MAX31856(hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE))

# Loop printing measurements every second.
#print('Press Ctrl-C to quit.')
#while True:
#temp = sensor.read_temp_c()
#internal = sensor.read_internal_temp_c()
#print('Thermocouple Temperature: {0:0.3F}*C'.format(temp))
#print('    Internal Temperature: {0:0.3F}*C'.format(internal))
#time.sleep(1.0)

temp = sensor.read_temp_c()
internal = sensor.read_internal_temp_c()
#string = ""
#if len(sys.argv)>1:
#	string = sys.argv[1]
Пример #6
0
this is testi module and is not needed for pilnfired.py daemon
  assumption: display.py test run successfully
  If display is not set up, comment out the while True loop
  and it will just print to screen once
"""

from signal import *
import os
import time
from Adafruit_GPIO import SPI
from Adafruit_MAX31856 import MAX31856
from display import display

SPI_PORT = 0
SPI_DEVICE = 0
sensor = MAX31856(hardware_spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

lcd = display()
lcd.clear()


def clean(*args):
    print('doing the cleanup')
    lcd.close(clear=True)
    os._exit(0)


for sig in (SIGABRT, SIGINT, SIGTERM):
    signal(sig, clean)

temp = sensor.read_temp_c()
Пример #7
0
import datetime
import glob
import MySQLdb
from time import strftime

# Local Imports
from Adafruit_MAX31856 import MAX31856 as MAX31856

#logging.basicConfig(filename='simpletest.log', level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#_logger = logging.getLogger(__name__)

# Uncomment one of the blocks of code below to configure your Pi to use software or hardware SPI.

## Raspberry Pi software SPI configuration.
tc0Pins = {"clk": 14, "cs": 23, "do": 18, "di": 15}
tc0 = MAX31856(software_spi=tc0Pins)
tc1Pins = {"clk": 14, "cs": 23, "do": 18, "di": 15}
tc1 = MAX31856(software_spi=tc1Pins)
tc2Pins = {"clk": 14, "cs": 23, "do": 18, "di": 15}
tc2 = MAX31856(software_spi=tc2Pins)
tc3Pins = {"clk": 14, "cs": 23, "do": 18, "di": 15}
tc3 = MAX31856(software_spi=tc3Pins)


# Loop printing measurements every second.
print('Press Ctrl-C to quit.')
while True:
datetimeWrite = (time.strftime("%Y-%m-%d ") + time.strftime("%H:%M:%S"))
    
    
    
Пример #8
0
GPIO.setmode(GPIO.BCM)

AppDir = '/home/pi/PILN'
StatFile = '/home/pi/html/pilnstat.json'

#--- sqlite3 db file ---
SQLDB = '/home/pi/db/PiLN.sqlite3'

#--- Global Variables ---
ITerm = 0.0
LastErr = 0.0
SegCompStat = 0
LastTmp = 0.0

#--- MAX31856 only works on SPI0, SPI1 cannot do mode=1 ---
Sensor0 = MAX31856(tc_type=MAX31856.MAX31856_K_TYPE,
                   hardware_spi=SPI.SpiDev(0,0)) #SPI0,CE0 Kiln
Sensor1 = MAX31856(tc_type=MAX31856.MAX31856_K_TYPE,
                   hardware_spi=SPI.SpiDev(0,1)) #SPI0,CE1 Room
#--- Fan to cool control box---
FAN=13
GPIO.setup(FAN, GPIO.OUT)
GPIO.output(FAN, GPIO.LOW)
def fan(dafan, ambient, internal):
  if internal > ambient + 10:
      GPIO.output(dafan, GPIO.HIGH)
  else:
      GPIO.output(dafan, GPIO.LOW)

#--- Relays ---
HEAT = (24, 23, 22)
for element in HEAT:
Пример #9
0
 def __init__(self):
     self.sensor = MAX31856(
         hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE))
Пример #10
0

def log_data(temp, internal, elapsed):
    with open(data_file_path, 'a', newline='') as log:
        log.write("{0},{1},{2},{3}\n".format(time.strftime(
            "%Y-%m-%d %H:%M:%S"), str(elapsed), str(internal), str(temp)))

#logging.basicConfig(filename='simpletest.log', level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#_logger = logging.getLogger(__name__)

# Uncomment one of the blocks of code below to configure your Pi to use software or hardware SPI.


# Raspberry Pi software SPI configuration.
software_spi = {"clk": 25, "cs": 8, "do": 9, "di": 10}
sensor = MAX31856(software_spi=software_spi)

# Raspberry Pi hardware SPI configuration.
#SPI_PORT   = 0
#SPI_DEVICE = 0
#sensor = MAX31856(hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE))


start = time.time()
# Loop printing measurements every second.
print('Press Ctrl-C to quit.')
while True:
    temp = sensor.read_temp_c()
    internal = sensor.read_internal_temp_c()
    end = time.time()
    elapsed = end - start
# Local Imports
from Adafruit_MAX31856 import MAX31856 as MAX31856

logging.basicConfig(
    filename='simpletest.log',
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
_logger = logging.getLogger(__name__)

# Uncomment one of the blocks of code below to configure your Pi to use software or hardware SPI.

## Raspberry Pi software SPI configuration.
#software_spi = {"clk": 25, "cs": 8, "do": 9, "di": 10}
#sensor = MAX31856(software_spi=software_spi, tc_type=MAX31856.MAX31856_K_TYPE)

# Raspberry Pi hardware SPI configuration.
SPI_PORT = 0
SPI_DEVICE = 0
sensor = MAX31856(hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE),
                  tc_type=MAX31856.MAX31856_K_TYPE)

# Loop printing measurements every second.
print('Press Ctrl-C to quit.')
while True:
    temp = sensor.read_temp_c()
    internal = sensor.read_internal_temp_c()
    print('Thermocouple Temperature: {0:0.3F}*C'.format(temp))
    print('    Internal Temperature: {0:0.3F}*C'.format(internal))
    time.sleep(1.0)
Пример #12
0
 def __int__(MAX31856):
     self.T0 = MAX31856(hardware_spi=SPI.SpiDev(0,0))
     self.T1 = MAX31856(hardware_spi=SPI.SpiDev(0,1))
     self.temp[] = readit()
     self.internal[] = readint()
Пример #13
0
with open("logs/general_" + timestamp + ".log", "w") as log:
    pass

logging.basicConfig(
    filename="logs/MAX31856/" + timestamp + ".log",
    level=logging.DEBUG,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
_logger = logging.getLogger(
    __name__)  # Creates log-file the thermocouple-chip.

# Raspberry Pi hardware SPI configuration.
SPI_PORT = 0
SPI_DEVICE = 0
sensor = MAX31856(
    hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE),
    tc_type=MAX31856.MAX31856_K_TYPE)  #remove tc_type for non-K thermocouples

# Relay configuration.
relay = DOD(0)  # Creates a general DigitalOutputDevice using GPIO pin 0

# Definitions for plot
fig = Figure(figsize=(2, 2), dpi=100)
ax = fig.add_subplot(111)
x = []
y = []
line, = ax.plot(x, y, "-")


# Animation function
def animate(i):
Пример #14
0
# Local Imports
from Adafruit_MAX31856 import MAX31856 as MAX31856

logging.basicConfig(
    filename='simpletest.log',
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
_logger = logging.getLogger(__name__)

# Uncomment one of the blocks of code below to configure your Pi to use software or hardware SPI.

## Raspberry Pi software SPI configuration.
#CLK = 25
#CS  = 24
#DO  = 18
#sensor = MAX31856(CLK, CS, DO)

# Raspberry Pi hardware SPI configuration.
SPI_PORT = 0
SPI_DEVICE = 0
sensor = MAX31856(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

# Loop printing measurements every second.
print('Press Ctrl-C to quit.')
while True:
    temp = sensor.readTempC()
    internal = sensor.readInternalTempC()
    print('Thermocouple Temperature: {0:0.3F}*C'.format(temp))
    print('    Internal Temperature: {0:0.3F}*C'.format(internal))
    time.sleep(1.0)
Пример #15
0
lcd = display()
lcd.clear()

AppDir = '/home/mypiln/MyPiLN'
StatFile = '/home/mypiln/MyPiLN/html/pilnstat.json'
#--- sqlite3 db file ---
SQLDB = '/home/mypiln/MyPiLN/db/PiLN.sqlite3'
#--- Global Variables ---
ITerm = 0.0
LastErr = 0.0
SegCompStat = 0
LastTmp = 0.0
#--- MAX31856 only works on SPI0, SPI1 cannot do mode=1 ---
SPI_PORT = 0    #SPI0
SPI_DEVICE = 0  #CS0
Sensor0 = MAX31856(tc_type=MAX31856.MAX31856_K_TYPE,spi = SPI.SpiDev(SPI_PORT,SPI_DEVICE))
#---output GPIOs for 3 Relays ---
#HEAT = (22, 23, 24)
#---testing w/ 1 relay ---
HEAT = (24)
for element in HEAT:
    GPIO.setup(element, GPIO.OUT)
    GPIO.output(element, GPIO.LOW)
#--- input GPIO for kilnsitter ---
KS = 27
GPIO.setup(KS, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def kilnsitter():
    state = GPIO.input(KS)
    return (state)
#--- Cleanup ---
def clean(*args):