ATO Based on Salinity

Do you have a question on how to do something.
Ask in here.

Posts: 12537
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Sat Aug 01, 2015 6:51 pm
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.
Roberto.

Posts: 18
Joined: Fri May 22, 2015 10:48 am
Location: California
PostPosted: Sat Aug 08, 2015 10:01 am
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();
}
Image
User avatar
Posts: 5421
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Aug 08, 2015 6:40 pm
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.

Posts: 18
Joined: Fri May 22, 2015 10:48 am
Location: California
PostPosted: Fri Aug 28, 2015 11:59 pm
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();
}
Image
Previous

Return to How do I code ...

Who is online

Users browsing this forum: Google [Bot] and 3 guests