Buzzer on while ATO pump relay is active

Do you have a question on how to do something.
Ask in here.
Post Reply
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

I'm sure this is simple... just having a brain fart right now. I want my buzzer to be on only while the ATO pump relay is active. Doing some experimenting and want to know while I'm sitting around the house when the ATO tops off. I'm sure this is simple but I'm drawing a blank...

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Buzzer on while ATO pump relay is active

Post by rimai »

Which port do you have the buzzer connected to?
Roberto.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Buzzer on while ATO pump relay is active

Post by Sacohen »

My ATO is loud enough that I can hear it when it is on, but I have used the same code that triggers my ATO , but replaced the port with an empty port on the relay that I have a light plugged into.

IE:ReefAngel.WaterLevelATO(Test_Light,720,31,34);

I have my ports defined by names, but of you don't just use the port # on the relay.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Buzzer on while ATO pump relay is active

Post by Sacohen »

My ATO is loud enough that I can hear it when it is on, but I have used the same code that triggers my ATO , but replaced the port with an empty port on the relay that I have a light plugged into.

IE:ReefAngel.WaterLevelATO(Test_Light,720,31,34);

I have my ports defined by names, but of you don't just use the port # on the relay.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Buzzer on while ATO pump relay is active

Post by lnevo »

I wouldn't do it that way... You could potentially conflict with the normal ATO process that is going on.

I would suggest using the status of the ATO pump as the trigger.

ReefAngel.Relay.Set(Test_Light,ReefAngel.Relay.Status(ATO_Pump));

For the buzzer, I don't recall the syntax to turn the buzzer on, but the same logic would apply although syntax might differ.

Lee
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Buzzer on while ATO pump relay is active

Post by Sacohen »

Hey I'm still learning, but it has worked for me.
Lee's way is probably better.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

ATO pump is on Relay Box 1 socket #2 and my buzzer is on one of the Analog dimming ports on the relay box. I can change code or plug it in to either port.

I have a "Alert" variable that is currently either set to 0 or it something greater than 0 that automatically ups it to 25 to give me ~2.5V on the analog line and a very mellow but audible buzzer.

I want the buzzer just to notify me when the pump is pumping as I am doing some experiments with my ATO and would like the buzzer to turn on only while the ATO is pumping.

I was hoping for something is easy as something like a while statement While port2 is active Alert=25 else Alert = 0

Do the relay boxes have a software variable that goes true\false 1/0 while a relay is on that is available to read during each loop cycle? I imagine they do and I am probably just being stupid... The controller needs to change some software setting to turn them on/off.

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

See My ATO got stuck in the ON position once about 8 months ago and pumped my entire 44 Gallons of ATO water into my sump... overflowed my sump and I ended up with about 20 gallons of water on the floor. Since that time ATO has been disabled because I could not trust it. Now I am getting ready for a business trip in a few weeks and would like to work a few things out before I go. Want to build trust back up in the ATO and mess with some different settings in my code to try to prevent another STUCK ON situation.

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Buzzer on while ATO pump relay is active

Post by lnevo »

Yes you can do ReefAngel.Relay.Status(Port2); which will return 0 (off) or 1 (on). You could even be clever and do this

Code: Select all

Alert=ReefAngel.Relay.Status(Port2)*25;
If the status is 1 alert will be 25 and if staus is 0 alert will be 0 :)

Lee
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

lnevo wrote:Yes you can do ReefAngel.Relay.Status(Port2); which will return 0 (off) or 1 (on). You could even be clever and do this

Code: Select all

Alert=ReefAngel.Relay.Status(Port2)*25;
If the status is 1 alert will be 25 and if staus is 0 alert will be 0 :)

Lee

Sweet! The ReefAngel.Relay.Status(Portn) was the part I was missing. I like your nice efficient "clever" solution. That should work a treat. going to add it to my code now and upload to the RA+

I re-enabled my ATO a few days ago but moved the feed hose out of the sump and have it pumping back into the 44 Gallon Brute the ATO water is in for now. Until I build trust again. I want to see\hear it cycle for the next week or two. Probably going to also code it to only top off during hours I am home to hear it for now. After all I need to get to the tank and manually top it for now or it will time out. The buzzer for now is to tell me to get my arse over there and watch\top it off before it times out.

Funny the ATO worked flawlessly for months and then one day out of the blue I get home from work and the ATO pump was pumping away. Water was everywhere. skimmer shooting water out the top like a fountain. water right up to the edge of the top of my sump and all over the floor. That was the LAST time my ATO was in use...
Now I want to start using it again. 8 months plus of back to manual top off is really starting to get old. Specially at about 3 gallons of evap a day... lol

Thanks for the pointer. Gonna give it a try along with some code to only allow topoff during certain hours if I can figure that out...

Nick
Last edited by 00Warpig00 on Fri Jun 27, 2014 6:34 pm, edited 1 time in total.
180G FOWLR
20GH QT#1
29G QT#2

Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Buzzer on while ATO pump relay is active

Post by lnevo »

The other thing that you can do is check out my OverridePorts routine. You can prevent your relay from being manually triggered. It'll only do what you've hardcoded it to. This way you dont accidentally hit the wrong button. One thing at a time.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

Funny,

I think I might be hot on the trail of my ATO bug that caused my sump to overflow 8+ months ago.

Little rundown. I have my ATO coded to automatically top off with saltwater from my 44G Saltwater Brute if the salinity on the probe is below 30 (300) at top off time. It Tops off from my 44G pure RO/DI Brute if the Salinity is 30 (300) or above on the probe at ATO time. Both feed into my sump separately.

So today my controller flagged the ATO timeout because I was at work when the ATO triggered and I have my two brutes both feeding back into themselves. Nothing else could happen but a timeout.

Here is the interesting part. When I just made my change to the code and uploaded it, I expected the ATO to turn on and top off. My salinity in the tank (FOWLR) is at 30.8 (308) according to the probe. due to the 308 I expected my pump in the RO/DI Brute to kick on and pump RO/DI. The SW brute pump kicked on instead and started pumping to top off... hmm strange I'm thinking. Salinity is at 308 it should have turned on the OTHER pump. SO I watch it pump SW back into the brute it's pumping out of for x seconds until the ATO timeout trips, water level is not rising in sump because both brutes are pumping into themselves. So I'm thinking ok when this times out and the ATO timeout flag is tripped the pump in the SW brute will turn off. IT DID NOT TURN OFF! In fact it is still pump ing an hour later... ATO flag tripped... Red LED is on and is still on. I have not cleared the flag yet. Still pumping away. Here is what I think might have happened.

When the code uploaded and the controller rebooted I am guessing that the SW pump was selected because the salinity probe may have had a value of 0 on the first loop through the code. This would set the pump to the SW pump not the RO pump. Then over the next X seconds the salinity probe started to read correctly at 308 changing the ATO pump back to the RO/DI pump port on the relay box. When the ATO timed out since there was a change in ports from 7 to 2 during the topoff the controller probably attempted to shut down port 2 the RO/DI pump and left port 7 The SW port on. I had a similar problem with my low\high temp monitoring due to the temp probe staying at a value of 0 for too long on start up. I wonder if the exact same thing is happening with the salinity probe.

So I am guessing that what may have happened is that the controller for some reason reset while it was topping off and since it immediately needed to top off seeing the ATO Low float saying it's time to top off caused this described scenario to occur...

Just a theory...

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

I have another question....

If all of the hardware attached to the controller needs to be debounced like the temp probes PH Probes Salinity probes etc. at controller reboot\startup time... can I call a simple loop right as the first function inside the main loop to sit in that sub loop function until millis is > than say 1000 or 5000 or even 10000. until all the hardware is debounced or does the hardware need to be accessed in the main loop in order to ever debounce?

I would rather debounce everything at once and have the controller take an extra 1 or 5 or even 10 seconds to truly start up than deal with debounce issues for every piece of hardware I ever add to the controller...

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Buzzer on while ATO pump relay is active

Post by rimai »

Can you post the piece of your code that does the ATO?
It is only the very first run of loop that you don't have things initialized.
The function that reads everything is ShowInterface().
So, in the very first pass, everything is zero.
Roberto.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

rimai wrote:Can you post the piece of your code that does the ATO?
It is only the very first run of loop that you don't have things initialized.
The function that reads everything is ShowInterface().
So, in the very first pass, everything is zero.

Here is my entire code... A bit long... But I have been trying to remark as much stuff as possible to make it easy to find and understand. I have "//*****Begin ATO By Salinity Additions" Code sections and other code sections remarked...

Code: Select all

    #include <ReefAngel_Features.h>
    #include <Globals.h>
    #include <RA_Wifi.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <Time.h>
    #include <DS1307RTC.h>
    #include <InternalEEPROM.h>
    #include <RA_NokiaLCD.h>
    #include <RA_ATO.h>
    #include <RA_Joystick.h>
    #include <LED.h>
    #include <RA_TempSensor.h>
    #include <Relay.h>
    #include <RA_PWM.h>
    #include <Timer.h>
    #include <Memory.h>
    #include <RA_Colors.h>
    #include <RA_CustomColors.h>
    #include <Salinity.h>
    #include <RF.h>
    #include <IO.h>
    #include <ORP.h>
    #include <AI.h>
    #include <PH.h>
    #include <WaterLevel.h>
    #include <ReefAngel.h>

    ////// Place global variable code below here


    // Initialize Alert variables
    byte AlertManual=0;
    byte AlertATOPump=0;
    byte AlertNonCritical=0;
    byte AlertCritical=0;
    byte overheatflag=0;
    byte atoflag=0;
    byte iochannel0flag=0;
    byte iochannel1flag=0;
    byte iochannel2flag=0;
    byte iochannel3flag=0;
    byte iochannel4flag=0;
    byte iochannel5flag=0;


    //*****Begin Light Mask Timer Additions
    byte LightMaskRemaining=0;
    byte CurrentLightMask=0;
    byte PreviousLightMask=255;
    byte IgnoreMaskDuration; //manual switch to disable automatic Light Mask timeout (0=normal, != 0 = Ignore Light Mask timeout)
    byte MaskDuration; //Mask timer length in minutes 0 - 255
    long TargetMillis; //End of Timer in Millis 
    long CurrentMillis; //Current Time in Millis
    long InitialMillis; //Start Time in Millis
   
    //*****End Light Mask Timer Additions


    //*****Begin reporting of Maximum\Minimum Temperature on probe T1 Additions
    int T1LowTemp=999;
    int T1HighTemp=1;
    int T1Read=1;
 
    //*****End reporting of Maximum\Minimum Temperature on probe T1 Additions

    //*****Begin WaterChange Additions

    // skimmer port
    byte SkimmerPort = Port4;
    // return port
    byte ReturnPort = Port3;
    // sump drain port
    byte SumpDrainPort = Port8;
    // SaltWater brute pump
    byte SWBrutePort = Port7;
    // Timer for countdowns
    TimerClass tm;

    //*****End WaterChange Additions


    //*****Begin ATO By Salinity Additions

    byte ATOBrutePort = Port2;

    //*****End ATO By Salinity Additions


    //*****Begin Custom IO Expander Additions

    byte CustomIOExpander = 255;

    //*****End Custom IO Expander Additions


    ////// Place global variable code above here


    //*****Begin Custom Menu Additions

    #include <avr/pgmspace.h>
    prog_char menu1_label[] PROGMEM = "Mask LED's On";
    prog_char menu2_label[] PROGMEM = "Mask LED's Off";
    prog_char menu3_label[] PROGMEM = "Mask LED's Clear";
    prog_char menu4_label[] PROGMEM = "Water Change";
    prog_char menu5_label[] PROGMEM = "Clear ATO Timeout";
    prog_char menu6_label[] PROGMEM = "Overheat Clear";
    prog_char menu7_label[] PROGMEM = "PH Calibration";
    prog_char menu8_label[] PROGMEM = "Date / Time";

    // Group the menu entries together
    PROGMEM const char *menu_items[] =
      {
        menu1_label, menu2_label, menu3_label, menu4_label, menu5_label, menu6_label, menu7_label, menu8_label,
      };

    //*****End Custom Menu Additions


    void setup()
    {
        // This must be the first line
        ReefAngel.Init();  //Initialize controller

        //_Compiled_With_Libs_Version_1.1.0
        InternalMemory.write(110, 110);
   
        //_Running_Config_Revision_108
        InternalMemory.write(111, 108);

        //*****Begin Custom Menu Additions... Initialize Custom Menu

        ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));   

        //*****End Custom Menu Additions

        //*****Begin Light Mask Timer Additions

        if (InternalMemory.read(199) !=0) (InternalMemory.write(199, 0)); //sets the controller to non masked LED mode upon reboot.   

        //*****End Light Mask Timer Additions




        // Ports toggled in Feeding Mode
        ReefAngel.FeedingModePorts = 0;
        ReefAngel.FeedingModePortsE[0] = 0;
        // Ports toggled when Lights On / Off menu entry selected
        ReefAngel.LightsOnPorts = 0;
        ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit;
        // Ports turned off when Overheat temperature exceeded
        ReefAngel.OverheatShutoffPorts = Port4Bit | Port5Bit | Port6Bit;
        ReefAngel.OverheatShutoffPortsE[0] = 0;
        // Use T1 probe as temperature and overheat functions
        ReefAngel.TempProbe = T1_PROBE;
        ReefAngel.OverheatProbe = T1_PROBE;
        // Set the Overheat temperature setting
        InternalMemory.OverheatTemp_write( 850 );


        // Ports that should always be on/off at startup 
        ReefAngel.Relay.On( Port3 );//Turns 180G Return Pump ON if controller reboots
        ReefAngel.Relay.Off( Port2 );//Turns 180G RO/DI Topoff OFF if controller reboots
        ReefAngel.Relay.Off( Port7 );//Turns 180G SW Topoff OFF if controller reboots
        ReefAngel.Relay.Off( Port8 );//Turns 180G Sump Drain OFF if controller reboots
        ReefAngel.Relay.On( Box1_Port5 );//Turns 20GH QT Return Pump ON if controller reboots
        ReefAngel.Relay.On( Box1_Port6 );//Turns 29G QT Return Pump ON if controller reboots
        ReefAngel.Relay.On( Box1_Port7 );//Turns 20GH QT MaxiJet Pump ON if controller reboots
        ReefAngel.Relay.On( Box1_Port8 );//Turns 29G QT MaxiJet Pump ON if controller reboots
        

        ////// Place additional initialization code below here

        ReefAngel.CustomVar[0]=0;
        ReefAngel.CustomVar[1]=0;
        ReefAngel.CustomVar[2]=0;
        ReefAngel.CustomVar[3]=0;
        ReefAngel.CustomVar[4]=0;
        ReefAngel.CustomVar[5]=0;
        ReefAngel.CustomVar[6]=0;   
        ReefAngel.CustomVar[7]=0;
   
   
        ////// Place additional initialization code above here
    }

    void loop()
    {
        ReefAngel.StandardFan( Port1,790,820 );
        ReefAngel.Relay.DelayedOn( Port4,1 );
        ReefAngel.WavemakerRandom( Port5,30,100 );
        ReefAngel.StandardHeater( Port6,750,760 );
        ReefAngel.StandardHeater( Box1_Port3,750,760 );
        ReefAngel.StandardHeater( Box1_Port4,750,760 );


    //*****Begin Custom Menu Additions
    //*****Begin Light Mask Timer Additions                   

      //LightMaskRemaining = ( TargetMillis - CurrentMillis ) / 3600000;//Display Light Mask Time Remaining in Hours
      LightMaskRemaining = ( TargetMillis - CurrentMillis ) / 60000;//Display Light Mask Time Remaining in Minutes          
      //LightMaskRemaining = ( TargetMillis - CurrentMillis ) / 1000;//Display Light Mask Time Remaining in seconds
      CurrentLightMask = InternalMemory.read(199);//reads current light mask setting
      MaskDuration = InternalMemory.read (198);  //Mask timer length in minutes 0 - 255 (0:00 - 4:15)       
      IgnoreMaskDuration = InternalMemory.read (197); //manual switch to disable automatic Light Mask timeout (0=normal, != 0 = Ignore Light Mask timeout)
      CurrentMillis = millis();//update the timer to the current count
      
        // Removes LED's from a "MASKED" State
      if ( CurrentLightMask == 0 )
        {
          ReefAngel.PWM.SetChannel( 0, PWMParabola(14,0,23,59,1,100,1) ); //Sets LED Drivers on Ch0 to Parabola math
          ReefAngel.PWM.SetChannel( 1, PWMParabola(14,0,23,59,1,100,1) ); //Sets LED Drivers on Ch1 to Parabola math
          ReefAngel.PWM.SetChannel( 3, PWMSlope(2,0,7,30,0,50,0,0) ); //Opens/closes 5V relay on Ch3 that shorts\opens dimmer leads on Ch0 LED driver to turn Driver on/off
          ReefAngel.PWM.SetChannel( 4, PWMSlope(0,0,14,0,0,50,0,0) ); //Opens/closes 5V relay on Ch4 that shorts\opens dimmer leads on Ch1 LED driver to turn Driver on/off
          ReefAngel.StandardLights( Box1_Port1,13,0,23,0 ); //turns QT Light schedule on if not masked off
          ReefAngel.StandardLights( Box1_Port2,13,0,23,0 ); //turns QT Light schedule on if not masked off
        }

      if ( PreviousLightMask != CurrentLightMask )//Checks if the light mask setting has been changed
        {

          //Checks if light mask value has been set to an invalid value by direct memory access and clears (sets to 0) mask if not valid
        if ( CurrentLightMask > 2 ) 
          {
            InternalMemory.write(199, 0); //clears light mask if value is not valid. 
          }
  
        // MASKS LED's Off
        if ( CurrentLightMask == 1 )
          {
            TargetMillis = CurrentMillis + ( MaskDuration * 60000 ); //Set the duration of the mask timer in minutes ( 1 - 255 )
            ReefAngel.PWM.SetChannel( 0, 0 ); //Sets LED Drivers on Ch0 to 0%
            ReefAngel.PWM.SetChannel( 1, 0 ); //Sets LED Drivers on Ch1 to 0%
            ReefAngel.PWM.SetChannel( 3, 50 ); //closes 5V relay on Ch3 that shorts dimmer leads on Ch0 LED driver to turn Driver off
            ReefAngel.PWM.SetChannel( 4, 50 ); //closes 5V relay on Ch4 that shorts dimmer leads on Ch1 LED driver to turn Driver off
            ReefAngel.Relay.Off( Box1_Port1 ); //turns QT Lights OFF if masked off
            ReefAngel.Relay.Off( Box1_Port2 ); //turns QT Lights OFF if masked off
          }

        // MASKS LED's On
        if ( CurrentLightMask == 2 )
          {
            TargetMillis = CurrentMillis + ( MaskDuration * 60000 ); //Set the duration of the mask timer in minutes ( 1 - 255 )
            ReefAngel.PWM.SetChannel( 0, 100 ); //Sets LED Drivers on Ch0 to 100%
            ReefAngel.PWM.SetChannel( 1, 100 ); //Sets LED Drivers on Ch1 to 100%
            ReefAngel.PWM.SetChannel( 3, 0 ); //Opens 5V relay on Ch3 that removes short on dimmer leads on Ch0 LED driver to turn Driver on
            ReefAngel.PWM.SetChannel( 4, 0 ); //Opens 5V relay on Ch4 that removes short on dimmer leads on Ch1 LED driver to turn Driver on
            ReefAngel.Relay.On( Box1_Port1 ); //turns QT Lights ON if masked on
            ReefAngel.Relay.On( Box1_Port2 ); //turns QT Lights ON if masked on
          }
        
        PreviousLightMask = CurrentLightMask;
        }

        if ( CurrentLightMask != 0 )// Checks if lights are masked on or off
          {
            if ( IgnoreMaskDuration == 0 )//Checks if Light mask timer ignore byte is active
              {
                if ( CurrentMillis > TargetMillis )//checks if Light mask timeout has expired.
                  {
                    InternalMemory.write(199, 0); //clears forgotten light mask due to timeout. 
                    CurrentMillis = 0;//sets back to 0 when not being used to prevent display from counting negative time when Light mask is cleared.
                    TargetMillis = 0;//sets back to 0 when not being used to prevent display from counting negative time when Light mask is cleared.
                  }

                else
                  {
                  }          

              }
              
            else
              {
                CurrentMillis = 0;//sets back to 0 when not being used to prevent display from counting negative time when Light mask is cleared.
                TargetMillis = 0;//sets back to 0 when not being used to prevent display from counting negative time when Light mask is cleared.
              }

          }              

        else
          {
            CurrentMillis = 0;//sets back to 0 when not being used to prevent display from counting negative time when Light mask is cleared.
            TargetMillis = 0;//sets back to 0 when not being used to prevent display from counting negative time when Light mask is cleared.
          }
              
              
    //*****End Custom Menu Additions
    //*****End Light Mask Timer Additions

    //*****Begin reporting of Maximum\Minimum Temperature on probe T1 Additions

        T1Read = ReefAngel.Params.Temp[T1_PROBE];
          if (T1Read !=0)//Debounce for Low Temperature reading 0 at startup 
            {
              T1LowTemp = min(T1LowTemp, T1Read);//Tracks Low Temperature
              T1HighTemp = max(T1HighTemp, T1Read);//Tracks High Temperature
            }
         
    //*****End reporting of Maximum\Minimum Temperature on probe T1 Additions


        overheatflag = InternalMemory.read( Overheat_Exceed_Flag );
        atoflag = InternalMemory.read( ATO_Exceed_Flag );
        iochannel0flag = ! ReefAngel.IO.GetChannel( 0 );
        iochannel1flag = ! ReefAngel.IO.GetChannel( 1 );
        iochannel2flag = ! ReefAngel.IO.GetChannel( 2 );
        iochannel3flag = ! ReefAngel.IO.GetChannel( 3 );
        iochannel4flag = ! ReefAngel.IO.GetChannel( 4 );
        iochannel5flag = ! ReefAngel.IO.GetChannel( 5 );
        AlertManual = InternalMemory.read (112);  //Manul Switch to turn on buzzer          
        AlertATOPump = ReefAngel.Relay.Status(Port2);
        AlertNonCritical = atoflag + iochannel2flag + iochannel3flag + iochannel4flag + iochannel5flag;
        AlertCritical = AlertManual + AlertATOPump + overheatflag + iochannel0flag + iochannel1flag;   
        if ( AlertNonCritical >= 1 ) AlertNonCritical = 25;
        if ( AlertCritical >= 1 ) AlertCritical = 25;   
        if ( AlertNonCritical >= 1 ) ReefAngel.PWM.SetActinic(millis()%60000<100?AlertNonCritical:0);
        if ( AlertNonCritical >= 1 ) ReefAngel.PWM.SetDaylight(millis()%60000<100?AlertNonCritical:0);
        if ( AlertCritical >= 1 ) ReefAngel.PWM.SetActinic(millis()%300<100?AlertCritical:0);
        if ( AlertCritical >= 1 ) ReefAngel.PWM.SetDaylight(millis()%300<100?AlertCritical:0);   

       
        ////// Place your custom code below here

        ReefAngel.CustomVar[0]=InternalMemory.read(ATO_Exceed_Flag);
        ReefAngel.CustomVar[1]=InternalMemory.read(Overheat_Exceed_Flag);
        ReefAngel.CustomVar[2]=CustomIOExpander;
        ReefAngel.CustomVar[3]=AlertManual;
        ReefAngel.CustomVar[4]=LightMaskRemaining;
        ReefAngel.CustomVar[5]=AlertNonCritical;
        ReefAngel.CustomVar[6]=AlertCritical;   
        ReefAngel.CustomVar[7]=ATOBrutePort;
       
        if ( ReefAngel.CustomVar[0]== 1 )
          {
            ReefAngel.Relay.RelayMaskOff=~(Port4Bit);
          }

        //*****Begin WC Additions

        // If menu equals waterchange mode
        // then we start the automatic water change
        // Otherwise we ignore and proceed
        if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE)
          {
            AutoWaterChange();
          }
       
        //*****End WC Additions
       
       
        //*****Begin ATO By Salinity Additions
       
        if (ReefAngel.Params.Salinity<300)
          {
            ATOBrutePort=Port7;
          }
        else
          {
            ATOBrutePort=Port2;
          }
        ReefAngel.StandardATO(ATOBrutePort,40 );
        if (iochannel2flag == 1)
          {
            ReefAngel.Relay.RelayMaskOff=~(Port7Bit);
          }
        if (iochannel4flag == 1)
          {
            ReefAngel.Relay.RelayMaskOff=~(Port2Bit);
          }
         
        //*****End ATO By Salinity Additions

        ////// Place your custom code above here

        // This should always be the last line
        ReefAngel.Portal( "00Warpig00" );
        ReefAngel.ShowInterface();
    }


    //*****Begin Custom Menu Additions

    //Mask Lights On. Forces Lights's On Full Blast
    void MenuEntry1()
      {
        InternalMemory.write(199, 2);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Mask Lights On"); waitForTime(2);
        ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
      }

    //Mask Lights Off. Forces Lights Off
    void MenuEntry2()
      {
        InternalMemory.write(199, 1);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Mask Lights Off"); waitForTime(2);
        ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
      }

    //Mask Lights Clear. Remove Light Masking Returns Lights to normal schedule
    void MenuEntry3()
      {
        InternalMemory.write(199, 0);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Mask Lights Clear"); waitForTime(2);
        ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
      }
     
    //Start Waterchange Mode
    void MenuEntry4()
      {
        ReefAngel.WaterChangeModeStart();
      }

    //Clear ATO Timeout Flag
    void MenuEntry5()
      {
        ReefAngel.ATOClear();
        ReefAngel.DisplayMenuEntry("Clear ATO Timeout");
      }

    //Clear Overheat Flag
    void MenuEntry6()
      {
        ReefAngel.OverheatClear();
        ReefAngel.DisplayMenuEntry("Clear Overheat");
      }

    //Calibrate PH Probe
    void MenuEntry7()
      {
        ReefAngel.SetupCalibratePH();
        ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
      }

    //Set clock Date & Time
    void MenuEntry8()
      {
        ReefAngel.SetupDateTime();
        ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
      }
     
    //*****End Custom Menu Additions


    //*****Begin Water Change Additions

    void AutoWaterChange()
    {
        // auto water change mode
        // Display Starting Water Change"
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Starting Water Change"); waitForTime(3);

        // Check Saltwater BRUTE for sufficient saltwater on IO Module Port2
        if ( isSWBruteEmpty() )
          {
            ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
            ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Not Enough Saltwater"); waitForTime(3);

            //Abort Water Change if insufficient saltwater
            // Handles the cleanup to return to the main screen
            ReefAngel.ClearScreen(DefaultBGColor);
            ReefAngel.DisplayedMenu = DEFAULT_MENU;
            DrawCustomGraph();
            return;
          }
       
        //Display Disabling ATO Pump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");   
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Disabling ATO Pump"); waitForTime(3);

        // turn off ATO pump port to prevent ATO from trying to fill a sump being drained intentionally
        ReefAngel.Relay.RelayMaskOff=~(Port2Bit);
       
        //Display Stopping Skimmer
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stopping Skimmer"); waitForTime(3);

        // turn off the skimmer port
        ReefAngel.Relay.Off(SkimmerPort);
        ReefAngel.Relay.Write();
       
        //Display Skimmer Draining
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Skimmer Draining"); waitForTime(3);   

        // wait for 1 minute
        waitForTime(60);

        //Display Skimmer Done Draining
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Skimmer Done Draining"); waitForTime(3);
       
        //display Stopping Return Pump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stopping Return Pump"); waitForTime(3);

        //Stop Return Pump
        ReefAngel.Relay.Off(ReturnPort);
        ReefAngel.Relay.Write();
       
        //Display Draining To Sump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Draining To Sump"); waitForTime(3);

        //display Sump Filling
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Filling"); waitForTime(3);

        // wait for IO Mod Port 1 to be active
        waitForIOChannel(1);

        //display Sump Is Full
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Is Full"); waitForTime(3);

        //Display Sump Settling
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settling"); waitForTime(3);

        // wait for sump to settle
        waitForTime(30);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settled"); waitForTime(3);

        // display Draining Sump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Start Draining Sump"); waitForTime(3);

        //turn on sump drain pump
        ReefAngel.Relay.On(SumpDrainPort);
        ReefAngel.Relay.Write();

        //display Sump Draining
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Draining"); waitForTime(3);

        // wait for sump empty port active, IO Mod Port 0
        waitForIOChannel(0);
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Is Empty"); waitForTime(3);

        //display Stopping Sump Draining
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stopping Sump Drain"); waitForTime(3);

        // turn off sump drain
        ReefAngel.Relay.Off(SumpDrainPort);
        ReefAngel.Relay.Write();

        //Display Sump Settling
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settling"); waitForTime(3);

        // wait for sump to settle
        waitForTime(30);

        //display Sump Settled
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settled"); waitForTime(3);

        //display Starting Saltwater Pump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Start Saltwater Pump"); waitForTime(3);

        //turn on Saltwater Pump
        ReefAngel.Relay.On(SWBrutePort);
        ReefAngel.Relay.Write();

        //display Saltwater Pumping
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Saltwater Pumping"); waitForTime(3);

        // wait for sump full float switch active, IO Mod Port 1
        waitForIOChannel(1);

        //display Stop Saltwater Pump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Stop Saltwater Pump"); waitForTime(3);

        // turn off sw brute pump
        ReefAngel.Relay.Off(SWBrutePort);
        ReefAngel.Relay.Write();   

        //diasplay Sump is Full
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Is Full"); waitForTime(3);

        //Display Sump Settling
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settling"); waitForTime(3);

        // wait for sump to settle
        waitForTime(30);

        //display Sump Settled
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Sump Settled"); waitForTime(3);
       
        //display Starting Return Pump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Starting Return Pump"); waitForTime(3);

        // turn on return pump
        ReefAngel.Relay.On(ReturnPort);
        ReefAngel.Relay.Write();

        //display Return Pump Started
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Return Pump Started"); waitForTime(3);

        //display Normalizing Waterlevel
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Normalizing Waterlevel"); waitForTime(3);

        //waiting 2 minutes for waterlevel to normalize
        waitForTime(120);
       
        //display Starting Skimmer
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Starting Skimmer"); waitForTime(3);

        //turn on skimmer
        ReefAngel.Relay.On(SkimmerPort);
        ReefAngel.Relay.Write();

        //display Normalizing Skimmer
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Normalizing Skimmer"); waitForTime(3);

        //wait for 2 minutes for skimmer to normalize
        waitForTime(120);

        //display Skimmer Normalized
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Skimmer Normalized"); waitForTime(3);

        //display Enabling ATO Pump
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Enabling ATO Pump"); waitForTime(3);

        //Enable ATO pump
        ReefAngel.Relay.RelayMaskOff = B11111111;
        ReefAngel.Relay.Write();

        //display Water Change Complete
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "                      ");
        ReefAngel.LCD.DrawText(ModeScreenColor, DefaultBGColor, 2, 30, "Water Change Complete"); waitForTime(3);

        // Handles the cleanup to return to the main screen
        ReefAngel.ClearScreen(DefaultBGColor);
        ReefAngel.DisplayedMenu = DEFAULT_MENU;
        DrawCustomGraph();
    }

    bool isSWBruteEmpty()
    {
      // check status of IO Mod Port 2
      if ( ! ReefAngel.IO.GetChannel(2) )
          return true;
      return false;
    }

    void waitForTime(int seconds)
    {
        bool done = false;
        tm.SetInterval(seconds);
        tm.Start();
        int t = tm.Trigger - now();
        do
        {
          // check the wifi interface
          pingSerial();
          // wait for specified seconds
          if ( (t >= 0) && ! tm.IsTriggered() )
            {
              wdt_reset();
              delay(200);
            }
            else
            {
              done = true;
            }
        } while ( !done );
        return;
    }

    void waitForIOChannel(byte channel)
    {
        // TODO complete this function
        do
        {
          wdt_reset();
          // display something on screen
          // check the wifi interface
          pingSerial();
          delay(200);
          // TODO check the IO channel logic
        } while ( ReefAngel.IO.GetChannel(channel) );
    }

    //*****End Water Change Additions


    //*****Begin Custom IO Expander Additions

        byte expanderRead()
        {
          byte _data=0;
          Wire.requestFrom(0x27, 1);
          if(Wire.available())
            {
            _data = Wire.read();
            CustomIOExpander = _data;
            }
          delay(10);
          return _data;
        }
       
        boolean expanderReadGetChannel(byte channel)
        {
          return bitRead(expanderRead(),channel);
        }

    //*****End Custom IO Expander Additions
       

    void DrawCustomMain()
    {
        int x,y;
        char text[10];
        // Dimming Expansion
        x = 15;
        y = 2;
        for ( int a=0;a<6;a++ )
        {
          if ( a>2 ) x = 75;
          if ( a==3 ) y = 2;
          ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :   " );
          ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a );
          ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,ReefAngel.PWM.GetChannelValue(a) );
          y += 10;
        }
        pingSerial();

        // I/O Expansion
        byte bkcolor;
        x = 14;
        y = 34;
        for ( int a=0;a<6;a++ )
        {
          ReefAngel.LCD.DrawCircleOutline( x+(a*20),y,4,COLOR_MEDIUMORCHID );
          if ( ReefAngel.IO.GetChannel(a) ) bkcolor=COLOR_WHITE; else bkcolor=COLOR_GRAY;
          ReefAngel.LCD.FillCircle( x+(a*20),y,2,bkcolor );
        }
        pingSerial();

        // Parameters
    #if defined DisplayLEDPWM && ! defined RemoveAllLights
        ReefAngel.LCD.DrawMonitor( 15, 44, ReefAngel.Params,
        ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
    #else // defined DisplayLEDPWM && ! defined RemoveAllLights
        ReefAngel.LCD.DrawMonitor( 15, 44, ReefAngel.Params );
    #endif // defined DisplayLEDPWM && ! defined RemoveAllLights
        pingSerial();

        // Salinity
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,73, "SAL:" );//Display Salinity
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,82, "LMTR:" );//Display Light Mask Time Remaining
//        ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,45,82, "  Hours." );//Clear screen video from data location before new data draw          
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,45,82, "    Min." );//Clear screen video from data location before new data draw
//        ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,45,82, "      Sec." );//Clear screen video from data location before new data draw          
//        ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,45,82, ( TargetMillis - CurrentMillis ) / 3600000 );//Display Light Mask Time Remaining in Hours
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,45,82, ( TargetMillis - CurrentMillis ) / 60000 );//Display Light Mask Time Remaining in Minutes          
//        ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,45,82, ( TargetMillis - CurrentMillis ) / 1000 );//Display Light Mask Time Remaining in seconds
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,60,73, "L:" );//Display Low Temperature   
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,96,73, "H:" );//Display High Temperature       
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,73, ReefAngel.Params.Salinity );//Display Salinity
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,72,73, T1LowTemp );//Display Low Temperature
          ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,108,73, T1HighTemp );//Display High Temperature   

        pingSerial();

        // Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox( 12, 90, TempRelay );
        pingSerial();

        // Relay Expansion
        TempRelay = ReefAngel.Relay.RelayDataE[0];
        TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
        TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
        ReefAngel.LCD.DrawOutletBox( 12, 104, TempRelay );
        pingSerial();

        // Date and Time
        ReefAngel.LCD.DrawDate( 6, 122 );
        pingSerial();
    }

    void DrawCustomGraph()
    {
    }

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Buzzer on while ATO pump relay is active

Post by rimai »

Yes, this is going to behave just like you said:

Code: Select all

        if (ReefAngel.Params.Salinity<300)
          {
            ATOBrutePort=Port7;
          }
        else
          {
            ATOBrutePort=Port2;
          }
        ReefAngel.StandardATO(ATOBrutePort,40 );
It will also cause the problem if the Salinity is at 301 and while the ATO is on, it fluctuates to 299. The other port will always stay on.
I think if you do it this way, you ensure that the other port will be off:

Code: Select all

        if (ReefAngel.Params.Salinity<300)
          {
            ReefAngel.StandardATO(Port7,40 );
            ReefAngel.Relay.Off(Port2);
            ATOBrutePort=Port7;
          }
        else
          {
            ReefAngel.StandardATO(Port2,40 );
            ReefAngel.Relay.Off(Port7);
            ATOBrutePort=Port2;
          }
Roberto.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

I will give that a try. That makes total sense. Control both ports in each of the two possible scenarios not just one.

can I do a ShowInterface() during the setup code to initialize all the hardware values? If not how about very early in my loop? Seems there might be some reasons to not do ShowInterface() that early that I may be overlooking. Or can ShowInterface() be called twice in the code. Once early and once in its current location in the code (which is pretty deep into my code).

I will bet the second scenario (not a reboot) is what caused my last overflow. When the ATO started the level was at 299. If you really think about the code the goal of the code is to keep my tank right at 300. so if it was balancing at 299/300/299/300 when the line of code ran for the ATO on the next loop it happened to be at 299 and kicked on the saltwater which upped the salinity to 300 or 301 switched back to the RO port and tried to shut it down. leaving the saltwater port active all day.

Nick
Last edited by 00Warpig00 on Sat Jun 28, 2014 7:51 am, edited 1 time in total.
180G FOWLR
20GH QT#1
29G QT#2

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Buzzer on while ATO pump relay is active

Post by rimai »

Technically you can, but it is inside that function that the relays change state based on what you coded before the function.
For example ReefAngel.Relay.On(Port1) doesn't really turn the port on. It prepares the port to be turned on by assigning a value to a hidden variable. Then, when ShowInterface is called, that's when it will actually turn the port on.
I think it is best for optimization if you do one in setup instead of two in loop.
The main reason we changed to the end was that at reboot, the relays were all turning off and back on for a split of a second if the function is placed at beginning.
So, you may experience that if you add a ShowInterface inside setup.
Roberto.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

ahh ok. it sounds like if I do call ShowInterface() in the setup it wont matter unless I also initialize all of the "hidden variables" I need initialized before the ShowInterface().

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

could I also debounce the Salinity probe by doing something like the following

Code: Select all

        if (ReefAngel.Params.Salinity<100)
          {
            ReefAngel.Relay.Off(Port2);
            ReefAngel.Relay.Off(Port7);
          }
        else
        if (ReefAngel.Params.Salinity<300)
          {
            ReefAngel.StandardATO(Port7,40 );
            ReefAngel.Relay.Off(Port2);
            ATOBrutePort=Port7;
          }
        else
          {
            ReefAngel.StandardATO(Port2,40 );
            ReefAngel.Relay.Off(Port7);
            ATOBrutePort=Port2;
          }
(edit) redundant... because first loop both the first two IF's will run.

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

So in my setup...

Do I still need this

Code: Select all

    //*****Begin ATO By Salinity Additions

    byte ATOBrutePort = Port2;
or should I change it to Port7 since at startup Port7 will become my ATO port in the first loop due to salinity being 0 anyhow. Thinking about it... I guess it really doesn't much matter what it is initialized as...

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Buzzer on while ATO pump relay is active

Post by rimai »

I don't think it matters now.
That code should be able to handle the state changes properly.
Roberto.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

This seems to be working 95% of what I am hoping for...

The ATO selection code I am working with for now is as follows

Code: Select all

        //*****Begin ATO By Salinity Additions
        
        if (ReefAngel.Params.Salinity<300)//if salinity is low switch to Saltwater ATO
          {
            ReefAngel.StandardATO(Port7,40 );//ATO Port is now Saltwater Port7
            ReefAngel.Relay.Off(Port2);//Turn off RO/DI Port2 
            ATOBrutePort=Port7;
            char ATOBruteText[ ] = "ATOSW";
          }
        else//if Salinity is high switch to RO/DI Topoff
          {
            ReefAngel.StandardATO(Port2,40 );//ATO Port is now RO/DI Port2
            ReefAngel.Relay.Off(Port7);//Turn off Saltwater Port7
            ATOBrutePort=Port2;
            char ATOBruteText[ ] = "ATORO";
          }        
        if (iochannel2flag == 1)//IF ATO Brute is empty do not pump
          {
            ReefAngel.Relay.RelayMaskOff=~(Port7Bit);//Mask Off Saltwater Brute Pump 
          }
        if (iochannel4flag == 1)//IF ATO Brute is empty do not pump
          {
            ReefAngel.Relay.RelayMaskOff=~(Port2Bit);//Mask Off RO/DI Brute Pump
          }
         
        //*****End ATO By Salinity Additions

The Buzzer code seems to mostly work. For some reason The buzzer gets stuck on at 25 about 50% of the time the ATO tops off. All the alert variables return to 0 but the
ReefAngel.PWM.SetActinic & ReefAngel.PWM.SetDaylight I am guessing need an else statement to insure they are off when the variable drops back from 25 to 0.

my current (not quite right) code is below.

Code: Select all

        overheatflag = InternalMemory.read( Overheat_Exceed_Flag );
        atoflag = InternalMemory.read( ATO_Exceed_Flag );
        iochannel0flag = ! ReefAngel.IO.GetChannel( 0 );
        iochannel1flag = ! ReefAngel.IO.GetChannel( 1 );
        iochannel2flag = ! ReefAngel.IO.GetChannel( 2 );
        iochannel3flag = ! ReefAngel.IO.GetChannel( 3 );
        iochannel4flag = ! ReefAngel.IO.GetChannel( 4 );
        iochannel5flag = ! ReefAngel.IO.GetChannel( 5 );
        AlertATOPump = ReefAngel.Relay.Status(Port2);
        AlertNonCritical = atoflag + iochannel2flag + iochannel3flag + iochannel4flag + iochannel5flag;
        AlertCritical = AlertATOPump + overheatflag + iochannel0flag + iochannel1flag;   
        if ( AlertNonCritical >= 1 ) AlertNonCritical = 25;
        if ( AlertCritical >= 1 ) AlertCritical = 25;   
        if ( AlertNonCritical >= 1 ) ReefAngel.PWM.SetActinic(millis()%60000<100?AlertNonCritical:0);
        if ( AlertNonCritical >= 1 ) ReefAngel.PWM.SetDaylight(millis()%60000<100?AlertNonCritical:0);
        if ( AlertCritical >= 1 ) ReefAngel.PWM.SetActinic(millis()%300<100?AlertCritical:0);
        if ( AlertCritical >= 1 ) ReefAngel.PWM.SetDaylight(millis()%300<100?AlertCritical:0);   

Guessing I need to change the bottom 4 if statements of the above to be something like this.

Code: Select all

        if ( AlertNonCritical >= 1 ) ReefAngel.PWM.SetActinic(millis()%60000<100?AlertNonCritical:0);
        else { ReefAngel.PWM.SetActinic(0) }
        if ( AlertNonCritical >= 1 ) ReefAngel.PWM.SetDaylight(millis()%60000<100?AlertNonCritical:0);
        else { ReefAngel.PWM.SetDaylight(0) }
        if ( AlertCritical >= 1 ) ReefAngel.PWM.SetActinic(millis()%300<100?AlertCritical:0);
        else { ReefAngel.PWM.SetActinic(0) }
        if ( AlertCritical >= 1 ) ReefAngel.PWM.SetDaylight(millis()%300<100?AlertCritical:0);   
        else { ReefAngel.PWM.SetDaylight(0) }

Not sure of my syntax above, but I am guessing that's what I need to do to be sure the buzzer turns OFF

Also, I realize I am using both my PWM ports for the buzzer. Did that because both were unused and I made it so it did not matter which port I plugged the buzzer into.

That will be changing after I return from my business trip. I just purchased my Eheim auto feeder yesterday and have been gathering my parts 5V relay\3V ac adapter etc to modify it and hook it up to the other port when I return from my trip. Gonna leave it on timer feed for now while I am gone.

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

So my ATO is acting funny still after all.

1.ATO float switch triggers top off

2.correct pump starts to pump for ATO.

3.Buzzer does it's thing to warn me it's topping up.

4.about 4 seconds into the topoff the pump shuts down and the buzzer stop.

5. 35 seconds later my ATO times out. Red light skimmer shuts down ato flag is set.

my ATO timer is set at 40 seconds. Why would the pump turn off 4 seconds or so in but the ATO still time out?

This seems to happen very frequently. 80% of the ATO cycles.

confused... Seems like the pump knows the ATO cycle is over and turns off but the controller continues to count to 40 and times out.

Nick
180G FOWLR
20GH QT#1
29G QT#2

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Buzzer on while ATO pump relay is active

Post by rimai »

I just tested the code to be sure and seems to be working fine.
Is 4 seconds enough to make your water level rise from the bottom float and activate the top float?
Seems very short to me.
Roberto.
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

yes 4 to 8 seconds for a top off is not uncommon. my low and high float water levels are really close together in my sump.

normally (no water needed state) my float switches sit at ATO Low = Off & ATO High = 0n
If I remove 1/4 cup of water (with a measuring cup) from my sump my ATO High switch changes to Off so both High and Low switches report off. If I remove an additional 3/4 cup (with a measuring cup) of water from my sump The ATO Low Switch will change to On so High will be Off and Low will be on. Also my ATO pump is either a Maxijet 600 (filling with RO) or a Maxijet 1200 (filing with SW). Total pump on time seems to average around 8 seconds although it takes a couple seconds for water to hit the sump after it kicks on because the supply container is at the other end of about 10 feet of 3/8 id hose.

Just strange. I have never had issues with my ATO timing out in the past with this setup.
180G FOWLR
20GH QT#1
29G QT#2

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Buzzer on while ATO pump relay is active

Post by rimai »

Are you sure there is not an override for port 2 or port7 somewhere else in the code?
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Buzzer on while ATO pump relay is active

Post by lnevo »

Where's the full code listed?
00Warpig00
Posts: 289
Joined: Wed May 16, 2012 9:52 pm

Re: Buzzer on while ATO pump relay is active

Post by 00Warpig00 »

I do not see another override for port 2 or 7 except for in waterchange mode...

Full code is here. Way down at the bottom. Version 109. I did make a few slight changes per my ideas a few posts above about the buzzer locking on. So now I am running my Version 110 (also at the end of that thread).

In the past few days with an ATO happening a few times a day running my Version 110 The ATO has not timed out even once nor has the buzzer locked on (buzzing).

http://forum.reefangel.com/viewtopic.php?f=11&t=4722

I may have resolved the issue, not sure. If I did I'm not sure why my changes made any difference tot he ATO timeout. I only expected changes with the buzzer not locking on.

Nick

I have made a code change
180G FOWLR
20GH QT#1
29G QT#2

Image
Post Reply