What is the problem?
I've attempted to write a script that monitors a gas sensor and then upon detection signals a relay to turn off the printer.
I wanted to tie the script into an action command I have setup in the config.yaml that triggers a GPIO pin to activate relay to turn the power on the printer. I have it setup in the config to run toggle GPIO pin and run the script working fine. However the issue is that if the sensor script is running it seems to own the GPIO communication until I quit the script and then the other action commands I have setup to turn on/off the printer/lights/temp/fan will work.
What did you already try to solve it?
googled, tested, trying to understand what the issue is. I'm not experienced enough with python to figure out how to release the GPIO but keep the script monitoring the gas sensor.
Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log
, serial.log
or output on terminal tab, ...)
Here's the config portion
- action: printeron
command: gpio -g mode 23 out
command: /home/pi/oprint/bin/python /home/pi/scripts/smokesensor.py
name: Turn on the Printer
Here's the script
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import mathDO = 3
PrinterPower = 23
GPIO.setmode(GPIO.BCM)def setup():
GPIO.setup (DO, GPIO.IN)
GPIO.setup (PrinterPower, GPIO.OUT)
GPIO.output (PrinterPower, 0)def Print(x):
if x == 1:
print ''
print ' *********'
print ' * Safe~ *'
print ' *********'
print ''
if x == 0:
print ''
print ' ***************'
print ' * Danger Gas! *'
print ' ***************'
print ''def loop():
status = 1
count = 0
while True:tmp = GPIO.input(DO); if tmp != status: Print(tmp) status = tmp if status == 0: # print(tmp) count += 1 if count % 2 == 0: GPIO.output(PrinterPower, 0) else: GPIO.output(PrinterPower, 1) print(tmp) import push break time.sleep(1)
def destroy():
GPIO.output(PrinterPower, 0)
GPIO.cleanup()if name == 'main':
try:
setup()
loop()
except KeyboardInterrupt:
destroy()
Thanks for any help!