Multi-water level ATO dumping water when it shouldn't

Basic / Standard Reef Angel hardware
Post Reply
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Multi-water level ATO dumping water when it shouldn't

Post by Smotz »

Lo all,

Below is my code. My multi-water level module is giving me problems. It's activating the ATO when it shouldn't. It just dumped water from 110% to 130% for example.

The levels seem stable - about a 2% fluctuation.

Any idea how I can troubleshoot this?

Code: Select all

  if ( ReefAngel.WaterLevel.GetLevel(1) <=85 && ReefAngel.WaterLevel.GetLevel(2) <=85) ReefAngel.Relay.On (Topoff);
  if ( ReefAngel.WaterLevel.GetLevel(1) >=95 || ReefAngel.WaterLevel.GetLevel(2) >=95) ReefAngel.Relay.Off (Topoff);

  if ( ReefAngel.WaterLevel.GetLevel(1) >= 145 || ReefAngel.WaterLevel.GetLevel(2) >= 145 ) ReefAngel.Relay.Override(Topoff,0);
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Multi-water level ATO dumping water when it shouldn't

Post by rimai »

Are you sure you don't have nothing else in your code that uses the same port?
Could it be that you overrode the port and forgot about it?
Roberto.
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Multi-water level ATO dumping water when it shouldn't

Post by Smotz »

here's the code if you care to look

Code: Select all

////  Port 1			Heater
////  Port 2			ATO pump
////  Port 3			Feeder
////  Port 4			Protein Skimmer
////  Port 5			Return Pump
////  Port 6			Wavemakers
////  Port 7                    UV Sterilizer
////  Port 8                    Cabinet Light

////  BOX 1 PORT 1              Calcium Doser
////  BOX 1 PORT 2              Alkalinity Doser
////  BOX 1 PORT 3              Media Reactor
////  BOX 1 PORT 8              Sump Fan
////  BOX 1 PORT 8              Fans

////  Probe T1  SUMP
////  Probe T2  Tank
////  Probe T3  Canopy


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

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

#define Heater Port1
#define Topoff Port2
#define Feeder Port3
#define Skimmer Port4
#define Return Port5
#define Wave Port6
#define UVlight Port7
#define Fugelight Port8
#define CanopyFan  Box1_Port8
#define CalcDose  Box1_Port1
#define AlkDose  Box1_Port2
#define Reactor Box1_Port3
#define SumpFan  Box1_Port7


#define FugelightBit   1<<7
#define UVlightBit   1<<6
#define WaveBit   1<<5
#define ReturnBit   1<<4
#define SkimmerBit   1<<3
#define FeederBit   1<<2
#define TopoffBit   1<<1
#define HeaterBit   1<<0

static byte wpMode;
static byte wpWavStr;
static byte wpWavOff;
unsigned long NoteTime;

////// 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.AddMultiChannelWaterLevelExpansion();  // Multi-Channel Water Level Expansion Module
    ReefAngel.Network.WifiAuthentication("Smotz:xxxxxx");
    
// Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = SkimmerBit | ReturnBit | TopoffBit | UVlightBit ;
    ReefAngel.FeedingModePortsE[0] = FeederBit;  ////Reactor
// Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = HeaterBit | SkimmerBit | ReturnBit | TopoffBit | WaveBit | UVlightBit | FeederBit ;
    ReefAngel.WaterChangePortsE[0] = FeederBit; ///reactor
// Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = FugelightBit;
// Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = HeaterBit | TopoffBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit | FeederBit | Reactor;
    ReefAngel.OverheatShutoffPortsE[0] = FeederBit; ////reactor

// Use T2 (Tank) probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T2_PROBE;

// Ports that are always off
    ReefAngel.Relay.Off( Feeder );
    ReefAngel.Relay.Off( Topoff );

// Ports that are always on
    ReefAngel.Relay.On( Box1_Port3 );
    ReefAngel.Relay.On( Box1_Port4 );    
    ReefAngel.Relay.On( Box1_Port5 );
    ReefAngel.Relay.On( Box1_Port6 );
    ReefAngel.Relay.On( Box1_Port7 );  

// DCPUMP
    ReefAngel.DCPump.FeedingSpeed=255;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    ReefAngel.DCPump.ActinicChannel=Sync; 
    ReefAngel.DCPump.DaylightChannel=AntiSync; 
    ReefAngel.DCPump.Threshold=30; 
  ////// Place additional initialization code below here
    
  ////// Place additional initialization code above here
}

void loop()
{
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( Wave );
    ReefAngel.Relay.Off( Feeder );
    ReefAngel.MoonLights( Fugelight );
    ReefAngel.StandardHeater( Heater );
    ReefAngel.StandardFan( SumpFan );
    
////// Place your custom code below here

// Static bool to track if we are currently feeding or not
static boolean feedingActive = false;

//FEEDING MODE
// Begin Feeding Mode
      if (((hour() == 7)) && (minute() == 30) || (hour() == 18) && (minute() == 00)) {
          ReefAngel.FeedingModeStart(); // FEEDING MODE @ 7:30 AM or 6:00 PM
          NoteTime = millis(); // Grab millis value of when feeding mode started
          feedingActive = true; // We are entering feeding mode, so set to true
      }

      if (feedingActive) {
          unsigned long DeltaTS = millis() - NoteTime;
          if ( DeltaTS >= 130000 ) {
              ReefAngel.Relay.Off(Feeder); // turn off 2 minutes 10 secs
              feedingActive = false; // Feeding mode is now over, set to false
          } else
          if ( DeltaTS >= 120000 ) ReefAngel.Relay.On(Feeder); // turn on after 2 minutes
          else
          if ( DeltaTS >= 70000 ) ReefAngel.Relay.Off(Feeder); // turn off 1 min 10 secs 
          else
          if ( DeltaTS >= 60000 ) ReefAngel.Relay.On(Feeder); // turn on after 1 minute
      }
   
// Main Top Off
//   ReefAngel.WaterLevelATO(1,Topoff,15,85,95);  
  if ( ReefAngel.WaterLevel.GetLevel(1) <=85 && ReefAngel.WaterLevel.GetLevel(2) <=85) ReefAngel.Relay.On (Topoff);
  if ( ReefAngel.WaterLevel.GetLevel(1) >=95 || ReefAngel.WaterLevel.GetLevel(2) >=95) ReefAngel.Relay.Off (Topoff);

  if ( ReefAngel.WaterLevel.GetLevel(1) >= 145 || ReefAngel.WaterLevel.GetLevel(2) >= 145 ) ReefAngel.Relay.Override(Topoff,0);


//Dosing
   ReefAngel.DosingPumpRepeat1( CalcDose );
   ReefAngel.DosingPumpRepeat2( AlkDose );
//// 30,20 = 17.5 ml day
//// ReefAngel.DosingPumpRepeat(CalcDose,0,30,20);
//// ReefAngel.DosingPumpRepeat(AlkDose,10,30,20);

// Turn on Canopy Fans when the temp of T3 (Canopy) gets above 85.0 degrees
    if ( ReefAngel.Params.Temp[T3_PROBE] >= 850 ) ReefAngel.Relay.On( CanopyFan );
// Turn off Canopy Fans when the temp of T2 (Canopy) gets below 80.0 degrees
    if ( ReefAngel.Params.Temp[T3_PROBE] < 800 ) ReefAngel.Relay.Off( CanopyFan );
    
    ReefAngel.Relay.DelayedOn(Skimmer,5); 
    ReefAngel.Relay.DelayedOn(Reactor,2);
    
// Buzzer if temp is too high or low, or waterlevel 1 is too high or too low.
    if (ReefAngel.DisplayedMenu!=WATERCHANGE_MODE && ReefAngel.DisplayedMenu!=FEEDING_MODE) // Only check if not Feeding Mode or Water Change Mode
    {  
    if ( ReefAngel.Params.Temp[T2_PROBE] < 700 || ReefAngel.Params.Temp[T2_PROBE] > 850 || ReefAngel.WaterLevel.GetLevel(1) > 140 || ReefAngel.WaterLevel.GetLevel(1) < 70)
        {   
        pinMode(lowATOPin,OUTPUT);
        digitalWrite(lowATOPin,HIGH);
        }
        else
        {
        pinMode(lowATOPin,OUTPUT);
        digitalWrite(lowATOPin,LOW);
    }}

// Turn the fugelight on if the return is off 
    if (ReefAngel.Relay.Status ( Return ) == 0) ReefAngel.Relay.On( Fugelight );
  
 // Custom Wave Routine 
  if (InternalMemory.DCPumpMode_read()==11)  
  {
    ReefAngel.DCPump.UseMemory=false;
    // set the wpMode based on what time it is
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) wpMode=5;   // Feeding Mode
    else 
      if ( (hour() >= 2) && (hour() < 8) ) wpMode=1;       // from 2am - 8am  
      else
        if ( (hour() >= 8) && (hour() < 11) ) wpMode=4;      // from 8am - 11am  Nutrient Transport
        else
          if ( (hour() >= 11) && (hour() < 14) ) wpMode=2;     // from 11a - 2pm
          else
            if ( (hour() >= 14) && (hour() < 17) ) wpMode=3;     // from 2pm - 5pm
            else
              if ( (hour() >= 17) && (hour() < 20) ) wpMode=2;     // from 5pm - 8pm
              else
                if ( (hour() >= 20) && (hour() < 23) ) wpMode=3;     // from 8pm - 11p
                else
                  if (hour() >= 23) wpMode=2;                          // from 11pm - midnight 
                  else
                    if (hour() < 2) wpMode=1;                            // from midnight - 2am

    switch (wpMode) 
    {
    case 1:  // 2am to 8am  Night Mode
      wpWavStr=35; 
      wpWavOff=10; 
      ReefAngel.DCPump.SetMode (Sine, wpWavStr, wpWavOff);
      break;

    case 2:  // 5am to 8am, 11am to 2pm, 5pm to 8pm, 11pm to midnight
      wpWavStr=45; 
      wpWavOff=3; 
      ReefAngel.DCPump.SetMode (Else, wpWavStr, wpWavOff);
      break;

    case 3:  // 2pm to 5pm, 8pm to 11pm
      wpWavStr=65; 
      wpWavOff=7; 
      ReefAngel.DCPump.SetMode (Else, wpWavStr, wpWavOff);
      break;

    case 4:  // 8am to 11am
      wpWavStr=70; 
      wpWavOff=10; 
      ReefAngel.DCPump.SetMode (NutrientTransport, wpWavStr,wpWavOff);
      break; 

    case 5:  //feeding mode
      wpWavStr=30;
      wpWavOff=3;
      ReefAngel.DCPump.SetMode (LongPulse, wpWavStr, wpWavOff);
      break; 
    }
  }
  else ReefAngel.DCPump.UseMemory = true;    //  If it's not custom mode on the portal, then do what mode the portal says.
  //  End Custom Wave Routine  

//  Only turn on UV Sterilizer between 11pm and 3am
    if ( (hour() >= 3) && (hour() < 23) )  // from 3a - 11p
    ReefAngel.Relay.Off(UVlight);
    else ReefAngel.Relay.On(UVlight);

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

// This should always be the last line
    ReefAngel.Portal( "Smotz" );
    ReefAngel.ShowInterface();
}

void DrawCustomMain()
{
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 5, ReefAngel.Params,
    ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 5, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
    pingSerial();

//    Salinity
//    ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,20,80, "SAL:" );
//    ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,44,80, ReefAngel.Params.Salinity );
//    pingSerial();

// Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 12, 95, TempRelay );
    pingSerial();
// Relay Expansion
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 12, 105, TempRelay );
    pingSerial();
// Date and Time
    ReefAngel.LCD.DrawDate( 6, 122 );
    pingSerial();
//draw the mode on the screen
    char buf[16];
    char buf2[16];
//    char buf3[32];
    sprintf(buf,"%d%% +/- %d%%",wpWavStr,wpWavOff);
    sprintf(buf2,"Wave Mode = %d%",wpMode);
//    sprintf(buf3,"Return Power = %d%",InternalMemory.LEDPWMActinic_read());
//    ReefAngel.LCD.DrawText(0,255,10,40,buf3);
    ReefAngel.LCD.DrawText(0,255,20,60,buf);
    ReefAngel.LCD.DrawText(0,255,20,50,buf2);
}

void DrawCustomGraph()
{
}
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Multi-water level ATO dumping water when it shouldn't

Post by Smotz »

To add - I just got a text alert that both water level 1 and 2 (I use both) are at 0. When I checked after getting the alert it was fine @ 98%.

..what can it be...how to test..

water level module?
water level tubes / pvc? probably not as both 1 & 2 tripped at the same time
expansion hub?
usb cables?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Multi-water level ATO dumping water when it shouldn't

Post by rimai »

Use this to prevent it from turning on when you get zeros.

Code: Select all

if ( ReefAngel.WaterLevel.GetLevel(1) <=85 && ReefAngel.WaterLevel.GetLevel(2) <=85 && ReefAngel.WaterLevel.GetLevel(1) >0 && ReefAngel.WaterLevel.GetLevel(2) >0) ReefAngel.Relay.On (Topoff);
I would start by checking the connections and usb cables.
Try a different port in the hub too.
Roberto.
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Multi-water level ATO dumping water when it shouldn't

Post by Smotz »

rimai wrote:Use this to prevent it from turning on when you get zeros.

Code: Select all

if ( ReefAngel.WaterLevel.GetLevel(1) <=85 && ReefAngel.WaterLevel.GetLevel(2) <=85 && ReefAngel.WaterLevel.GetLevel(1) >0 && ReefAngel.WaterLevel.GetLevel(2) >0) ReefAngel.Relay.On (Topoff);
I would start by checking the connections and usb cables.
Try a different port in the hub too.

is there a way that I can monitor the water level live without refreshing?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Multi-water level ATO dumping water when it shouldn't

Post by rimai »

Only with the use of the cloud server, which requires the cloud wifi attachment or RA Star(coming soon).
Roberto.
Post Reply