Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emergency shutoff #60

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
884f4fe
added pinouts for kiln hat PCB
tanaes Jan 8, 2022
4d201ab
added e relay code
tanaes Jan 9, 2022
f7f63a0
added comment
tanaes Jan 9, 2022
8f88ecc
merge fix
tanaes Jan 9, 2022
ef5f011
testing TM1637 display addition
tanaes Jan 9, 2022
f496712
fixed errors
tanaes Jan 9, 2022
6679867
added init display
tanaes Feb 5, 2022
5ae5916
moved display code to oven
tanaes Feb 5, 2022
4bc68aa
updating config
tanaes Feb 5, 2022
fb673ff
testing
tanaes Feb 5, 2022
cc3ddbb
moving display code
tanaes Feb 5, 2022
cd1e079
testing
tanaes Feb 5, 2022
8ca8839
testing
tanaes Feb 5, 2022
1f32c18
testing
tanaes Feb 5, 2022
03f319c
testing
tanaes Feb 5, 2022
504f0ff
testing
tanaes Feb 5, 2022
17d8db8
testing
tanaes Feb 5, 2022
5d728bc
testing
tanaes Feb 5, 2022
38674ba
testing
tanaes Feb 5, 2022
3762602
testing
tanaes Feb 5, 2022
c3e2d6f
testing
tanaes Feb 5, 2022
4c8215f
testing
tanaes Feb 5, 2022
f3d2213
displays!!
tanaes Feb 5, 2022
98dfcf5
added display update routine
tanaes Feb 5, 2022
35e6b10
updated display defaults
tanaes Feb 5, 2022
eadf9f8
fixed object order
tanaes Feb 5, 2022
3f9b82a
typo
tanaes Feb 5, 2022
4ca77a0
fixing error
tanaes Feb 5, 2022
da2acf2
fixed float to int
tanaes Feb 5, 2022
8af5215
fixed float to int
tanaes Feb 5, 2022
d96235f
added log file location
tanaes Feb 6, 2022
1e8076f
added logging to safety relay
tanaes Feb 6, 2022
6cdd626
rearranging Output class functions
tanaes Feb 6, 2022
160e32b
fixed bug
tanaes Feb 6, 2022
ae85668
fixed bug
tanaes Feb 6, 2022
425acd2
splitting temp and time updates
tanaes Feb 6, 2022
41030fc
added reset to IDLE on time disp
tanaes Feb 6, 2022
5edbc81
added gpio off function on service stop
tanaes Jul 16, 2022
5bf5045
Merge branch 'kiln-hat' into emergency-shutoff
tanaes Jul 23, 2022
0f2c85d
added *56 library*
tanaes Jul 23, 2022
3ca0a55
added *56 library*
tanaes Jul 23, 2022
d994c8e
Merge branch 'displays' into emergency-shutoff
tanaes Jul 23, 2022
d628200
changed log path
tanaes Jul 23, 2022
281f78a
changed log path
tanaes Jul 23, 2022
a85926a
adding status file
tanaes Jul 23, 2022
5862e4c
adding status file
tanaes Jul 23, 2022
cf69e36
adding status file
tanaes Jul 23, 2022
a88c92f
added dostar monitor code
tanaes Aug 6, 2022
88d7577
moved dotstar files
tanaes Aug 6, 2022
a65e680
pin naming
tanaes Aug 6, 2022
62a9b12
pin naming
tanaes Aug 6, 2022
871dc20
pin naming
tanaes Aug 6, 2022
6cff7dd
testing
tanaes Aug 6, 2022
1545253
testing
tanaes Aug 6, 2022
622c7ed
testing
tanaes Aug 6, 2022
b50ac3e
testing
tanaes Aug 6, 2022
22f6ffb
testing
tanaes Aug 6, 2022
24449ea
testing
tanaes Aug 6, 2022
17c26a4
testing
tanaes Aug 6, 2022
f5087f0
testing
tanaes Aug 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

# uncomment this if using MAX-31856
#from lib.max31856 import MAX31856
from lib.max31856 import MAX31856

########################################################################
#
Expand All @@ -10,6 +10,8 @@
### Logging
log_level = logging.INFO
log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s'
log_file = '/home/pi/kiln-controller.log'
status_file = '/home/pi/kiln-controller.status'

### Server
listening_ip = "0.0.0.0"
Expand All @@ -29,22 +31,51 @@
# can use whichever GPIO you prefer/have available.

### Outputs
gpio_heat = 23 # Switches zero-cross solid-state-relay

## Mosfet outputs
gpio_heat = 17 # pin 11 Switches zero-cross solid-state-relay
gpio_e_relay = 27 # pin 13
gpio_fan = 22 # pin 15

# Note: `gpio_e_relay` is used to and a redundant mechanical relay in series with
# the SSR. Because SSRs normally fail closed (i.e. energized), this provides a
# way for the controller to shut off the kiln in the event that the SSR fails.
# It is designed to be used with the SSR input connected to the safety relay's
# Normally Open (NC) output; thus, the kiln can only heat when the RPi has
# energized the safety relay.

## Display outputs

temp_disp = {'type': 'TMC1637',
'pins': {'clock': 16,
'data': 26}} # pin 36, pin 37

time_disp = {'type': 'TMC1637',
'pins': {'clock': 20,
'data': 21}} # pin 38, pin 40

gpio_dotstar_clk = 19 # pin 35
gpio_dotstar_dat = 13 # pin 33

## I2C pins
gpio_i2c_sda1 = 2 # pin 3
gpio_i2c_scl1 = 3 # pin 5


### Thermocouple Adapter selection:
# max31855 - bitbang SPI interface
# max31856 - bitbang SPI interface. must specify thermocouple_type.
max31855 = 1
max31856 = 0
max31855 = 0
max31856 = 1
# see lib/max31856.py for other thermocouple_type, only applies to max31856
# uncomment this if using MAX-31856
#thermocouple_type = MAX31856.MAX31856_S_TYPE
thermocouple_type = MAX31856.MAX31856_K_TYPE

### Thermocouple Connection (using bitbang interfaces)
gpio_sensor_cs = 27
gpio_sensor_clock = 22
gpio_sensor_data = 17
gpio_sensor_di = 10 # only used with max31856
gpio_sensor_cs = 8 # pin 24
gpio_sensor_clock = 11 # pin 23
gpio_sensor_data = 9 # pin 21
gpio_sensor_di = 10 # pin 19

########################################################################
#
Expand Down Expand Up @@ -83,7 +114,7 @@
########################################################################
#
# Simulation parameters
simulate = True
simulate = False
sim_t_env = 60.0 # deg C
sim_c_heat = 100.0 # J/K heat capacity of heat element
sim_c_oven = 5000.0 # J/K heat capacity of oven
Expand Down
31 changes: 31 additions & 0 deletions dotstar_fail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT

"""
5This example blinks the LEDs purple at a 0.5 second interval.
6
7For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if
8using a different board or form of NeoPixels.
9
This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
"""
import config
import board
import adafruit_dotstar

from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.color import PURPLE

dotstar_num = config.dotstar_num = 27
dotstar_clk = config.gpio_dotstar_clk = 19 # pin 35
dotstar_dat = config.gpio_dotstar_dat = 13 # pin 33

pixels = adafruit_dotstar.DotStar(getattr(board, 'D%s' % dotstar_clk),
getattr(board, 'D%s' % dotstar_dat),
dotstar_num)

blink = Blink(pixels, speed=0.5, color=PURPLE)

while True:
blink.animate()
143 changes: 143 additions & 0 deletions dotstar_watcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env python

import board
import adafruit_dotstar
import config
import ast
from time import sleep
from math import ceil
from adafruit_led_animation.helper import PixelSubset
from adafruit_led_animation.animation.rainbowchase import RainbowChase
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.color import PURPLE
from adafruit_led_animation.group import AnimationGroup
from adafruit_led_animation.sequence import AnimationSequence


time_int = 0.5


class KilnStatus:
def __init__(self, status_fp):
self.state = 'STARTUP'
self.heat = False
self.temp = 0.0
self.target = 0.0
self.runtime = 0.0
self.totaltime = 0.0
self.delay = 0.5
self.status_fp = status_fp
self.speed = 0.1

def check_status(self):
with open(self.status_fp, 'r') as f:
status = ast.literal_eval(f.readline().strip())
self.state = status['state']
self.heat = status['heat']
self.temp = status['temperature']
self.target = status['target']
self.totaltime = status['totaltime']
self.runtime = status['runtime']

# {'runtime': 0,
# 'temperature': 78.41890624999999,
# 'target': 0,
# 'state': 'IDLE',
# 'heat': 0,
# 'totaltime': 0,
# 'kwh_rate': 0.1319,
# 'currency_type': '$',
# 'profile': None,
# 'pidstats': {}}


def update_status(kiln_status):
"""Monitor button that reverses rainbow direction and changes blink speed.
Assume button is active low.
"""

kiln_status.check_status()


def task_strip_top(pixels, kiln_status):
while True:
if kiln_status.state == 'STARTUP':
top = RainbowChase(pixels,
kiln_status.speed,
size=2,
spacing=3,
reverse=False,
step=8)
elif kiln_status.state == 'IDLE':
top = Pulse(pixels,
kiln_status.speed,
(135, 135, 135),
period=5)
elif kiln_status.state == 'RUNNING':
top = Comet(pixels,
kiln_status.speed,
(120, 200, 180),
tail_length=10,
reverse=False,
bounce=False,
ring=True)
elif kiln_status.state == 'EMERGENCY RESET':
top = Blink(pixels,
0.7,
(255, 0, 0))
return(top)

def task_strip_right(pixels, kiln_status):
r_blink = Blink(pixels, speed=0.5, color=PURPLE)
return(r_blink)

def main():

# setup

status_fp = config.status_file

kiln_status = KilnStatus(status_fp)

dotstar_num = config.dotstar_num = 27
dotstar_clk = config.gpio_dotstar_clk = 19 # pin 35
dotstar_dat = config.gpio_dotstar_dat = 13 # pin 33

pixels = adafruit_dotstar.DotStar(getattr(board, 'D%s' % dotstar_clk),
getattr(board, 'D%s' % dotstar_dat),
dotstar_num)

substrip_len = ceil(dotstar_num/3.0)

strip_left = PixelSubset(pixels,
0,
substrip_len)

strip_right = PixelSubset(pixels,
dotstar_num - substrip_len,
dotstar_num)

strip_top = PixelSubset(pixels,
substrip_len,
dotstar_num - substrip_len)

l_blink = Blink(strip_left, speed=0.5, color=PURPLE)


while True:
kiln_status.check_status()
right = task_strip_right(strip_right, kiln_status)
top = task_strip_top(strip_top, kiln_status)
animations = AnimationSequence(
AnimationGroup(
l_blink,
right,
top
))
animations.animate()
sleep(time_int)

if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions gpio_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python

if __name__ == "__main__":
pins = list(range(0,40))
GPIO.setup(pins, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
4 changes: 3 additions & 1 deletion kiln-controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
print ("Copy config.py.EXAMPLE to config.py and adapt it for your setup.")
exit(1)

logging.basicConfig(level=config.log_level, format=config.log_format)
logging.basicConfig(level=config.log_level,
format=config.log_format,
filename=config.log_file)
log = logging.getLogger("kiln-controller")
log.info("Starting kiln controller")

Expand Down
35 changes: 35 additions & 0 deletions lib/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import tm1637
import logging

log = logging.getLogger(__name__)


class TM1637(object):
def __init__(self,
clk_pin,
dat_pin):

self.clk_pin = clk_pin
self.dat_pin = dat_pin

try:
self.tm = tm1637.TM1637(clk=clk_pin,
dio=dat_pin)
except ImportError as e:
log.warning('import failure: \n%s' % e)

def temp(self,
t):
self.tm.number(t)

def time(self,
h,
m):
self.tm.numbers(h, m, True)

def text(self,
text):
self.tm.show(text[0:4])

def off(self):
self.tm.write([0, 0, 0, 0])
1 change: 1 addition & 0 deletions lib/init/kiln-controller.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Description=kiln-controller

[Service]
ExecStart=/home/pi/kiln-controller/venv/bin/python /home/pi/kiln-controller/kiln-controller.py
ExecStopPost=/home/pi/kiln-controller/venv/bin/python /home/pi/kiln-controller/gpio_off.py

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions lib/init/kiln-display.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=kiln-display

[Service]
ExecStart=/home/pi/kiln-controller/venv/bin/python /home/pi/kiln-controller/dotstar_watcher.py
ExecStopPost=/home/pi/kiln-controller/venv/bin/python /home/pi/kiln-controller/dotstar_fail.py

[Install]
WantedBy=multi-user.target
Loading