ATO code is not working properly.

Do you have a question on how to do something.
Ask in here.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

ATO code is not working properly.

Post by lnevo »

It wont kick in till it hits the low threshold.

Take some water out and see if its working or not... Or move the sensor..
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 »

Sorry. I'm a little foggy today. Having a bad allergy day.

I raised the sensor and it did kick in.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

During wc? Hmm I'll look at it more closely tomorrow. We'll get this!
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'll look at it again tomorrow.
I don't remember if I was in WC mode or not when I tried it lady night.
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 »

The 1pm cycle came and went and the ATO DID NOT kick, but the WL DID NOT go below the lower limit of 31%.

At 7pm the Water Level was 31% prior to the water exchange, when the cycle started it dropped to 28% and the ATO kicked in.

AT 7:50pm (move then the 5min delay after the Denit pump cycle) I started a WC mode.
lifted the WL tube up so it was below the 31% low level (25%) and the ATO DID NOT kick in.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Ok that helps...so WC is working as expected, yes?
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, it seems to be working properly.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Try this code

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_Pump         6
#define DeNit_Doser        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 Unused             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=20;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.

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

////// 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 );

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

  ReefAngel.Relay.Set(DeNit_Doser,(now()-3600)%21600<1200);       // Runs for 1200s every 21600 seconds
  ReefAngel.Relay.Set(DeNit_Pump,((now()-3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset

  // ReefAngel.Relay.DelayedOn( ATO_Pump,10 );
  // ReefAngel.WaterLevelATO(ATO_Pump,720,32,32); // Enable ATO the ATO

  // Delay WL ATO after water change and DeNit_Dosing
  static time_t wcTimer=0;
  static time_t denitTimer=0;
  
  if (ReefAngel.DisplayedMenu == WATERCHANGE_MODE) wcTimer=now();
  if (ReefAngel.Relay.Status(DeNit_Pump)) denitTimer=now();
  
  // Start with defined WaterLevel ATO 
  ReefAngel.WaterLevelATO(ATO_Pump,720,32,34); 
  // You should see a much more stable pump usage with a wider threshold 32-34.
  // Also since the water level measure can fluctuate it could lead to a lot of on/off cycling
  // which could also cause the relay to be on more often and it we reboot, we may maintain the state we don't want...
  // Especially if it could take up to 30 seconds to reboot :)
  
  // First 10 minutes after WC disable ATO
  if (now()-wcTimer >= 0 && now()-wcTimer < 600)
    ReefAngel.Relay.Off(ATO_Pump); 

  // First 5 minutes after DeNit_Doser was on
  if (ReefAngel.Relay.Status(DeNit_Pump) || ReefAngel.Relay.Status(DeNit_Doser))
    ReefAngel.Relay.Off(ATO_Pump); 

  // Disable ATO if Salinity is below 33.5. 
  if (ReefAngel.Params.Salinity<335) 
    ReefAngel.Relay.Off(ATO_Pump); 
    
  // Disable ATO if ATO High IsActive()
  if (ReefAngel.HighATO.IsActive()) 
    ReefAngel.Relay.Off(ATO_Pump);
    
  // 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(40,20,true );    // ElseMode on sync mode, 40 +/- 20%
  } else  {
    ReefAngel.DCPump.UseMemory=true;                 // Use whatever is in the portal
  }

  // No longer necessary since we've defined the speeds for these modes in setup();
  //
  // if( ReefAngel.DisplayedMenu==FEEDING_MODE ) ReefAngel.PWM.SetActinic(20);
  // if( ReefAngel.DisplayedMenu==WATERCHANGE_MODE ) ReefAngel.PWM.SetActinic(0);

  ////// 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;
  }
}
So what I'm doing now is just turning off the ATO when either the DeNit ports are on... Lets me make sure I'm not crazy first and go from there... I know you only want the ATO off for the first 5 minutes of the DeNit_Doser...but I don't think 15 minutes will kill you...
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 »

No that would be fine,
I'll try it tonight.

Thanks again for the work on it.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

I know this may sound stupid but is it possible that you have the ports backwards and that DeNit_Doser comes on first? If you have the DeNit_Pump plugged in that port the process would work for you, but my code would be broken of course..

I have to do the math on your timing setup but i have a feeling that the line with -1200 fires first..just want to make sure you see the port activity matches what we are expecting... I'm probably wrong but its worth at least asking the question..
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 »

No. Sorry to say you are wrong about the port (relays) being backwards.

I've checked that many times when we first set it up (with cosmith71) and more recently barbecue the dosing pump broke and I had to replace a part, so I watched that it was turning correctly when I did that.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Ok. Worth asking. I'll look at the math anyway because I want to understand how that is better...
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Ok, I see now better. The pump part is actually on the second line and the offset is 3600-1200, so it's actually -4800 which is greater than (earlier) than the doser which is offset only -3600. The confusing part is that the pump line comes first :) I'm good now and yeah we should be good. I'll review my code to make sure I'm aligned properly but I should be....

If the code I posted earlier today works, we can try doing this as the statement

if ( (now()-3600(-1200)%21600<1500) ReefAngel.Relay.Off(ATO_Pump) // Start time same as DeNit_Pump but keep it off for 1500 seconds (25 minutes)

Then we can take out the other timer that I added...
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. So you want me to try the code you posted earlier and if it works

Replace this....

ReefAngel.Relay.Set(DeNit_Doser,(now()-3600)%21600<1200); // Runs for 1200s every 21600 seconds
ReefAngel.Relay.Set(DeNit_Pump,((now()-3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset

with this...

if ( (now()-3600(-1200)%21600<1500) ReefAngel.Relay.Off(ATO_Pump) // Start time same as DeNit_Pump but keep it off for 1500 seconds (25 minutes)

Is that the correct thing to replace?

Can I ask why replace it if it works?
Is it a better way to do it?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

No. thats not what you want to replace...

Let's try the first code first.. The only issue with that is your ATO will be off for 40 minutes. I just want to do that as a sanity check. Then if that works we can use the same code you are using to activate the denitrate process with the similar code that I propsed to disable the ato pump.

It would give some consistency to what you've got going making it cleaner and easier to maintain longer term.
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 »

No problem. I will try the code you put up earlier when I get home.

Thanks.
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 love the Bluetooth module.
I just remoted into my laptop, downloaded your new code, changed a couple of things for the 2nd Jebao pump and then uploaded it, so when I get home I can just wait for the 7pm cycle and watch (or listen to) what happens.

I don't have to rush to try to get the code changed and uploaded in the 30 min I may have between when I get home and when the cycle happens at 7pm.

I'll let you know what happens.

My WL is at 31% right now and I;m going to leave it there so that when the cycle happens it will definitely drops below the low limit and want to turn on 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 »

By George I think you got it. The 40 min 7pm cycle came and went and I did not hear the ATO go kick in until 7:46.
The WL was at 28% though out the water exchange.
That was strange because the WL was back up to 32% at that point.
It only came on for about 10 seconds.
At 7:52 it came on again for about 10 seconds.

I just happened again at 8:04 for about 10 seconds too?

Water level is reading 32%, but if I look at the sump it looks higher than that.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Whats salinity at? Don't forget we have a few checks now. Also you may need to recalibrate after moving the sensor around...
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 I know, but those checks are to disable it if the salinity is below 33.5 or the ATO High is on.
The salinity is 36.6 and the ATO High is not on.

It should not have gone on.
The only thing I can think of is that I forgot to change the spread from 34 to 32 like you have to 34 to 31 like you wanted (3% spread). So it may have dropped below 32 for a brief second, but if that was the case it should have stayed on until it reached 34% (the high level) correct?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

I'll post my next attempt tomorrow for you to try that will get you the 25 minutes off you want.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Try this code:

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_Pump         6
#define DeNit_Doser        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 Unused             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=20;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.

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

////// 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_Pump_Offset=1200;
  int DeNit_Pump_Runtime=1200;
  int DeNit_Doser_Runtime=1200;
  int DeNit_ATO_Offtime=1500;

  // Pump comes on first
  ReefAngel.Relay.Set(DeNit_Pump,((now()-3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
  // Doser comes on second
  ReefAngel.Relay.Set(DeNit_Doser,(now()-3600)%21600<1200);       // Runs for 1200s every 21600 seconds
  // Disable ATO
 ReefAngel.Relay.Set(ATO_Pump, !((now()-3600(-1200)%21600<1500); // Start time same as DeNit_Pump but for 1500 seconds (25 minutes)

  // 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.Relay.Off(ATO_Pump); 

  // Disable ATO if Salinity is below 33.5. 
  if (ReefAngel.Params.Salinity<335) 
    ReefAngel.Relay.Off(ATO_Pump); 
    
  // Disable ATO if ATO High IsActive()
  if (ReefAngel.HighATO.IsActive()) 
    ReefAngel.Relay.Off(ATO_Pump);
    
  // 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(40,20,true );    // ElseMode on sync mode, 40 +/- 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;
  }
}
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Try this now. I moved the ato definition outside of the custom code as that part is now a standard definition. The off during the DeNitrate process is with the DeNitrate code. I added variables you could use to replace all the static numbers to make it easier to change later...I'll leave it to you later to replace the numbers with the variables...didn't want to start troubleshooting that now.i modified the syntax of what I posted earlier so it's the same style as the DeNitrate steps. That should make it pretty clear. I really hope this does the trick. I'm fairly confident though. Good luck.
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 very much Lee. I appreciate the time you put in on this.
If this does not work, what I have not (the 40 minutes) will be fine.

Do you have any idea why the ATO was turning on for about 10 seconds at a time last night?
That was strange.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Not sure yet, but most likely the fluctuations as you said. The wider the threshold the better. I've set it to 31,34 in the code above.
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 »

Yeah. I've been changing the other ones to 31,34, but I forgot on the last one.

Unless I mis-understand how it work, it should kick in when the WL goes below 31 and stay on until it reaches 34.

Is that correct?

This seemed like it was going on when it got below 32 and staying on longer enough to get it just above 32.

When I had the really tight params of 32,32 it would kick in when it went below 32 (basically high 31) and stay on until it got above 32 (low 33) and even though it seemed tight it was a good range in the sump.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Yes
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;

I just tried loading the new code and got the following error.

'3600 cannot be used as a function'

it's reading line 119 at the bottom of the window.

// Disable ATO
ReefAngel.Relay.Set(ATO_Pump, !((now()-3600(-1200)%21600<1500); // Start time same as DeNit_Pump but for 1500 seconds (25 minutes)
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: ATO code is not working properly.

Post by lnevo »

Sorry it should be 3600)-1200 on that line
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 a coding idiot.

Now I'm getting

expected ')' before numeric constant

with the line the way I put it...

// Disable ATO
ReefAngel.Relay.Set(ATO_Pump, !((now()3600)-1200 %21600<1500); // Start time same as DeNit_Pump but for 1500 seconds (25 minutes)

Also this is at the bottom...

Steves_New_Code.cpp: In function 'void loop()':
Steves_New_Code:118: error: expected `)' before numeric constant
Steves_New_Code:118: error: expected `)' before ';' token
Steves_New_Code:118: error: expected `)' before ';' token

Sorry I can't figure these errors out myself.
Post Reply