Update 'testing.py'
This commit is contained in:
parent
00dd649873
commit
d546d5fb3c
55
testing.py
55
testing.py
@ -9,7 +9,7 @@ import RPi.GPIO as gp
|
||||
from adafruit_mcp3xxx.analog_in import AnalogIn
|
||||
|
||||
|
||||
def test_relay_on_off(rly=None):
|
||||
def test_relay_on_off(rly=None, watering_time=None):
|
||||
# use GPIO numbering
|
||||
gp.setmode(gp.BCM)
|
||||
|
||||
@ -17,40 +17,61 @@ def test_relay_on_off(rly=None):
|
||||
gp.output(rly, gp.HIGH)
|
||||
|
||||
try:
|
||||
while True:
|
||||
gp.output(rly, gp.LOW)
|
||||
print("Relay 1 ON")
|
||||
time.sleep(1)
|
||||
gp.output(rly, gp.HIGH)
|
||||
print("Relay 1 OFF")
|
||||
time.sleep(1)
|
||||
gp.output(rly, gp.LOW)
|
||||
#print(f"Relay 1 ON pin {rly}")
|
||||
time.sleep(watering_time)
|
||||
gp.output(rly, gp.HIGH)
|
||||
#print(f"Relay 1 OFF pin {rly}")
|
||||
time.sleep(2)
|
||||
except KeyboardInterrupt:
|
||||
gp.cleanup()
|
||||
|
||||
|
||||
def test_sensor_in_out_water():
|
||||
def test_sensor_in_out_water(channel=None):
|
||||
channels = {"5": board.D5}
|
||||
# create the spi bus
|
||||
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
|
||||
|
||||
# print(dir(board.pin))
|
||||
# create the chip select
|
||||
cs = digitalio.DigitalInOut(board.D5)
|
||||
# ch = ast.literal_eval(channel)
|
||||
# ch = eval(channel)
|
||||
# print(ch)
|
||||
cs_1 = digitalio.DigitalInOut(channels[channel])
|
||||
# cs_2 = digitalio.DigitalInOut(board.D5)
|
||||
|
||||
# create the mcp object
|
||||
mcp = MCP.MCP3008(spi, cs)
|
||||
mcp_1 = MCP.MCP3008(spi, cs_1)
|
||||
# mcp_2 = MCP.MCP3008(spi, cs_2)
|
||||
|
||||
#https://docs.circuitpython.org/en/latest/shared-bindings/analogio/index.htm
|
||||
# create an analog input channel on pin 5
|
||||
analog_ic = AnalogIn(mcp, MCP.P5)
|
||||
|
||||
analog_ic_1 = AnalogIn(mcp_1, MCP.P5)
|
||||
# analog_ic_2 = AnalogIn(mcp_2, MCP.P6)
|
||||
# print(dir(analog_ic_1._mcp._spi_device))
|
||||
#print(analog_ic_1._pin_setting)
|
||||
try:
|
||||
while True:
|
||||
print(f"Raw ADC value: {analog_ic.value:.2f}")
|
||||
print(f"ADC Voltage value: {analog_ic.voltage:.3f}")
|
||||
# print(f"Raw ADC value: {analog_ic.value:.2f}")
|
||||
print(f"ADC Voltage value sensor 1: {analog_ic_1.voltage:.3f}")
|
||||
# print(f"ADC Voltage value sensor 2: {analog_ic_2.voltage:.3f}\n")
|
||||
time.sleep(.5)
|
||||
except KeyboardInterrupt:
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from datetime import date
|
||||
# Relay 1 on GPIO21
|
||||
#test_relay_on_off(21)
|
||||
test_sensor_in_out_water()
|
||||
for _ in range(2):
|
||||
# plantas colgantes
|
||||
test_relay_on_off(rly=16, watering_time=5)
|
||||
time.sleep(2)
|
||||
# plantas estanteria
|
||||
test_relay_on_off(rly=26, watering_time=5)
|
||||
time.sleep(2)
|
||||
# limonero
|
||||
test_relay_on_off(rly=23, watering_time=4)
|
||||
time.sleep(2)
|
||||
#test_sensor_in_out_water("5")
|
||||
print(f"Ha regado el {date.today()}")
|
Loading…
Reference in New Issue
Block a user