Delay Time?
Delay Time?
I currently have my reef angel set up to ATO based off salinity.
The code below works fine, but what I found is the top up dispense needs to be close to the salinity probe, else the ATO runs for too long, lowering salinity too much.
I have the ATO dispense within about 6 inches of the salinity probe, which works fine, but obviously causes the salinity to dip very quickly when ATo actuates, so I do not get a nice clean record of salinity.
What I would like to do is modify the code so that when my salinty triggers the ATO, the ATO will run for 5 seconds and then wait for 5 minutes before it is enable again. This will enable me to move the ATO dispense away from the salinity probe and get a good record of actual salinity.
Any help please??
////// Place global variable code below here
unsigned long lastLowSal=now();
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.SetTemperatureUnit( Celsius ); // set to Celsius Temperature
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
ReefAngel.FeedingModePortsE[0] = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = 0;
ReefAngel.WaterChangePortsE[0] = 0;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
ReefAngel.LightsOnPortsE[0] = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = 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( 260 );
// Ports that are always on
ReefAngel.Relay.On( Port4 );
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port8 );
ReefAngel.Relay.On( Box1_Port1 );
ReefAngel.Relay.On( Box1_Port4 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.MHLights( Port3,0,40,23,30,5 );
ReefAngel.StandardHeater( Port6,254,256 );
ReefAngel.StandardFan( Port7,255,257 );
ReefAngel.MHLights( Box1_Port5,23,31,23,33,1 );
////// Place your custom code below here
///// If salinity > 35.1 activate ATO pump until salinity < 35.1
if (ReefAngel.Params.Salinity<351) lastLowSal=now();
ReefAngel.Relay.Set(Port1,(now()-lastLowSal>120));
The code below works fine, but what I found is the top up dispense needs to be close to the salinity probe, else the ATO runs for too long, lowering salinity too much.
I have the ATO dispense within about 6 inches of the salinity probe, which works fine, but obviously causes the salinity to dip very quickly when ATo actuates, so I do not get a nice clean record of salinity.
What I would like to do is modify the code so that when my salinty triggers the ATO, the ATO will run for 5 seconds and then wait for 5 minutes before it is enable again. This will enable me to move the ATO dispense away from the salinity probe and get a good record of actual salinity.
Any help please??
////// Place global variable code below here
unsigned long lastLowSal=now();
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.SetTemperatureUnit( Celsius ); // set to Celsius Temperature
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
ReefAngel.FeedingModePortsE[0] = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = 0;
ReefAngel.WaterChangePortsE[0] = 0;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
ReefAngel.LightsOnPortsE[0] = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = 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( 260 );
// Ports that are always on
ReefAngel.Relay.On( Port4 );
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port8 );
ReefAngel.Relay.On( Box1_Port1 );
ReefAngel.Relay.On( Box1_Port4 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.MHLights( Port3,0,40,23,30,5 );
ReefAngel.StandardHeater( Port6,254,256 );
ReefAngel.StandardFan( Port7,255,257 );
ReefAngel.MHLights( Box1_Port5,23,31,23,33,1 );
////// Place your custom code below here
///// If salinity > 35.1 activate ATO pump until salinity < 35.1
if (ReefAngel.Params.Salinity<351) lastLowSal=now();
ReefAngel.Relay.Set(Port1,(now()-lastLowSal>120));
Re: Delay Time?
What is it doing now?
It waits 120 seconds of high salinity to trigger ATO???
It waits 120 seconds of high salinity to trigger ATO???
Roberto.
Re: Delay Time?
Yes, to make sure it is def high salinity, it waits 120 secs, and if salinity >35.1 for 120 secs, triggers ATO until salinity drops below 35.1.rimai wrote:What is it doing now?
It waits 120 seconds of high salinity to trigger ATO???
The last bit is the bit I want to improve as when ATO operates, it causes a big dip in salinity as near the probe and if I have the salinity probe further away, it dumps too much ATO water in and salinity.
Te salinity trigger is perfect with the delay of 120 secs, just want the ATO to operate for a short burst and then wait 5 minutes or so and then re enable the salinity trigger - hope this makes sense!!
Re: Delay Time?
Just to add a bit more detail, I want to accomplish more than this, but this is the first step.
I have both the salinity probe and water level sensor and have tried using one or the other for ATO, but neither is perfect.
When I just use the salinity probe, salinity is keep spot on as you would expect, but over time, my sump level gets depleted, as there is no replacement of water taken out from skimming (I skim quite wet).
When I just use level sensor, the level is kept spot on, as you would expect, but over time my salinity is lowered as this tops up RO water to replace water taken out by skimming.
So my plan is to use salinity to control the RO top up and have a separate container with salted water (old water change water) that I can top up the water level with using the level sensor. For this, I would like to have something like,
if salinity is 35ppt activate salt water top up port until water level increases to let's say 50. So if you could help with ths part too, that would be great!
I have both the salinity probe and water level sensor and have tried using one or the other for ATO, but neither is perfect.
When I just use the salinity probe, salinity is keep spot on as you would expect, but over time, my sump level gets depleted, as there is no replacement of water taken out from skimming (I skim quite wet).
When I just use level sensor, the level is kept spot on, as you would expect, but over time my salinity is lowered as this tops up RO water to replace water taken out by skimming.
So my plan is to use salinity to control the RO top up and have a separate container with salted water (old water change water) that I can top up the water level with using the level sensor. For this, I would like to have something like,
if salinity is 35ppt activate salt water top up port until water level increases to let's say 50. So if you could help with ths part too, that would be great!
Re: Delay Time?
Looks like you are trying to do what 00Warpig00 is doing.
http://forum.reefangel.com/viewtopic.ph ... 0&start=10
http://forum.reefangel.com/viewtopic.ph ... 0&start=10
Roberto.
Re: Delay Time?
Hi Roberto, Similar but not quite what I'm after.rimai wrote:Looks like you are trying to do what 00Warpig00 is doing.
http://forum.reefangel.com/viewtopic.ph ... 0&start=10
Is there a simple function for turning on a port for x seconds?
Also, to enable a delay for x seconds before my salinity is checked again, is the waitfortime function the best to use?
Re: Delay Time?
No such function.
We need to come up with them.
Try this:
We need to come up with them.
Try this:
Code: Select all
#include <Salinity.h>
#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 <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
//unsigned long lastLowSal=now();
boolean ATOEnabled=true;
boolean ATOPumping=false;
unsigned long ATOStart=now();
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.SetTemperatureUnit( Celsius ); // set to Celsius Temperature
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
ReefAngel.FeedingModePortsE[0] = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = 0;
ReefAngel.WaterChangePortsE[0] = 0;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
ReefAngel.LightsOnPortsE[0] = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = 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( 260 );
// Ports that are always on
ReefAngel.Relay.On( Port4 );
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port8 );
ReefAngel.Relay.On( Box1_Port1 );
ReefAngel.Relay.On( Box1_Port4 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
////// Place additional initialization code below here
ReefAngel.Timer[1].SetInterval(300); // Timer to enable ATO
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.MHLights( Port3,0,40,23,30,5 );
ReefAngel.StandardHeater( Port6,254,256 );
ReefAngel.StandardFan( Port7,255,257 );
ReefAngel.MHLights( Box1_Port5,23,31,23,33,1 );
////// Place your custom code below here
///// If salinity > 35.1 activate ATO pump until salinity < 35.1
// if (ReefAngel.Params.Salinity<351) lastLowSal=now();
// ReefAngel.Relay.Set(Port1,(now()-lastLowSal>120));
if (ReefAngel.Params.Salinity<351 && !ATOPumping)
{
ATOPumping=true;
ATOStart=now();
}
if (now()-ATOStart<5)
{
if (ATOEnabled) ReefAngel.Relay.On(Port1);
ReefAngel.Timer[1].Start();
}
else
{
ReefAngel.Relay.Off(Port1);
ATOEnabled=false;
}
if (ReefAngel.Timer[1].IsTriggered())
{
ATOEnabled=true;
}
}
Roberto.
Re: Delay Time?
Roberto, your a star - as always!
I will try and digest the code to understand it and give it a try!
I will try and digest the code to understand it and give it a try!
Re: Delay Time?
Well, I spent some time to figure out what the code was doing, and then decided it wouldnt work!
So as not to trouble you, I sat down and figured out what I wanted to do and guess what - it works!!!
Basically, if salinity greater than 35.1 for more than 2 minutes, it enables ATO pump in for 5 secs, then disables the ATO function for 5 mins to wait for the true salinity to stabilise after the ATO - if salinity is greater than 35.1 still, repeats the process and if less than 35.1, waits until salinity reaches >35.1 for 2 minutes before it activates again.
Code below if anyone interested:
So as not to trouble you, I sat down and figured out what I wanted to do and guess what - it works!!!
Basically, if salinity greater than 35.1 for more than 2 minutes, it enables ATO pump in for 5 secs, then disables the ATO function for 5 mins to wait for the true salinity to stabilise after the ATO - if salinity is greater than 35.1 still, repeats the process and if less than 35.1, waits until salinity reaches >35.1 for 2 minutes before it activates again.
Code below if anyone interested:
#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 <ReefAngel.h>
////// Place global variable code below here
unsigned long lastLowSal=now();//salinity >35.1 timer
boolean SALduration=true;//salinity >35.1 for 2 minutes flag
boolean ATOEnabled=false;//enable ATO function for 5 seconds
boolean ATOPumping=true;//disable ATO function for 5 minutes
unsigned long ATOStart=now();//ATO 5 sec run timer
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.SetTemperatureUnit( Celsius ); // set to Celsius Temperature
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
ReefAngel.FeedingModePortsE[0] = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = 0;
ReefAngel.WaterChangePortsE[0] = 0;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
ReefAngel.LightsOnPortsE[0] = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = 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( 260 );
// Ports that are always on
ReefAngel.Relay.On( Port4 );
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port8 );
ReefAngel.Relay.On( Box1_Port1 );
ReefAngel.Relay.On( Box1_Port4 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
////// Place additional initialization code below here
ReefAngel.Timer[1].SetInterval(300); // 5 mins before reactivation of ATO
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.MHLights( Port3,0,40,23,30,5 );
ReefAngel.StandardHeater( Port6,253,255 );
ReefAngel.StandardFan( Port7,255,257 );
ReefAngel.MHLights( Box1_Port5,23,31,23,33,1 );
////// Place your custom code below here
///// If salinity >35.1 for 120 sec set SALduration flag
if (ReefAngel.Params.Salinity<351) lastLowSal=now();
if (now()-lastLowSal>120) SALduration=false;
if (SALduration && ATOPumping)//if salinity>35.1 for 2 minutes enable ATO
{ATOStart=now();
}
else
{
ATOEnabled=true;
ATOPumping=false;
}
if (now()-ATOStart<5)//ATO pump on time 5 seconds
{
if (ATOEnabled) ReefAngel.Relay.On(Port1);
ReefAngel.Timer[1].Start();//start 5 minute disable of ATO
}
else
{
ReefAngel.Relay.Off(Port1);
ATOEnabled=false;
}
if (ReefAngel.Timer[1].IsTriggered())//after 5 minute disable, enable ATO
{
ATOPumping=true;
ATOStart=now();
SALduration=true;
}
///// if skimmer cup full, turn off skimmer
if (ReefAngel.HighATO.IsActive()) {
bitClear(ReefAngel.Relay.RelayMaskOff,2);
}
else {
bitSet(ReefAngel.Relay.RelayMaskOff,2);
}
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "dazza1304" );
ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 10, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 10, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();
// Salinity
ReefAngel.LCD.DrawText( COLOR_BLACK,DefaultBGColor,15,46, "SAL:" );
ReefAngel.LCD.DrawText( COLOR_BLACK,DefaultBGColor,39,46, ReefAngel.Params.Salinity );
pingSerial();
// ORP
ReefAngel.LCD.DrawText( COLOR_PALEVIOLETRED,DefaultBGColor,75,46, "ORP:" );
ReefAngel.LCD.DrawText( COLOR_PALEVIOLETRED,DefaultBGColor,99,46, ReefAngel.Params.ORP );
pingSerial();
// Water Level
ReefAngel.LCD.DrawText( COLOR_BLACK,DefaultBGColor,75,63, "WL:" );
ReefAngel.LCD.DrawText( COLOR_BLACK,DefaultBGColor,99,63, ReefAngel.WaterLevel.GetLevel() );
pingSerial();
// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 79, TempRelay );
pingSerial();
// Relay Expansion
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox( 12, 98, TempRelay );
pingSerial();
// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}
void DrawCustomGraph()
{
}
Re: Delay Time?
Think I am finally getting the hang of this programming!