slergos
Posts: 2
Joined: Sat Jun 29, 2019 8:41 am

Python Programming for Hydroponics

Sat Jun 29, 2019 8:53 am

Hello, My name is Savvas, im an agricultural scientist, i have already build a prototype contrller for hydroponics on ESP32 / arduino, now i want to move on to Rasbberry / Python to take advantage of its hardware benefits , (remote acces and GUI)...
i need to control 12 peristaltic pumps and some solenoids.
the peristaltic pumps must start all at the same time (not one after the other) and run each one for a diferent time.
any idea how to achieve that?
Thank you !

pcmanbob
Posts: 6400
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Python Programming for Hydroponics

Sat Jun 29, 2019 12:41 pm

HI.

So which bit do you want help with connecting the pumps/solenoids physically to the pi gpio or switching them on for a set time period ?

if your new to the pi and its gpio then the physical computing guide may be a good place to start.

https://projects.raspberrypi.org/en/pro ... -computing

if its the physical connection you need help with then will will need to know details about the pumps/solenoids
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

PhatFil
Posts: 1305
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Python Programming for Hydroponics

Sat Jun 29, 2019 4:41 pm

slergos wrote:
Sat Jun 29, 2019 8:53 am
Hello, My name is Savvas, im an agricultural scientist, i have already build a prototype contrller for hydroponics on ESP32 / arduino, now i want to move on to Rasbberry / Python to take advantage of its hardware benefits , (remote acces and GUI)...
i need to control 12 peristaltic pumps and some solenoids.
the peristaltic pumps must start all at the same time (not one after the other) and run each one for a diferent time.
any idea how to achieve that?
Thank you !
Hi may i suggest you use your Pi With your current h/w, esp dev boards make great wifi assets for a smart system you host on your pi. there are a number of mature home automation systems with a strong user base such as Home assistant and Domoticz that can provide you with a gui for reference and control as well as providing the mechanisms for automatic reactions to sensor input.

to get 12x or any number of discrete esp wifi controllers all to start at the same time could be accomplished in a number of ways, With the tools i use for my own home automation experiments Mqtt/Node-red and tasmota firmware installed on my esp devices, Using Mqtt to issue commands to all the devices i would
1) point/confirm all are pointed at the same ntp server to sync time.
2) for each device define and set up a one off timer to start and end as desired all sharing the same start time.

slergos
Posts: 2
Joined: Sat Jun 29, 2019 8:41 am

Re: Python Programming for Hydroponics

Mon Jul 01, 2019 7:56 am

Firstly i woul like to thank all of you for the replies,
All the hardware is already setup. Since im newbie on Python, all i need is a sample code on how to start all pumps run simultanuasly for a diferent time each one, on ESP32 i used millis that helped me to have a kind of multitasking... is there any way to have the same result on Python? When i use time/sleep i get a serial pump operation but this is not what i need.
Thank you again.

scotty101
Posts: 3648
Joined: Fri Jun 08, 2012 6:03 pm

Re: Python Programming for Hydroponics

Mon Jul 01, 2019 8:09 am

Perhaps you can share the code you currently have...

Here is an example of something you maybe able to adapt.

Code: Select all

import time

class TimerDevice:
    def __init__(self,pin,on_for_time):
        self.pin = pin
        self.on_for_time = on_for_time
        self.start_time = None
    def start(self):
        self.start_time = time.time()
        print("Turning on pin {0}".format(self.pin))
    def update(self):
        now = time.time()
        if self.start_time:
            #Only check if timer has been started and is active
            if now > self.start_time+self.on_for_time:
                #Turn off pin and make timer inactive
                print("Turning off pin {0}".format(self.pin))
                self.start_time = None

if __name__ == '__main__':
    timers = []
    timers.append(TimerDevice(17,5))
    timers.append(TimerDevice(23,9))
    timers.append(TimerDevice(8,10))
    timers.append(TimerDevice(9,12))
    timers.append(TimerDevice(21,15))

    for timer in timers:
        timer.start()
    
    while True:
        for timer in timers:
            timer.update()
        time.sleep(1)

Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “Beginners”