Mike Hogan
Published © GPL3+

Tank Farm - Well and rain water irrigation controller

Tank Farm Manager is a Raspberry Pi 2b based irrigation controller that integrates rain water collection with well water systems.

AdvancedShowcase (no instructions)6,144
Tank Farm - Well and rain water irrigation controller

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
16gb SSD with Windows 10 core.
×1

Software apps and online services

Windows 10 IoT Core
Microsoft Windows 10 IoT Core
c# code

Story

Read more

Schematics

Board Layout

Connections to Pi

Valve connection

Code

Tank Farm read XML file sample code

C#
System settings read from XML config files
private void LoadXML_appConfig()
        {
            using (XmlReader reader = XmlReader.Create(@"appconfig.xml"))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name.ToString())
                        {
                            case "RainDetect":
                                RainDetect.IsOn = Convert.ToBoolean(reader.ReadElementContentAsString());
                                break;
                            case "TankFeed":
                                toggleTankFlow.IsOn = Convert.ToBoolean(reader.ReadElementContentAsString());
                                break;
                            case "VoiceOn":
                                HearVoice.IsOn = Convert.ToBoolean(reader.ReadElementContentAsString());
                                break;


                        }

                    }

                }
            }
        }

Tank Manager read keypad sample code

C#
IO pins are expensive and often overused for user button presses. As an alternative. Small USB number keypads provide 18 discrete key press/button press inputs.
 // detect keypad presses
        private void KeyDown_1(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
        {
            keyActions(e.Key.ToString());
        }
        
        
        // process keypress actions
        private void keyActions(string key)
        {
          
          if (key == "Subtract")
            {
                if (HearVoice.IsOn == false)
                {
                    LogMCMsg("Voice on", true);
                    HearVoice.IsOn = true;
                }
                else
                {
                    LogMCMsg("Voice off", true);
                    HearVoice.IsOn = false;
                }

            }
            .......
       }

Tank Farm valve control sample code

C#
Example operational logic for zone irrigation, auto water presssure and tank feed control
 private void OpLogic()
        {
            // check to see if automation is turned off
            if (Automate.IsOn == true)
            {
                // lower plot
                if (mcData[6].Value == "0" && autoWaterPlot1 == false)
                {
                    autoWaterPlot1 = true;
                    //turn on water pressure if feed from well
                    if (mcData[4].Value == "1" && toggleTankFlow.IsOn == false)
                        DevToggle(4, true);
                }

                // turn off water pressure if garden last off
                if (mcData[6].Value == "1")
                {
                    if (mcData[4].Value == "0" && autoWaterPlot1 == true && autoFillTank == false && autoWaterVinyard == false && IrrigateSeries1Started == false && toggleTankFlow.IsOn == false)
                        DevToggle(4, false);

                    autoWaterPlot1 = false;
                    
                }
                
                ...............
                
          }
          
        }    

Tank Farm UI toggle device sample code

C#
- Flipping switches from UI invokes DevToggle(device,state). Which then calls PinOn(Device).
- If Micro Controller is not installed in panel, application will run in simulation mode.
- PinOn(device) makes hardware call to the micro controller to drive pin high.
- Timer evaluates pins configured for digital pulse output (DPO) and changes pins from a high state to a low state after one interval.
private void toggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            if (toggleValve1.IsOn == true && mcData[4].Value == "1")
                DevToggle(4, true);
            if (toggleValve1.IsOn == false && mcData[4].Value == "0")
                DevToggle(4, false);
        }
        
        
         private void DevToggle(int devNum, bool state)
        {
            if (mcData[devNum].Value == "1" && state == true)
            {
                PinOn(devNum - 4);
                if (simActive == true)
                {
                    mcData[devNum].Value = "0";
                    mcData2[devNum].SimPin = "0";
                    mcData2[devNum].PinChangedToOn = true;
                }
            }

            if (mcData[devNum].Value == "0" && state == false)
            {
                PinOn(devNum - 4);
                if (simActive == true)
                {
                    mcData[devNum].Value = "1";
                    mcData2[devNum].SimPin = "1";
                    mcData2[devNum].PinChangedToOff = true;
                }
            }
        }
        
         private int PinOn(int pinNum)
        {
            if (pinNum > -1 && pinNum < 13)
                dev[pinNum].Write(GpioPinValue.High);
            return -1;

        }
        
        private void Timer_Tick(object sender, object e)
        {
            // manage digital pulse outputs
            for (int i = 0; i < 12; i++)
            {
                if (mcParams[i].Type == "DPO")
                {
                    if (mcData2[i].PinSet == true)
                    {
                        dev[i].Write(GpioPinValue.Low);
                        mcData2[i].PinSet = false;
                    }

                    if (dev[i].Read() == 0)
                    {
                        //next step
                    }
                    else
                    {
                        mcData2[i].PinSet = true;
                    }
                }
            }
        }

Credits

Mike Hogan

Mike Hogan

8 projects • 38 followers
Interested in hardened massive io frameworks

Comments