ATO code is not working properly.

Do you have a question on how to do something.
Ask in here.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

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

Re: ATO code is not working properly.

Post by Sacohen »

Lee;

Again thanks for all your help and even posting this modified code for the pump change.
Is there anything I need to to in the portal to activate it or will it start working randomly once it is uploaded?

I know it only changes modes once a day or after every reboot.

If there was a particular mode that I wanted (say short pulse) for a little bit,would I just change it in the portal and then on the next day or reboot it will kick into random mode again?

Finally do any of the speed and duration setting need to be set in the portal for this to work or is just works with my parameters of 40% speed with a 20% variation for the other modes?

Sorry for all the questions I jut want to make sure I understand how it works.

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

Re: ATO code is not working properly.

Post by lnevo »

If you look at the code where I'm calling elsemode i replaced 40 with the speed setting in the portal. I left the 20% but you could change it to use duration instead for that param (thats what i do :))

If you are in custom mode it will use the random mode for that day. If you want something different just change it on the portal but you'll have to change it back to go back to the random/custom mode.

In my INO i have a separate memory variable that i use so i can change the custom sub-mode but that's getting more complicated because no easy way to change it...but if you want it we can do it..
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

Still having issues with the ATO coming on for 2-5 seconds every 30 seconds or so.
Very strange.
The only thing I have changed is I switched the DeNit_Pump and DeNit_Doser to the way they should be.
Before I wrote this post I went back to a saved copy of the code before I changed anything and it is still doing it.

Salinity is 35.6ppt and WL is at the lower limit of 31%.

If it drops below 31% the pump should kick in and and stay on until it reached the upper limit of 34%, but it kicks in for a couple of seconds until it gets above 31% and then shuts off. Then a min or so later it does it again.

This can get to be very annoying, especially since this ATO pump is so noisy when it is on.

Any ideas on why this is happening?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Is this during the process or is this all the time? If it's all the time, it's possible one of the other checks we made is shutting it off.. I doubt the high ato is getting reached... but maybe the switch is flakey? More likely is the salinity probe. I've seen my ph probe bounce around sometimes and when you look at my charts it is not a stable number.. we can probe this like so..

Code: Select all

  // Disable ATO if Salinity is below 33.5. 
  if (ReefAngel.Params.Salinity<335) 
    ReefAngel.Relay.Override(ATO_Pump,0); 
Put that instead of the current salinity check. What will happen is that it will mask off the port.. You're ATO timeout will also probably kick in and you'll see the blue (iphone) or green (android) or it will be OFF instead of AUTO in the portal. If this happens we know its the salinity probe.

What we'll need to do is put some time of countdown that we want to see salinity 33.5 for 10 seconds lets say before we disable the ATO. In this case we may want to leave it with the override so you can address the salinity.. but this way if it blips you aren't getting the micro bursts...
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

And if that doesn't do it, we can try shifting the same code to the ATO switch... one by one we'll find it.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

It happens all the time. The ATO during the process is working great.

I'll try switching out the Salinity code and see what happens.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

lnevo wrote:And if that doesn't do it, we can try shifting the same code to the ATO switch... one by one we'll find it.
Cool...sounds like probe jitter to me.

Roberto, i think i've seen sone code you've posted to help with that? I dont want to reinvent and troubleshoot the wheel :)
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: ATO code is not working properly.

Post by rimai »

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

Re: ATO code is not working properly.

Post by lnevo »

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

Re: ATO code is not working properly.

Post by Sacohen »

lnevo wrote:Is this during the process or is this all the time? If it's all the time, it's possible one of the other checks we made is shutting it off.. I doubt the high ato is getting reached... but maybe the switch is flakey? More likely is the salinity probe. I've seen my ph probe bounce around sometimes and when you look at my charts it is not a stable number.. we can probe this like so..

Code: Select all

  // Disable ATO if Salinity is below 33.5. 
  if (ReefAngel.Params.Salinity<335) 
    ReefAngel.Relay.Override(ATO_Pump,0); 
Put that instead of the current salinity check. What will happen is that it will mask off the port.. You're ATO timeout will also probably kick in and you'll see the blue (iphone) or green (android) or it will be OFF instead of AUTO in the portal. If this happens we know its the salinity probe.

What we'll need to do is put some time of countdown that we want to see salinity 33.5 for 10 seconds lets say before we disable the ATO. In this case we may want to leave it with the override so you can address the salinity.. but this way if it blips you aren't getting the micro bursts...
Ok I put that code in and the ATO_pump in the portal went to OFF and on my Andriod I have the green dot.

So this says the Salinity probe is causing the problem even thought the salinity level is 35.9 ppt and the code say to disable it if it is below 33.5 ppt?

What next?

Thanks for the help.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

It means your probe is fluctuating. I'll look through the code in the post Roberto mentioned...what we want to do is make sure salinity is at that level for x amount of time before we decide to turn off the ATO.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

Thank you.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

You can just disable the salinity safety for now until we get you code to reenable...

Or you can live with it...
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

Yes. that's fine.

Just put it back to what it was and comment it out is fine?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Comment it out. Doesnt matter which version :)
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

Done. I'll keep an ear open for it and see if it stay off or comes on and goes threw to 34%.

Update:

Last night it came on and stayed on until it reach 33% then shut off, so it seems to be working right.

Just need to figure out the code for the salinity, but that's not a rush.
I'm going to take a look at that thread and see if I can find it.

If I find something I'll post it here before inserting it in my code just to make sure.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Ok, that code actually did a lot of things, but it did help me to put this together....

Code: Select all

    // Track Salinity low duration
    static unsigned long lastGoodSal;
    static boolean lowSalFlag;
   
    // Salinity is good, update counter
    if (ReefAngel.Params.Salinity>=335) lastGoodSal=now(); 
    
    // Counter hasn't been updating in 120 seconds..
    if (now()-lastGoodSal>120) {
      lowSalFlag=true; // Salinity is definitely below 33.5
    } else {
      lowSalFlag=false; // Salinity back to normal
    }
    
    // Disable ATO if lowSalFlag is true
    if (lowSalFlag) ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
This will go right in place of the previous salinity check or whatever you currently left in place or commented :)

Code: Select all

 // Disable ATO if Salinity is below 33.5. 
  if (ReefAngel.Params.Salinity<335) 
    ReefAngel.Relay.Override(ATO_Pump,0); 
It would be helpful moving forward especially for readers of the thread and myself :) if you would post your latest and greatest working code assuming this piece works for you :) I'm fairly confident (I know it at least compiles...) but I've been there before too...Please test and let me know.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

I will try it in a bit.
I actually just created a PDE thread that I'm going to be storing the code and I'll add that to my signature.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

OK. It's working, kind of. The code you added to let the salinity stabilize is working.

What is going on is that it will start and run for 2 min (I didn't time it but it seems like 2 min) and then it will stop.

What's happening is as the RO water is going into the sump it is affecting the Salinity probe in the sump and bringing the reading below the 33.5ppt.

So if I extend the 120 period that you have it will let the pump run until it reaches the 34% level and will only disable the ATO if the salinity is below 33.5ppt before the ATO kicks in.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

You can do that or you could move your ATO outlet further from the probe.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

I'm going to re-plumb my system in the next week or so to work the chiller in. I'll try to get the ATO outlet further from the probe.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Lol you Floridians..everyone else is unplumbing their chillers!
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: ATO code is not working properly.

Post by Sacohen »

Here is the final working code.

Many thank to lnevo for his help in doing this.

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 <InternalEEPROM.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 <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>

// Define Relay Ports by Name
#define Actinic_Lights     1
#define Day_Lights         2
#define Unused             3
#define Pumps              4
#define Sump_Fan           5
#define DeNit_Doser        6
#define DeNit_Pump         7
#define Unused             8

#define ATO_Pump           Box1_Port1
#define Moon_Lights        Box1_Port2
#define Unused             Box1_Port3
#define Unused             Box1_Port4
#define Unused             Box1_Port5
#define Unused             Box1_Port6
#define Unused             Box1_Port7
#define Dummy              Box1_Port8


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

// Does not need to be global.
// unsigned long ATOUpdate=0;

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


void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port4Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit;
// Use T2 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 825 );
//Set Standard Menu
ReefAngel.AddStandardMenu();

// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=30;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.
ReefAngel.DCPump.DaylightChannel=AntiSync; // Now you're pump will be affected by the portal settings.

// Ports that are always on
ReefAngel.Relay.On( Pumps );
ReefAngel.Relay.On( Dummy );

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


////// Place additional initialization code above here
}

void loop()
{
  ReefAngel.StandardLights( Actinic_Lights,12,0,22,0 );
  ReefAngel.StandardLights( Day_Lights,13,0,21,0 );
  ReefAngel.StandardLights( Sump_Fan,13,0,21,0 );
  ReefAngel.WaterLevelATO(ATO_Pump,720,31,34); 

  ////// Place your custom code below here
  ReefAngel.Relay.Set( Moon_Lights, !ReefAngel.Relay.Status( Actinic_Lights ) );

  // DeNitrate Routine
  int DeNit_Offset=3600; 
  int DeNit_Repeat=21600;
  int DeNit_Doser_Offset=1200;
  int DeNit_Doser_Runtime=1200;
  int DeNit_Pump_Runtime=1200;
  int DeNit_ATO_Offtime=1500;

  // Pump comes on first
  ReefAngel.Relay.Set(DeNit_Pump,(now()-3600)%21600<1200);       // Runs for 1200s every 21600 seconds  
  // Doser comes on second
  ReefAngel.Relay.Set(DeNit_Doser,((now()-3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
  
  // Disable ATO
if ( (now()-3600)%21600<1500) ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);

  // Delay WL ATO after water change and DeNit_Dosing
  static time_t wcTimer=0;
  if (ReefAngel.DisplayedMenu == WATERCHANGE_MODE) wcTimer=now();

  // First 10 minutes after WC disable ATO
  if (now()-wcTimer >= 0 && now()-wcTimer < 600)
    ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);

    // Track Salinity low duration
    static unsigned long lastGoodSal;
    static boolean lowSalFlag;
   
    // Salinity is good, update counter
    if (ReefAngel.Params.Salinity>=335) lastGoodSal=now(); 
    
    // Counter hasn't been updating in 300 seconds..
    if (now()-lastGoodSal>300) {
      lowSalFlag=true; // Salinity is definitely below 33.5
    } else {
      lowSalFlag=false; // Salinity back to normal
    }
    
    // Disable ATO if lowSalFlag is true
    if (lowSalFlag) ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
    
  // Disable ATO if ATO High IsActive()
  if (ReefAngel.HighATO.IsActive()) 
    ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
    
  // Modified to use the DCPump class
  if (hour()<12 || hour()>=22) {
    ReefAngel.DCPump.UseMemory=false;                
    ReefAngel.DCPump.Mode=Constant;                  
    ReefAngel.DCPump.Speed=30;
  } else if (InternalMemory.DCPumpMode_read()==Custom) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Mode=Constant;                  // Won't really be constant. See next line.
    ReefAngel.DCPump.Speed=ElseMode(50,20,true );    // ElseMode on sync mode, 50 +/- 20%
  } else  {
    ReefAngel.DCPump.UseMemory=true;                 // Use whatever is in the portal
  }

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

  // This should always be the last line
  ReefAngel.Portal( "Sacohen","Seth0310" );
  ReefAngel.ShowInterface();
}

void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();

// Water Level
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,75,66, "WL:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,66, ReefAngel.WaterLevel.GetLevel() );
  ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
  strcat(text,"  ");
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,39,75,"Salinity:");
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,99,75,text);
pingSerial();

// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 92, TempRelay );
pingSerial();
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox(12, 104, TempRelay);

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

void DrawCustomGraph()
{
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis();        // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000);           // Set the initial delay
  static int NewSpeed = MidPoint;                  // Set the initial speed
  static int AntiSpeed = MidPoint;                 // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay)               // Check if the delay has elapsed
  {
    Delay=random(500,5000);                        // If so, come up with a new delay
    int ChangeUp = random(Offset);                 // Amount to go up or down
    if (random(100)<50)                            // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis();                           // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}
Post Reply