def __init__(self, pin): try: with open( "config.json", mode="r" ) as fpr: #try and except here because there is a changeable file system on the pi self.config = json.load(fpr) fpr.close() except FileNotFoundError: message.value = "config load error" self.error = 1 #not good but better print("could not open config file") try: with open("profiles/" + self.config["profile"] + ".json", mode="r") as fpr: self.sprofile = json.load(fpr) fpr.close() self.error = 0 #not good but better message.value = "Getting started" fileDisplay.value = self.config["profile"] + ".json" except FileNotFoundError: message.value = "profile load error" self.error = 1 #not good but better self.oven = digitalio.DigitalInOut(pin) self.oven.direction = digitalio.Direction.OUTPUT spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = digitalio.DigitalInOut(board.D2) self.sensor_status = False try: self.sensor = max6675.MAX6675(spi, cs) self.read_temp(self.sensor) self.ontemp = self.temperature self.offtemp = self.ontemp self.sensor_status = True except RuntimeError: print("temperature sensor not available") self.control = False self.reset() self.beep = Beep() self.set_state("ready") if self.sensor_status: if self.temperature >= 50: self.last_state = "wait" self.set_state("wait")
client = boto3.client('cloudwatch') def sendMetrics(value): response = client.put_metric_data( Namespace='smoker', MetricData=[ { 'MetricName': 'tempf', #'Dimensions': [ # { # 'Name': 'tempf', # 'Value': str(value) # }, #], 'Timestamp': datetime.utcnow(), 'Value': float(value), 'Unit': 'None', 'StorageResolution': 1 }, ]) while True: sensor_0_0 = max6675.MAX6675(cs_pin, clock_pin, data_pin, units) currentValue = sensor_0_0.get() print currentValue sendMetrics(currentValue) sleep(2)
targetT = 140 P = 7 I = 2 D = 1 pid = PID.PID(P, I, D) pid.SetPoint = targetT pid.setSampleTime(1) cs0_pin = 8 cs1_pin = 7 clock_pin = 11 data_pin = 9 units = "c" #tcd = max6675.MAX6675(cs0_pin, clock_pin, data_pin, units) tch = max6675.MAX6675(cs1_pin,clock_pin, data_pin, units) def readConfig (): global targetT with open ('/tmp/pid.conf', 'r') as f: config = f.readline().split(',') pid.SetPoint = float(config[0]) targetT = pid.SetPoint pid.setKp (float(config[1])) pid.setKi (float(config[2])) pid.setKd (float(config[3])) def createConfig (): if not os.path.isfile('/tmp/pid.conf'): with open ('/tmp/pid.conf', 'w') as f: f.write('%s,%s,%s,%s'%(targetT,P,I,D))
import time import board import busio import digitalio import sys import json import array import max6675 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = digitalio.DigitalInOut(board.D2) try: sensor = max6675.MAX6675(spi, cs) except RuntimeError as e: print(e) print("Unable to connect to the thermocouple sensor.") sys.exit(1) oven = digitalio.DigitalInOut(board.D4) oven.direction = digitalio.Direction.OUTPUT def oven_control(enable=False): #board.D4 oven.value = enable check_temp = 100 print("This program will determine calibration settings ") print("for your oven to use with the EZ Make Oven.\n\n") for i in range(10):
import time import RPi.GPIO as IO IO.setmode(IO.BCM) IO.setwarnings(False) pinRelay = 6 IO.setup(pinRelay, IO.OUT) IO.output(pinRelay, IO.LOW) print("yay") # default example cs_pin = 8 clock_pin = 11 data_pin = 9 units = "c" thermocouple = max6675.MAX6675(cs_pin, clock_pin, data_pin, units) running = True targetTemp = 220 PHASE_BRon = 1 PHASE_BRoff = 1 PHASE_LRon = 1 PHASE_LRoff = 3 PHASE_HoverOn = 1 PHASE_HoverOff = 9 sampleEnailTemp = 23 phaseOnValue = PHASE_BRon phaseOffValue = PHASE_BRoff phaseState = 0
def __init__(self, cs, clock, data, scale): import max6675 self.max = max6675.MAX6675(cs, clock, data, scale)