If it's not obvious, I'm trying to learn python, and am having a go at it. Although, I'm running into some issues. Any help would be appreciated.
I'm trying to run this on a Rpi3b+ & with a relay
Edit: What I'm trying to do is have the script check the water level first before the it activates the pump relay, but I can't even get the script to pass a debug run through. Or is there a better way to write this script that will work with a Rpi?
# Hydroponic Watering v.0.0.1
import RPi.GPIO as GPIO
import time
import sys
import signal
signal.signal(signal.sigint, GPIO)
# Setting GPIO pins on Rpi
GPIO.setmode(GPIO.BCM)
signal, resv_level_pin, GPIO.in, pull_up_down = GPIO.PUD_up = 18
pump_relay, GPIO.OUT = 9
def check_water_level
if resv_level_pin == true
pump_relay(on)
elif resv_level_pin == false
pump_relay(false)
print("Water level too low!")
exit(sys.exit)
Debug output as follows:
Traceback (most recent call last):
File "/usr/share/mu-editor/mu/mu-debug.py", line 4, in <module>
from mu.app import debug
ModuleNotFoundError: No module named 'mu'
---------- FINISHED ----------
exit code: 1 status: 0
signal.signal(signal.sigint, GPIO)is certainly not what you intend it to be. What issignal, resv_level_pin, GPIO.in, pull_up_down = GPIO.PUD_up = 18supposed to mean? Your function definition lacks the parentheses, the parameters (if any) and the colon. It is furthermore never called.ifandeliflack the colon too and the indentation is off afterif. Where there is theelifanelseshould suffice.TrueandFalsekeywords should start uppercase.exit(sys.exit)is not only superfluous but also a strange combination of two things. See here. It should beexit()orsys.exit()with the parameter being the error code if you intend to send one to the caller.