Weird Feeding Mode Behavior

Share you PDE file with our community
Post Reply
btorrenga
Posts: 100
Joined: Mon Apr 16, 2012 10:22 pm

Weird Feeding Mode Behavior

Post by btorrenga »

Feeding mode is programmed to turn off two ports on my expansion relay. In addition to those two ports, however, it also turns of three more ports on the main relay. I have posted my entire file here because I cannot figure out what part of it is misbehaving. Can anyone tell what I'm missing?

Code: Select all

/* The following features are enabled for this File: 

#define DisplayImages
#define SetupExtras
#define OverheatSetup
#define DateTimeSetup
#define VersionMenu
#define wifi
#define SaveRelayState
#define RelayExp
#define InstalledRelayExpansionModules 1
#define DosingPumpIntervalSetup
#define WDT
#define CUSTOM_MENU
#define CUSTOM_MENU_ENTRIES 9
#define CUSTOM_MAIN
#define COLORS_PDE
#define ENABLE_ATO_LOGGING
#define ENABLE_EXCEED_FLAGS
#define IOEXPANSION
#define FONT_8x8
#define FONT_8x16
#define FONT_12x16
#define NUMBERS_8x8
#define NUMBERS_8x16
#define NUMBERS_12x16
#define NUMBERS_16x16
#define CUSTOM_VARIABLES

*/


#include <ReefAngel_Features.h>
#include <RA_Colors.h>
#include <RA_CustomColors.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 <Timer.h>
#include <Memory.h>
#include <IO.h>
#include <ReefAngel.h>
#include <RA_PWM.h>
#include <avr/pgmspace.h>

////// Place global variable code below here
// Initialize Buzzer variables
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long buzzerinterval = 1000;           // interval at which to sound buzzer (milliseconds)
long previousMillis = 0;

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


prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "ATO Clear";
prog_char menu4_label[] PROGMEM = "Overheat Clear";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Date / Time";
prog_char menu7_label[] PROGMEM = "Version";
prog_char menu8_label[] PROGMEM = "Turn ON/OFF Skimmer";
prog_char menu9_label[] PROGMEM = "Turn Off Skimmer";
// Group the menu entries together
PROGMEM const char *menu_items[] = {
menu1_label, menu2_label, menu3_label,
menu4_label, menu5_label, menu6_label,
menu7_label, menu8_label, menu9_label
};
    
void MenuEntry1()
{
ReefAngel.FeedingModeStart();
}
void MenuEntry2()
{
ReefAngel.WaterChangeModeStart();
}
void MenuEntry3()
{
ReefAngel.ATOClear();
ReefAngel.DisplayMenuEntry("Clear ATO Timeout");
}
void MenuEntry4()
{
ReefAngel.OverheatClear();
ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry5()
{
ReefAngel.SetupCalibratePH();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry6()
{
ReefAngel.SetupDateTime();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry7()
{
ReefAngel.DisplayVersion();
}
void MenuEntry8()
{
ReefAngel.Relay.Toggle(Box1_Port8);
ReefAngel.Relay.Write();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry9()
{
ReefAngel.Relay.Off(Box1_Port8);
ReefAngel.Relay.Write();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}

void DrawCustomMain()
{
  ReefAngel.LCD.DrawDate(6, 119);
  pingSerial();
#if defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params);
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();
  // draw main relay
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
#ifdef RelayExp
  pingSerial();
  // draw 1st expansion relay
  TempRelay = ReefAngel.Relay.RelayDataE[0];
  TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
  TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
  ReefAngel.LCD.DrawOutletBox(12, 105, TempRelay);
#endif  // RelayExp
}
void DrawCustomGraph()
{
  // Change the 45 to adjust the horizontal position of the text 
  ReefAngel.LCD.DrawGraph(5, 5);
}


void CheckReservoirStatus(byte channel, byte pump)
{
    if ( ReefAngel.IO.GetChannel(channel) )
    {
        // If empty, shutoff the port, trigger alert
        ReefAngel.CustomVar[channel] = 1;
        ReefAngel.Relay.Off(pump);
    }
    else
    {
        // If not empty, turn on the port, clear alert
        ReefAngel.CustomVar[channel] = 0;
        ReefAngel.Relay.On(pump);
    }
}


void MyCustomATO(int ATOTimeout)
{
    /*
    This function works as follows:

    When it's time to topoff the system, we check the levels of each
    of the three reservoirs.  If a reservoir is empty, we set a custom
    flag to indicate it's empty on the portal and we do not start that
    pump.  Otherwise, we clear the custom flag for the reservoir and
    start the pump.
    The function monitors the switch levels like normal.
    Monitor the status of the reservoirs while topping off.
    When the high switch is triggered (aka, finished topping off), 
    ALL ports are turned off regardless of status (doesn't hurt to do this).
    If the timeout occurs, the LED light comes on and all ports are 
    turned off just like when we finish topping off.
    
    */
    unsigned long TempTimeout = ATOTimeout;
    TempTimeout *= 1000;

    if ( ReefAngel.LowATO.IsActive() && ( !ReefAngel.LowATO.IsTopping()) )
    {
        ReefAngel.LowATO.Timer = millis();
        ReefAngel.LowATO.StartTopping();

        // Check the level of each reservoir
        // If empty, set the alert and don't start topping off
        // otherwise if not empty, clear the alert and start topping
        CheckReservoirStatus(0, Port5);
        CheckReservoirStatus(1, Port6);
        CheckReservoirStatus(2, Box1_Port5);
    }

    // Monitor levels while topping off, to prevent a reservoir from running dry
    // Might need to remove this check here -- Nope, this seems to work fine.
    
    if ( ReefAngel.LowATO.IsTopping() )
    {
        CheckReservoirStatus(0, Port5);
        CheckReservoirStatus(1, Port6);
        CheckReservoirStatus(2, Box1_Port5);
    }

    if ( ReefAngel.HighATO.IsActive() )
    {
        ReefAngel.LowATO.StopTopping();  // stop the low ato timer
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        ReefAngel.Relay.Off(Box1_Port5);
    }

    if ( (millis()-ReefAngel.LowATO.Timer > TempTimeout) && ReefAngel.LowATO.IsTopping() )
    {
        ReefAngel.LED.On();
#ifdef ENABLE_EXCEED_FLAGS
        InternalMemory.write(ATO_Exceed_Flag, 1);
#endif  // ENABLE_EXCEED_FLAGS
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        ReefAngel.Relay.Off(Box1_Port5);
#ifdef ENABLE_ATO_LOGGING
        // bump the counter if a timeout occurs
        AtoEventCount++;
        if ( AtoEventCount >= MAX_ATO_LOG_EVENTS ) { AtoEventCount = 0; }
#endif  // ENABLE_ATO_LOGGING
    }
}

void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    // Initialize the custom menu
    ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));

    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePortsE[0] = Port4Bit | Port7Bit; //weird, this line turns off ports on main relay 5, 6 and 7, as well as expansion relay ports 4 and 7.
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port2Bit | Port4Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port4Bit;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port3Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port2Bit | Port5Bit | Port6Bit;
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port4Bit | Port5Bit | Port6Bit | Port8Bit;

    // Ports that are always on
    ReefAngel.Relay.On(Port3);
    ReefAngel.Relay.On(Box1_Port4);
    ReefAngel.Relay.On(Box1_Port7);
    ReefAngel.Relay.On(Box1_Port8);
    ////// Place additional initialization code below here
    ReefAngel.OverheatProbe = T1_PROBE; // Use Temperature probe 1 to check for overheat




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

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.StandardLights(Port1,23,0,2,0); // Moon lights on 23:00-02:00
    ReefAngel.StandardHeater(Port2,780,790); // 800w heater on at 78.0, off at 79.0
    ReefAngel.MHLights(Port4); // MH on 14:00-22:00, delay 15m if power fails
    ReefAngel.StandardLights(Port7,21,0,13,0); // Sump lights on 21:00-13:00
    ReefAngel.StandardLights(Port8);  //Was plant lights on 08:00-21:00, but now actinics
    ReefAngel.MHLights(Box1_Port1); // MH on 14:00-22:00, delay 15m if power fails
    ReefAngel.StandardHeater(Box1_Port2); // 250w heater on at 78.5, off at 79.0
    ReefAngel.StandardLights(Box1_Port3); // Actinics on 13:00-23:00
    ////// Place your custom code below here
    //ATO function
    MyCustomATO(InternalMemory.ATOTimeout_read());
    
    //Notify when sump level is low
    if ( ReefAngel.IO.GetChannel(4) )
    {
      ReefAngel.CustomVar[4]=1;
        // If the sump level is about to cavitate the pumps, then sound the alarm
        unsigned long currentMillis = millis();
        if(currentMillis - previousMillis > buzzerinterval) {
    // save the last time the buzzer turned on 
    previousMillis = currentMillis;   
    // if the buzzer is off turn it on and vice-versa:
    if (ReefAngel.PWM.GetDaylightValue() == 0)
      ReefAngel.PWM.SetDaylight(25);
    else
      ReefAngel.PWM.SetDaylight(0);
  }
    }
    else
    {
        // Turn the buzzer off when the sump level is above cavitation levels
        ReefAngel.PWM.SetDaylight(0);
        ReefAngel.CustomVar[4]=0;
    }

//If the ATO float switch is stuck, and the topoff pump timeout flag is set, then set C5=1
ReefAngel.CustomVar[5]=InternalMemory.read(ATO_Exceed_Flag);  //Note that this value should be either 0 or 1, but for some reason is 254 or 255.
    
//Vodka dosing 
      if ( ReefAngel.IO.GetChannel(3) )  //Check there is vodka in the reservoir
  {
    ReefAngel.Relay.Off(Box1_Port6);  //If no vodka, then set a variable and turn off the port
    ReefAngel.CustomVar[3]=1;
  }
  else  //If there is vodka, then dose
  {
    ReefAngel.CustomVar[3]=0;
    ReefAngel.DosingPumpRepeat1(Box1_Port6);
  }

//Monitor the water level in the display
ReefAngel.CustomVar[6]=ReefAngel.IO.GetChannel(5);
  
    ////// Place your custom code above here
    // This sends all the data to the portal
    // Do not add any custom code that changes any relay status after this line
    // The only code after this line should be the ShowInterface function
    ReefAngel.Portal("btorrenga");

    // This should always be the last line
    ReefAngel.ShowInterface();
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Weird Feeding Mode Behavior

Post by rimai »

Use this to get rid of the ones in the main box:

Code: Select all

ReefAngel.FeedingModePorts = 0; 
Roberto.
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Weird Feeding Mode Behavior

Post by binder »

Yeah, like Roberto said. If you don't have that line in there, the controller defaults to shutting off the default ports for FeedingMode. So no mention of FeedingModePorts means for it to use the defaults.
btorrenga
Posts: 100
Joined: Mon Apr 16, 2012 10:22 pm

Re: Weird Feeding Mode Behavior

Post by btorrenga »

Got it. Inserting that line fixed the issue. Thanks again for the insight.
Post Reply