Page 1 of 1

ATO Based on Salinity

Posted: Sun Jun 14, 2015 1:02 pm
by ritz
Hello, I'd like to set up my ATO top off to select ATO pumps based on current Salinity readings. My RO ATO is Box1_Port5 and the Saltwater ATO is on Box1_Port6. How do I code the ATO process to select the RO port be default, and the SW port when salinity is below 33PPT? Also, I'm using the multi channel water level expansion and would like to top off based on the reading of expansion 1, start at 86% and stop at 90%. Can I use the internetal memory settings for the high and low values? All my values are currently stored in internal memory. Thanks in advance!

ATO Based on Salinity

Posted: Mon Jun 15, 2015 5:13 am
by lnevo
Yes you can use the internal memory just use a variable for the port and an if statement to set that variable depending on the salinity

Re: ATO Based on Salinity

Posted: Tue Jun 16, 2015 8:04 am
by ritz
I can't seem to get this one right, please see my code below. I'm getting an error on the WaterLevelATO function. How is that properly referenced?

if (ReefAngel.Params.Salinity>35)
{
ReefAngel.WaterLevelATO ( Box1_Port5 );
}
else
{
ReefAngel.WaterLevelATO ( Box1_Port6 );
}

Re: ATO Based on Salinity

Posted: Tue Jun 16, 2015 9:40 am
by lnevo
It's something else in your code. The above code is fine.

Re: ATO Based on Salinity

Posted: Tue Jun 16, 2015 2:57 pm
by ritz
thanks. I think I figured it out, my change below checked out ok. Look good?

if (ReefAngel.Params.Salinity>35)
{
ReefAngel.WaterLevelATO (1, Box1_Port5 );
}
else
{
ReefAngel.WaterLevelATO ( 1, Box1_Port6 );
}

Re: ATO Based on Salinity

Posted: Tue Jul 14, 2015 7:38 pm
by ritz
I'm still having trouble with this one. See code below. regardless of salinity value, port 8 is always used for the top off.

#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 <PAR.h>
#include <ReefAngel.h>

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


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


void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.Use2014Screen(); // Let's use 2014 Screen
ReefAngel.AddSalinityExpansion(); // Salinity Expansion Module
ReefAngel.AddWaterLevelExpansion(); // Water Level Expansion Module
ReefAngel.AddMultiChannelWaterLevelExpansion(); // Multi-Channel Water Level Expanion Module
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port5Bit | Port6Bit | Port7Bit;
ReefAngel.FeedingModePortsE[0] = Port1Bit | Port2Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port4Bit | Port5Bit | Port6Bit | Port7Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
ReefAngel.LightsOnPortsE[0] = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port2Bit | Port4Bit | Port6Bit;
ReefAngel.OverheatShutoffPortsE[0] = 0;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;

// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;


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

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


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

void loop()
{
ReefAngel.ActinicLights( Port1 );
ReefAngel.DayLights( Port2 );
ReefAngel.MoonLights( Port3 );
ReefAngel.StandardHeater( Port4 );
ReefAngel.Relay.DelayedOn( Port6 );
if (ReefAngel.Params.Salinity > 350 )
{
ReefAngel.WaterLevelATO(1, Port7 );
}
else
{
ReefAngel.WaterLevelATO(1, Port8 );
}
ReefAngel.DosingPumpRepeat1( Box1_Port1 );
ReefAngel.DosingPumpRepeat2( Box1_Port2 );
ReefAngel.DCPump.UseMemory = true;
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = AntiSync;
////// Place your custom code below here


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

// This should always be the last line
ReefAngel.Portal( "ritz" );
ReefAngel.DDNS( "MyTank" ); // Your DDNS is ritz-MyTank.myreefangel.com
ReefAngel.ShowInterface();
}

Re: ATO Based on Salinity

Posted: Thu Jul 16, 2015 11:11 am
by ritz
Anybody??

Re: ATO Based on Salinity

Posted: Thu Jul 16, 2015 3:47 pm
by lnevo
Add a Serial.println(ReefAngel.Params.Salinity); before your if statement and see if the salinity value is what you expect. You'll have to use Serial Monitor in the GUI to see the result. Don't leave that enabled btw, just for testing

Re: ATO Based on Salinity

Posted: Thu Jul 30, 2015 12:39 am
by ritz
I tested my output via serial and confirmed output as expected. Any idea why it always defaults to port 8 regardless of salinity value?

Re: ATO Based on Salinity

Posted: Thu Jul 30, 2015 9:47 am
by rimai
Try adding this before your if statement:

Code: Select all

ReefAngel.Relay.Off( Box1_Port5 );
ReefAngel.Relay.Off( Box1_Port6 );

Re: ATO Based on Salinity

Posted: Thu Jul 30, 2015 12:06 pm
by ritz
Thanks will give that a try.....

Re: ATO Based on Salinity

Posted: Thu Jul 30, 2015 3:07 pm
by lnevo
But its Port7 and Port8 roberto?

Re: ATO Based on Salinity

Posted: Thu Jul 30, 2015 9:12 pm
by rimai
His code says it is the ports I used.

Re: ATO Based on Salinity

Posted: Fri Jul 31, 2015 10:27 am
by lnevo
He's got two different codes. In one he says he fixed it and in the second he says its broken but the second reverts his changes.....

Re: ATO Based on Salinity

Posted: Fri Jul 31, 2015 1:58 pm
by ritz
apologies, I've made some other changes along the way, here is a fresh copy of my code. I knew what Roberto meant, so I adjusted the ports accordingly. The ATO process doesn't run at all when I set those two ports to off, but the process does flag a timeout.

I'm actually having a number of issues with my code now. First, the heater is on at all times regardless of temperature. I tried updating the memory values for the heater settings and that doesn't seem to have helped - memory values are set to on at 77.0 and off at 77.4. Second, my power control module does not respond. I set the jumpers to make it box 2 or 3 and neither one worked. I can see the module in the app, but turning ports on or off has no actual effect. Lastly, I'm also having an issue where my second water level channel is always lower than channel 1. My sump is set up so that channel 1 is always equal to or less than the level of channel number 2. But as the level in channel 1 actually drops, the reported value for channel 2 drops, even if that water level has not actually dropped. help!! :oops:

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 <PAR.h>
#include <ReefAngel.h>

////// Place global variable code below here
// Define Relay Ports by Name, ports 1-8 on battery backup
#define Sump_Pump Port1
#define Food_Pump Port2
#define Heater Port3
#define RW15 Port4
#define NA1 Port5
#define NA2 Port6
#define NA3 Port7
#define NA4 Port8
#define Actinic Box1_Port1
#define Moon Box1_Port2
#define MHL Box1_Port3
#define MHR Box1_Port4
#define Swabbie Box1_Port5
#define Skimmer Box1_Port6
#define ATO_RO Box1_Port7
#define ATO_SW Box1_Port8
#define Calc Box2_Port1
#define Alk Box2_Port2
#define Food1 Box2_Port3
#define Food2 Box2_Port4
#define Food3 Box2_Port5
#define Dose1 Box2_Port6
#define Dose2 Box2_Port7
#define Dose3 Box2_Port8

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


void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
  ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
  ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
  ReefAngel.AddMultiChannelWaterLevelExpansion();  // Multi-Channel Water Level Expanion Module
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port1Bit;
  ReefAngel.FeedingModePortsE[0] = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
  ReefAngel.FeedingModePortsE[1] = 0;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port4Bit;
  ReefAngel.WaterChangePortsE[0] = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
  ReefAngel.WaterChangePortsE[1] = 0;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = 0;
  ReefAngel.LightsOnPortsE[0] = Port1Bit | Port3Bit | Port4Bit;
  ReefAngel.LightsOnPortsE[1] = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port3Bit;
  ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port4Bit | Port5Bit | Port6Bit;
  ReefAngel.OverheatShutoffPortsE[1] = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Feeeding and Water Change mode speed
  ReefAngel.DCPump.FeedingSpeed=( NutrientTransport,25,10 );
  ReefAngel.DCPump.WaterChangeSpeed=0;


  // Ports that are always on
  ReefAngel.Relay.On( Port1 );
  ReefAngel.Relay.On( Port2 );
  ReefAngel.Relay.On( Port4 );

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


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

void loop()
{
  ReefAngel.StandardHeater( Port3 );
  ReefAngel.ActinicLights( Box1_Port1 );
  ReefAngel.MoonLights( Box1_Port2 );
  ReefAngel.DayLights( Box1_Port3 );
  ReefAngel.DelayedStartLights( Box1_Port4 );
  ReefAngel.Relay.DelayedOn( Box1_Port6 );
  ReefAngel.DCPump.UseMemory = true;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync;

  ////// Place your custom code below here
  if (ReefAngel.Params.Salinity > 350 )
  {
    ReefAngel.WaterLevelATO(1, Box1_Port7 );
  }
  else
  {
    ReefAngel.WaterLevelATO(1, Box1_Port8 );
  }
  if (ReefAngel.LowATO.IsActive()) // low water cut off
  {
    ReefAngel.Relay.On( Port1 | Port2 );
    // alert=false;
  }
  else
  {
    ReefAngel.Relay.Off( Port1 | Port2 );
    // alert=true;
  }  

//  if (ReefAngel.HighATO.IsActive()) // High water skimmer shut off
//  {
//    ReefAngel.Relay.On(Box1_Port6);
//    // alert=false;
//  }
//  else
//  {
//    ReefAngel.Relay.Off(Box1_Port6);
//    // alert=true;
//  }

  if (hour()>=21 || hour()<=9) // if hour is >=9pm or hour is <9am
  { 
    ReefAngel.DCPump.SetMode( ReefCrest,20,10 ); // Set dc pump mode to ReefCrest at 20% power for night time
  }
  else
  {
    ReefAngel.DCPump.SetMode( ShortPulse,60,69 );  // set dc pump to shortpulae 60% for daytime
  }

  //  if (hour()=5 || hour()=11 || hour()=17 || hour()=23 )
  //  {
  //    ReefAngel.Relay.On( Box1_Port5 );
  //  }
  //  else
  //  {
  //    ReefAngel.Relay.Off( Box1_Port5 );
  //  }

//  switch(hour()){
//  case 5: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 11: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 17: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 23: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  default: 
//    ReefAngel.Relay.Off( Box1_Port5);
//  }

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

  // This should always be the last line
  ReefAngel.Portal( "ritz" );
  ReefAngel.DDNS( "MyTank" ); // Your DDNS is ritz-MyTank.myreefangel.com
  ReefAngel.ShowInterface();
}


Re: ATO Based on Salinity

Posted: Fri Jul 31, 2015 2:10 pm
by rimai
Let's try this way then:

Code: Select all

  if (ReefAngel.Params.Salinity > 350 )
  {
    ReefAngel.WaterLevelATO(1, Box1_Port7 );
    ReefAngel.Relay.Off(Box1_Port8 );
  }
  else
  {
    ReefAngel.WaterLevelATO(1, Box1_Port8 );
    ReefAngel.Relay.Off(Box1_Port7 );
  }
Run the i2cscanner to see if the id is setup correctly for the power module.
It should be 0x38 for Box1, 0x39 for Box2

Re: ATO Based on Salinity

Posted: Sat Aug 01, 2015 11:52 am
by ritz
Very odd - my RO ATO, Box1_Port6, came on at 4:15 AM this morning and ran endlessly and emptied the entire RO container into my tank. The port is set to auto but it's still turned on, and the sump is 20% above the top off limit. The heater issue is also causing me a major headache. Any idea on these two items?

Re: ATO Based on Salinity

Posted: Sat Aug 01, 2015 1:26 pm
by ritz
Can you guys confirm my dip switch set up? I want the two AC 8 port relays to be ports 1-16 and the dc relay ports 17-24? Should the expansion relay be set to ID 1 or 2? DC relay ID 2 or 3?

Re: ATO Based on Salinity

Posted: Sat Aug 01, 2015 2:08 pm
by ritz
My low water cut off doesn't work either..... am I missing something major here? Nothing seems to be working right! lol..... help plz!! :oops:

Re: ATO Based on Salinity

Posted: Sat Aug 01, 2015 6:46 pm
by rimai
Main relay box doesn't have an ID.
The first relay expansion box should be ID1 and the power module ID2.
The sure way to find out if you have set them correctly is to use the i2c scanner.
Like I posted above, box1 should be 0x38 and box2 should be 0x39.

Re: ATO Based on Salinity

Posted: Sat Aug 01, 2015 6:51 pm
by rimai
This is wrong:

Code: Select all

 if (ReefAngel.LowATO.IsActive()) // low water cut off
  {
    ReefAngel.Relay.On( Port1 | Port2 );
    // alert=false;
  }
  else
  {
    ReefAngel.Relay.Off( Port1 | Port2 );
    // alert=true;
  }  
Mathematically, Port1 | Port2 = Port3.
That's why your heater is not working and the lower cut off too. Both are being messed up by the code above.
I would suggest start your code with the basic and add custom code one at a time and verifying if that is working correctly. That way you now for sure what you added is indeed working.

Re: ATO Based on Salinity

Posted: Sat Aug 08, 2015 10:01 am
by ritz
OK, looks like ATO by salinity is working now. I also changed the low water cutoff statement to use the defined port names instead of the actual ports, which seems to have resolved the heater issue. However, the low water cutoff does not work. I'm also still having the issue where channel 2 always read < channel 1 regardless of actual water level. updated code below.

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 <PAR.h>
#include <ReefAngel.h>

////// Place global variable code below here
// Ports 1-8 on battery backup
#define Sump_Pump Port1
#define Food_Pump Port2
#define Heater Port3
#define RW15 Port4
#define NA1 Port5
#define NA2 Port6
#define NA3 Port7
#define NA4 Port8
#define Actinic Box1_Port1
#define Moon Box1_Port2
#define MHL Box1_Port3
#define MHR Box1_Port4
#define Swabbie Box1_Port5
#define Skimmer Box1_Port6
#define ATO_RO Box1_Port7
#define ATO_SW Box1_Port8
#define Calc Box2_Port1
#define Alk Box2_Port2
#define Food1 Box2_Port3
#define Food2 Box2_Port4
#define Food3 Box2_Port5
#define Dose1 Box2_Port6
#define Dose2 Box2_Port7
#define Dose3 Box2_Port8

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


void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
  ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
  ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
  ReefAngel.AddMultiChannelWaterLevelExpansion();  // Multi-Channel Water Level Expanion Module
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port1Bit | Port2Bit;
  ReefAngel.FeedingModePortsE[0] = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
  ReefAngel.FeedingModePortsE[1] = 0;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port4Bit;
  ReefAngel.WaterChangePortsE[0] = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
  ReefAngel.WaterChangePortsE[1] = 0;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = 0;
  ReefAngel.LightsOnPortsE[0] = Port1Bit | Port3Bit | Port4Bit;
  ReefAngel.LightsOnPortsE[1] = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port3Bit;
  ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port4Bit | Port5Bit | Port6Bit;
  ReefAngel.OverheatShutoffPortsE[1] = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Feeeding and Water Change mode speed
  ReefAngel.DCPump.FeedingSpeed=( NutrientTransport,25,10 );
  ReefAngel.DCPump.WaterChangeSpeed=0;


  // Ports that are always on
  ReefAngel.Relay.On( Port1 );
  ReefAngel.Relay.On( Port2 );
  ReefAngel.Relay.On( Port4 );

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


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

void loop()
{
  ReefAngel.StandardHeater( Heater );
  ReefAngel.ActinicLights( Box1_Port1 );
  ReefAngel.MoonLights( Box1_Port2 );
  ReefAngel.DayLights( Box1_Port3 );
  ReefAngel.DelayedStartLights( Box1_Port4 );
  ReefAngel.Relay.DelayedOn( Box1_Port6 );
  ReefAngel.DCPump.UseMemory = true;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync;

  ////// Place your custom code below here
  if (ReefAngel.Params.Salinity > 351 )
  {
    ReefAngel.WaterLevelATO(1, Box1_Port7 );
    ReefAngel.Relay.Off(Box1_Port8 );
  }
  else
  {
    ReefAngel.WaterLevelATO(1, Box1_Port8 );
    ReefAngel.Relay.Off(Box1_Port7 );
  }
  if (ReefAngel.LowATO.IsActive()) // low water cut off
  {
    ReefAngel.Relay.On( Sump_Pump | Food_Pump | Skimmer );
   // alert=false;
  }
  else
  {
    ReefAngel.Relay.Off( Sump_Pump | Food_Pump | Skimmer );
    // alert=true;
  }  

//if (ReefAngel.HighATO.IsActive()) // High water skimmer shut off
//  {
//    ReefAngel.Relay.On(Box1_Port6);
//  // alert=false;
//  }
//  else
//  {
//    ReefAngel.Relay.Off(Box1_Port6);
//    // alert=true;
//  }

//  if (hour()>=21 || hour()<=9) // if hour is >=9pm or hour is <9am
//  { 
//    ReefAngel.DCPump.SetMode( ReefCrest,20,10 ); // Set dc pump mode to ReefCrest at 20% power for night time
//  }
//  else
//  {
//    ReefAngel.DCPump.SetMode( ShortPulse,60,69 );  // set dc pump to shortpulae 60% for daytime
//  }
//
//  switch(hour()){
//  case 5: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 11: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 17: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 23: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  default: 
//    ReefAngel.Relay.Off( Box1_Port5);
//  }

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

  // This should always be the last line
  ReefAngel.Portal( "ritz" );
  ReefAngel.DDNS( "MyTank" ); // Your DDNS is ritz-MyTank.myreefangel.com
  ReefAngel.ShowInterface();
}

Re: ATO Based on Salinity

Posted: Sat Aug 08, 2015 6:40 pm
by lnevo
Your low cutoff is not working because you can't turn off multiple ports like that as Roberto told you earlier. You need to turn each port on or off explicitly. There is a way to do it but thats not it and it's more complicated than you need.

The difference between what your doing and what you have seen in other code like WaterChangePorts is that those use Port1Bit instead of Port1. But those are calculated along with ReefAngelRelayData which you should only touch through the functions.

Re: ATO Based on Salinity

Posted: Fri Aug 28, 2015 11:59 pm
by ritz
Ah, think I understand now. I made some updates, see below. Will let you know how it goes.

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 <PAR.h>
#include <ReefAngel.h>

////// Place global variable code below here
// Ports 1-8 on battery backup
#define Sump_Pump Port1
#define Food_Pump Port2
#define Heater Port3
#define RW15 Port4
#define RW8 Port5
#define NA2 Port6
#define NA3 Port7
#define NA4 Port8
#define Actinic Box1_Port1
#define Moon Box1_Port2
#define MHL Box1_Port3
#define MHR Box1_Port4
#define Swabbie Box1_Port5
#define Skimmer Box1_Port6
#define ATO_RO Box1_Port7
#define ATO_SW Box1_Port8
#define Calc Box2_Port1
#define Alk Box2_Port2
#define Food1 Box2_Port3
#define Food2 Box2_Port4
#define Food3 Box2_Port5
#define Dose1 Box2_Port6
#define Dose2 Box2_Port7
#define Dose3 Box2_Port8

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


void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
  ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
  ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
  ReefAngel.AddMultiChannelWaterLevelExpansion();  // Multi-Channel Water Level Expanion Module
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port1Bit | Port2Bit;
  ReefAngel.FeedingModePortsE[0] = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
  ReefAngel.FeedingModePortsE[1] = 0;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port4Bit;
  ReefAngel.WaterChangePortsE[0] = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
  ReefAngel.WaterChangePortsE[1] = 0;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = 0;
  ReefAngel.LightsOnPortsE[0] = Port1Bit | Port3Bit | Port4Bit;
  ReefAngel.LightsOnPortsE[1] = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = 0;
  ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port4Bit | Port5Bit | Port6Bit;
  ReefAngel.OverheatShutoffPortsE[1] = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Feeeding and Water Change mode speed
  ReefAngel.DCPump.FeedingSpeed=( NutrientTransport,40,10 );
  ReefAngel.DCPump.WaterChangeSpeed=0;


  // Ports that are always on
  ReefAngel.Relay.On( Port1 );
  ReefAngel.Relay.On( Port2 );
  ReefAngel.Relay.On( Port4 );
  ReefAngel.Relay.On( Port5 );
  ////// Place additional initialization code below here


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

void loop()
{
  ReefAngel.StandardHeater( Heater );
  ReefAngel.ActinicLights( Box1_Port1 );
  ReefAngel.MoonLights( Box1_Port2 );
  ReefAngel.DayLights( Box1_Port3 );
  ReefAngel.DelayedStartLights( Box1_Port4 );
  ReefAngel.Relay.DelayedOn( Box1_Port6 );
  ReefAngel.DCPump.UseMemory = true;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = Sync;

  ////// Place your custom code below here
  if (ReefAngel.Params.Salinity > 351 )
  {
    ReefAngel.WaterLevelATO(1, Box1_Port7 );
    ReefAngel.Relay.Off(Box1_Port8 );
  }
  else
  {
    ReefAngel.WaterLevelATO(1, Box1_Port8 );
    ReefAngel.Relay.Off(Box1_Port7 );
  }
  if (ReefAngel.LowATO.IsActive()) // low water cut off
  {
    ReefAngel.Relay.On( Sump_Pump );
    ReefAngel.Relay.On( Food_Pump );
    ReefAngel.Relay.On( Skimmer );
   // alert=false;
  }
  else
  {
    ReefAngel.Relay.Off( Sump_Pump );
    ReefAngel.Relay.Off( Food_Pump );
    ReefAngel.Relay.Off( Skimmer );
    // alert=true;
  }  

//if (ReefAngel.HighATO.IsActive()) // High water skimmer shut off
//  {
//    ReefAngel.Relay.On(Box1_Port6);
//  // alert=false;
//  }
//  else
//  {
//    ReefAngel.Relay.Off(Box1_Port6);
//    // alert=true;
//  }

//  if (hour()>=21 || hour()<=9) // if hour is >=9pm or hour is <9am
//  { 
//    ReefAngel.DCPump.SetMode( ReefCrest,20,10 ); // Set dc pump mode to ReefCrest at 20% power for night time
//  }
//  else
//  {
//    ReefAngel.DCPump.SetMode( ShortPulse,60,69 );  // set dc pump to shortpulae 60% for daytime
//  }
//
//  switch(hour()){
//  case 5: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 11: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 17: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  case 23: 
//    ReefAngel.Relay.On( Box1_Port5, 30 );
//  default: 
//    ReefAngel.Relay.Off( Box1_Port5);
//  }

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

  // This should always be the last line
  ReefAngel.Portal( "ritz" );
  ReefAngel.DDNS( "MyTank" ); // Your DDNS is ritz-MyTank.myreefangel.com
  ReefAngel.ShowInterface();
}