Re: ATO code is not working properly.
Posted: Sun Sep 22, 2013 7:08 pm
Thank you Lee.
Community discussion about Reef Angel Controllers and reefing related subjects
https://forum.reefangel.com/
Code: Select all
// Disable ATO if Salinity is below 33.5.
if (ReefAngel.Params.Salinity<335)
ReefAngel.Relay.Override(ATO_Pump,0);
Cool...sounds like probe jitter to me.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.
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.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..
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.Code: Select all
// Disable ATO if Salinity is below 33.5. if (ReefAngel.Params.Salinity<335) ReefAngel.Relay.Override(ATO_Pump,0);
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...
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);
Code: Select all
// Disable ATO if Salinity is below 33.5.
if (ReefAngel.Params.Salinity<335)
ReefAngel.Relay.Override(ATO_Pump,0);
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;
}
}