def initThermo(): global Temp_J global Temp_K global Probe_J global Probe_K global SPI_EN_J global SPI_EN_K global spi #Chip Select Pins SPI_EN_J = digitalio.DigitalInOut( board.D0) #Pin BCM0/Pin ID_SD on GPIO Extenstion Board SPI_EN_K = digitalio.DigitalInOut(board.D5) #Pin BCM5/GPIO Extension Board #Initialize SPI #SCLK = BCM11 MOSI=BCM10 MISO = BCM9 spi = busio.SPI(board.SCLK, board.MOSI, board.MISO) #Thermocouple Initialization via MMAX31856 Board Probe_J = maxBoard.MAX31856(spi, SPI_EN_J) #Type J thermocouple --> outer block Probe_K = maxBoard.MAX31856(spi, SPI_EN_K) #Type K thermocouple --> inner block #Temperature Reading. Temperatures are recorded in Celsius by default #------------------------------------------------------------------------ #Temperature Initialization Temp_J = 0 Temp_K = 0
def __init__(self): self.heater_duty_cycle = 0.0 self.fan_duty_cycle = 0.0 print('GPIO mode: {}'.format(GPIO.getmode())) # something is setting GPIO mode to BCM before we get here # assume mode is BCM ##GPIO.setmode(GPIO.BOARD) ##heater_pwm_pin = 12 heater_pwm_pin = 18 GPIO.setup(heater_pwm_pin, GPIO.OUT) heater_pwm_frequency = 100.0 self.heater = GPIO.PWM(heater_pwm_pin, heater_pwm_frequency) #heater_pwm_duty_cycle = 25.0 fan_pwm_pin = 13 GPIO.setup(fan_pwm_pin, GPIO.OUT) fan_pwm_frequency = 100.0 self.fan = GPIO.PWM(fan_pwm_pin, fan_pwm_frequency) #kit = MotorKit() #self.fan = kit.motor1 spi = busio.SPI(board.SCK, board.MOSI, board.MISO) cs = digitalio.DigitalInOut(board.D5) cs.direction = digitalio.Direction.OUTPUT self.thermocouple = adafruit_max31856.MAX31856(spi, cs)
def __init__(self, cs_digital_pin_no=5, ignore_faults=False): """ cs_digital_pin_no: GPIO Pin number on the R Pi which is connected to the CS channel on the adafruit_max31856 ignore_faults: Whether or not to ignore errors reported by the chip. Will raise a ThermocoupleError exception if an error reported (and not ignored). """ # Note whether to ignore faults self.ignore_faults = ignore_faults # TODO: Wrap this in a try/except block to handle PermissionErrors (and print a solution - add user to group that owns /dev/spidev0.*) # create a spi object spi = busio.SPI(board.SCK, board.MOSI, board.MISO) # allocate a CS pin and set the direction cs = digitalio.DigitalInOut(getattr(board, f'D{cs_digital_pin_no}')) cs.direction = digitalio.Direction.OUTPUT # create a thermocouple object with the above self.thermocouple = adafruit_max31856.MAX31856(spi, cs) # Check for any faults self.update_faults()
def main(): # Singleton housekeeping me = singleton.SingleInstance() # Setup logging root_logger = logging.getLogger() root_logger.setLevel(logging.INFO) handler = logging.FileHandler('pilot.log', 'a', 'utf-8') handler.setFormatter(logging.Formatter('%(asctime)s %(message)s')) root_logger.addHandler(handler) # Open thermocouple for reading spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = digitalio.DigitalInOut(board.D5) cs.direction = digitalio.Direction.OUTPUT max31856 = adafruit_max31856.MAX31856(spi, cs) while (True): currentTemp = max31856.temperature logging.info('Current temp: %s', currentTemp) if (currentTemp < 35): send_mail() time.sleep(60)
def soak_time(): print("Preheat Started") while True: try: thermocouple = adafruit_max31856.MAX31856(spi, cs) temp_C = thermocouple.temperature if temp_C < 60: print("Pre Heat") heatplate(1) time.sleep(2) heatplate(0) time.sleep(1) elif temp_C < 130: print('Soaking 1') heatplate(1) time.sleep(1) heatplate(0) time.sleep(6) elif temp_C < 138: heatplate(1) print('Soaking 2') elif temp_C < 150: print('Reflow') heatplate(1) time.sleep(1) heatplate(0) time.sleep(4) elif temp_C > 165: fan(0.5) time.sleep(6) fan(1) print('Cooling') except KeyboardInterrupt: heatplate(0) break sys.exit
Debug = False if Debug == True: TempRise = 0 #TotalSeg=0 LastProcVal = 0.0 RunState = "" # create a spi object spi = busio.SPI(board.SCK, board.MOSI, board.MISO) # allocate a CS pin and set the direction cs = digitalio.DigitalInOut(board.D5) cs.direction = digitalio.Direction.OUTPUT # create a thermocouple object with the above thermocouple = adafruit_max31856.MAX31856(spi, cs) #--- Relays --- HEAT = (23, 24) for element in HEAT: GPIO.setup(element, GPIO.OUT) GPIO.output(element, GPIO.LOW) #--- Set up logging --- # create logger L = logging.getLogger('') #--- Cleanup --- def clean(*args): print("\nProgram ending! Cleaning up...\n")
SPI_EN_J = digitalio.DigitalInOut( board.D0) #Pin BCM0/Pin ID_SD on GPIO Extenstion Board SPI_EN_K = digitalio.DigitalInOut(board.D5) #Pin BCM5/GPIO Extension Board Pressure_Transducer = digitalio.DigitalInOut( board.D8) #Pin BCM24, GPIO8, SPI0_CE0_N AO_pin = 2 #Initialize SPI #SCLK = BCM11 MOSI=BCM10 MISO = BCM9 spi = busio.SPI(board.SCLK, board.MOSI, board.MISO) #Thermocouple Initialization via MMAX31856 Board Probe_J = maxBoard.MAX31856(spi, SPI_EN_J) #Type J thermocouple --> outer block Probe_K = maxBoard.MAX31856(spi, SPI_EN_K) #Type K thermocouple --> inner block #Temperature Reading. Temperatures are recorded in Celsius by default #------------------------------------------------------------------------ #Temperature Initialization Temp_J = 0 Temp_K = 0 i = 0 #Pressure Calibration minVoltage = 1.74 #Derived from testing maxVoltage = 5.0 #Derived from Signal Conditioner setting minPressure = 0
def thermocoupleSetup(CSPin): SPI = busio.SPI(board.SCK, board.MOSI, board.MISO) CS = digitalio.DigitalInOut(CSPin) CS.direction = digitalio.Direction.OUTPUT thermocouple = adafruit_max31856.MAX31856(SPI, CS) return thermocouple
import busio import digitalio import adafruit_max31856 import settings import time spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = [digitalio.DigitalInOut(board.D5), digitalio.DigitalInOut(board.D6)] # , digitalio.DigitalInOut(board.D13) max31856 = [] for i in range(len(cs)): max31856.append(adafruit_max31856.MAX31856(spi, cs[i])) # max31856 = adafruit_max31856.MAX31856(spi, cs) def GetTemp(units, index): tempC = max31856[index].temperature tempF = (tempC * 1.8) + 32 # convert offset to correct units offset = 0 # offset = settings.settings['offsetTemp'] # if units != settings.settings['units']: # if units == "celsius": # offset = offset / 1.8 # else:
def __init__(self): self.my_spi = busio.SPI(board.SCK, board.MOSI, board.MISO) self.my_cs = digitalio.DigitalInOut(board.D5) self.my_cs.direction = digitalio.Direction.OUTPUT self.my_thermocouple = adafruit_max31856.MAX31856( self.my_spi, self.my_cs)
# Argparse opt_debug = False opt_verbose = False # Systemd Service Notifications - https://github.com/bb4242/sdnotify sd_notifier = sdnotify.SystemdNotifier() # create a spi object spi = busio.SPI(board.SCK, board.MOSI, board.MISO) # allocate a CS pin and set the direction cs = digitalio.DigitalInOut(board.D5) cs.direction = digitalio.Direction.OUTPUT # create a thermocouple object with the above thermocouple = adafruit_max31856.MAX31856(spi, cs, adafruit_max31856.ThermocoupleType.K) # ----------------------------------------------------------------------------- # Logging # ----------------------------------------------------------------------------- def print_line(text, error=False, warning=False, info=False, verbose=False, debug=False, console=True, sd_notify=False): timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) if console:
import board import busio import digitalio import adafruit_max31856 #SPI Bus object (busio based) - just defines the grouping of pins for SPI # - adafruit_bus_device/spi_device.py SPI = busio.SPI(board.SCK, board.MOSI, board.MISO) #Chip Select - if we want multiple SPI slave devices - can set multiple CS for # multiple slave SPI chips. CS = digitalio.DigitalInOut(board.D5) #Output as its chip selection - and default high - sets to low to select that # slave chip and then send data out of MOSI CS.direction = digitalio.Direction.OUTPUT #Finally set up thermocouple object - defaults to K Type thermocouple = adafruit_max31856.MAX31856(SPI, CS) # The .temperature reads the register - sets CS to low - and reads then puts # high after print(thermocouple.temperature)