Mike's RSM 500 Code

Share you PDE file with our community
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Mike's RSM 500 Code

Post by modulok »

I have two Vortech MP40s on the way, as well as the RF Expansion and Expansion Hub. I should have everything by Tuesday.

Here are my ideas:
  • Enable Center lights on for 10mins after RA feed mode
  • MP40: Change modes throughout the day, night mode when lights are off, feed mode
  • I would like to put both MP40s on the main relay (flow1-3, return, skimmer, MP40, MP40)
  • Change Power Failure mode so that a single MP40 goes to low power mode (Main Relay Box is connected to UPS)

I was thinking to update the light schedule. I have 3 separate fixtures, and was thinking of giving each a 15 minute break every few hours. Would it work just by giving separate ReefAngel.StandardLights for a single fixture, leaving 15 min gaps when necessary?

Thanks

Here is my current code.

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 <ReefAngel.h>

//--------------------------------- Place global variable code below here ---------------------------------
boolean PowerOutage=false; 
boolean DelayedPowerOutage=false;
// Globals for Params on Custom Main
byte x,y;
char text[10];

//--------------------------------- Custom Menu  ---------------------------------
#include <avr/pgmspace.h>
prog_char menu0_label[] PROGMEM = "Turn Lights On";
prog_char menu1_label[] PROGMEM = "Turn Lights Off";
prog_char menu2_label[] PROGMEM = "Start Feeding";
prog_char menu3_label[] PROGMEM = "Start Water Change";
prog_char menu4_label[] PROGMEM = "Clear Overheat";
prog_char menu5_label[] PROGMEM = "Calibrate pH";
prog_char menu6_label[] PROGMEM = "Display Version";
PROGMEM const char *menu_items[] = {
menu0_label, menu1_label, menu2_label, menu3_label, menu4_label, menu5_label, menu6_label  };

void MenuEntry1()
{
ReefAngel.DisplayMenuEntry("Item 1");ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
#ifdef RelayExp
for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
{
    ReefAngel.Relay.RelayMaskOnE[i] = ReefAngel.LightsOnPortsE[i];
}
#endif  // RelayExp
ReefAngel.Relay.Write();

}
void MenuEntry2()
{
ReefAngel.DisplayMenuEntry("Item 2");ReefAngel.Relay.RelayMaskOn = 0;
#ifdef RelayExp
for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
{
    ReefAngel.Relay.RelayMaskOnE[i] = 0;
}
#endif  // RelayExp
ReefAngel.Relay.Write();

}
void MenuEntry3()
{
ReefAngel.DisplayMenuEntry("Item 3");ReefAngel.FeedingModeStart();

}
void MenuEntry4()
{
ReefAngel.DisplayMenuEntry("Item 4");ReefAngel.WaterChangeModeStart();

}
void MenuEntry5()
{
ReefAngel.DisplayMenuEntry("Item 5");ReefAngel.OverheatClear();

}
void MenuEntry6()
{
ReefAngel.DisplayMenuEntry("Item 6");ReefAngel.SetupCalibratePH();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;

}
void MenuEntry7()
{
ReefAngel.DisplayMenuEntry("Item 7");ReefAngel.DisplayVersion();

}
//--------------------------------- End Custom Menu Globals ---------------------------------
//--------------------------------- Place global variable code above here ---------------------------------
//--------------------------------- Begin Custom Main ---------------------------------
void DrawCustomMain()
{
ReefAngel.LCD.DrawDate(5, 2);
ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
pingSerial();

// Display T1 Probe Value
ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
ReefAngel.LCD.DrawHugeNumbers(COLOR_CRIMSON, 255, 5, 14, text);
pingSerial();

// Display pH Text
ReefAngel.LCD.DrawText(COLOR_INDIGO,255,80,14,"pH");
// Display pH Value
ConvertNumToString(text, ReefAngel.Params.PH, 100);
ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 95, 14, text, Num8x16);
pingSerial();

// Display T3 Probe Text
ReefAngel.LCD.DrawText(COLOR_ROYALBLUE,255,80,24,"Rm");
// Display T3 Probe Value
ConvertNumToString(text, ReefAngel.Params.Temp[T3_PROBE], 10);
ReefAngel.LCD.DrawLargeText(COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16);
pingSerial();
//Moon Phase
ReefAngel.LCD.Clear(DefaultBGColor,5,88,95,95);
ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,5,88,MoonPhaseLabel());
//Dimmable Moon LEDs
ReefAngel.LCD.DrawText(COLOR_NAVY,255,5,98, "MoonLEDs:");
ReefAngel.LCD.Clear(DefaultBGColor,59,98,75,106);
ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,59,98, ReefAngel.PWM.GetActinicValue());
ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,75,98, "%");
  
// Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();

// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();

}

void DrawCustomGraph()
{}
//--------------------------------- End Custom Main ---------------------------------
//--------------------------------- Begin Setup ---------------------------------
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    // Initialize the menu
    ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));
    
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port7Bit; //Flow1-3,Return,Skimmer,CoolingFan
    ReefAngel.FeedingModePortsE[0] = Port2Bit | Port6Bit; //FrontT5,SumpHeater
    
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port7Bit; // Flow1-3,Return,Skimmer,DispHeater,CoolingFan
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port6Bit; //Front+BackT5,SumpHeater
    
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5
    
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port6Bit; //DispHeater
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port5Bit | Port6Bit; //Front+BackT5,FugeLight,SumpHeater
    
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );
    
    //--------------------------------- Place additional initialization code below here ---------------------------------
    ReefAngel.Timer[1].SetInterval(5);
    //--------------------------------- Place additional initialization code above here ---------------------------------
}
//--------------------------------- End Setup ---------------------------------
//--------------------------------- Begin Loop ---------------------------------
void loop()
{
    // Ports that are always on
    ReefAngel.Relay.On( Port1 ); //Flow1
    ReefAngel.Relay.On( Port2 ); //Flow2
    ReefAngel.Relay.On( Port3 ); //Flow3
    ReefAngel.Relay.On( Port4 ); //Return
    
    //Delay Start
    ReefAngel.Relay.DelayedOn( Port5,5 ); //Skimmer

    /*Feed Mode Delay on Pump
    static boolean feeding=true;
    static unsigned long feedingstarted = 0;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE)
    {
      if (!feeding)
      {
      feeding=true;
      feedingstarted = now();
      }
    } else {
      feeding=false;
    }
    
    int pumpdelay=InternalMemory.FeedingTimer_read()-240; // 4 minute delay
    if (now()-feedingstarted<=pumpdelay) {
      ReefAngel.Relay.Off( Port1 ); //Flow1
      ReefAngel.Relay.Off( Port2 ); //Flow2
      ReefAngel.Relay.Off( Port3 ); //Flow3
    }
    */
       
    // Ports that are delayed on Power Cycle & Feeding & Water Change
    if (PowerOutage && ReefAngel.Relay.IsRelayPresent(EXP1_RELAY))
    {
      PowerOutage=false;
      DelayedPowerOutage=false;
      LastStart=now();
    }
         
    // Heaters
    ReefAngel.StandardHeater( Port6,770,774 ); //DispHeater
    ReefAngel.StandardHeater( Box1_Port6,768,772 ); //SumpHeater
    
    // Cooling Fan
    ReefAngel.StandardFan( Port7,812,814 ); //Cooling Fan
    
    // T5 Light Schedule
    ReefAngel.StandardLights( Box1_Port1,9,0,20,0 ); //CenterT5 9a-8p
    ReefAngel.StandardLights( Box1_Port2,10,0,18,0 ); //FrontT5 10a-6p
    ReefAngel.StandardLights( Box1_Port3,10,30,18,45 ); //BackT5 1030a-645p
    
    // RSMLED Moonlight Schedule
    if (hour()>=6 && hour()<=8) ReefAngel.StandardLights( Box1_Port4,6,0,8,59 ); //RSMLED Morning 6a-9a
    else if(hour()>=20 && hour()<=23) ReefAngel.StandardLights( Box1_Port4,20,0,23,45 ); //RSMLED Evening 8p-1145p
    else if(hour()>=23 || hour()<=4) if (MoonPhase()>=90) ReefAngel.StandardLights( Box1_Port4,23,46,4,0 ); //RSMLED on for Full Moon 1146p-4a
    
    // Fuge Light Schedule
    //ReefAngel.StandardLights( Box1_Port5,0,0,8,0 ); //FugeLight 12a-8a
    
    // PWM Dimmable Moonlights Schedule
    if (hour()>=21 || hour()<4) // Turn Dimmable Moonlights on 9p & off 4a
    {
      ReefAngel.PWM.SetActinic(MoonPhase());
      ReefAngel.PWM.SetDaylight(MoonPhase());
    }
    else
    {
      ReefAngel.PWM.SetActinic(0);
      ReefAngel.PWM.SetDaylight(0);
    }
    
    //--------------------------------- Place your custom code below here ---------------------------------
    // Turn on Fuge light during water change mode
    //if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.On(Box1_Port5);
    
    // Power Outage - Only Flow2 port on
    if (!ReefAngel.Relay.IsRelayPresent(EXP1_RELAY)) PowerOutage=true; //Exp1 Relay NOT present
    if (!PowerOutage)
    { 
      ReefAngel.Timer[1].Start();
    } 
    if (ReefAngel.Timer[1].IsTriggered())
    { 
      DelayedPowerOutage=true;
    }
    if (DelayedPowerOutage)
    {
    ReefAngel.Relay.Off (Port1); //Flow1
    //ReefAngel.Relay.Off (Port2); //Flow2
    ReefAngel.Relay.Off (Port3); //Flow3
    ReefAngel.Relay.Off (Port4); //Return
    ReefAngel.Relay.Off (Port5); //Skimmer
    ReefAngel.Relay.Off (Port6); //Heater
    }
    
    // Skimmer off when Return pump is off.
    if (bitRead(ReefAngel.Relay.RelayMaskOff,3)==0) //Return
    {
        bitClear(ReefAngel.Relay.RelayMaskOff,4); //Skimmer
    }
    
    //////////// Place your custom code above here //////////// 

    // This should always be the last line
    ReefAngel.Portal( "modulok" );
    ReefAngel.ShowInterface();
}
//--------------------------------- End Loop ---------------------------------
Last edited by modulok on Fri Sep 13, 2013 6:54 pm, edited 1 time in total.
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Here is what I am thinking for the light schedule. Giving each fixture a 15min break every 2hrs. Any reason why it would be bad for the lights/fixture?

Code: Select all

    // Center T5 Light Schedule [ 9:15am - 6:00pm ]
    ReefAngel.StandardLights( CenterT5,9,15,11,15 ); //0915-1115
    ReefAngel.StandardLights( CenterT5,11,30,13,30 ); //1130-1330
    ReefAngel.StandardLights( CenterT5,13,45,15,45 ); //1345-1545
    ReefAngel.StandardLights( CenterT5,16,00,18,00 ); //1600-1800
        
    // Front T5 Light Schedule [ 10:00am - 6:45pm ]
    ReefAngel.StandardLights( FrontT5,10,0,12,0 ); //1000-1200
    ReefAngel.StandardLights( FrontT5,10,0,18,0 ); //1215-1415
    ReefAngel.StandardLights( FrontT5,10,0,18,0 ); //1430-1630
    ReefAngel.StandardLights( FrontT5,10,0,18,0 ); //1645-1845
    
    // Back T5 Light Schedule [ 11:15am - 8:00pm ]
    ReefAngel.StandardLights( BackT5,11,15,13,15 ); //1115-1315
    ReefAngel.StandardLights( BackT5,13,30,15,30 ); //1330-1530
    ReefAngel.StandardLights( BackT5,15,45,17,45 ); //1545-1745
    ReefAngel.StandardLights( BackT5,18,0,20,0 ); //1800-2000
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

It works, but you need to do some leg work, which would make it very hard to understand.
The way I would do it is set the StandardLights for the entire period and override it off when you what them off
Something like this:

Code: Select all

ReefAngel.StandardLights( CenterT5,9,15,18,0 ); //0915-1800
if (hour()==11 && minute()>=15 && minute()<=30) ReefAngel.Relay.Off(CenterT5);
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Something is very wrong now. After a few minutes, the red light starts blinking on the RA. On the display only a few ports shown as on, although everything that should be on is in fact on. Same ports show as on with the Android app. Can't turn on anything either.

I did a full power cycle for both relays and it did not help.

I added both MP40s to the RA (used the vortech setup code and such), and they are both white and running.

EDIT: ok, 8PM now, center T5 is still on, App and LCD show it as turned off. MoonLEDs should be on, like signature says, but they are not. I'm going to revert back to older code and see if problem is still there.

Any suggestions? I'm going to wait until 8 and see if the light goes off like it should.

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 <ReefAngel.h>

// Define Relay Ports by Name
#define Flow1           1
#define Flow2           2
#define Flow3           3
#define Return          4
#define Skimmer         5
#define VortechL        6
#define VortechR        7
#define HeaterDisp      8

#define CenterT5        Box1_Port1
#define FrontT5         Box1_Port2
#define BackT5          Box1_Port3
#define MoonLED         Box1_Port4
#define Unused          Box1_Port5
#define Unused          Box1_Port6
#define FanSump         Box1_Port7
#define HeaterSump      Box1_Port8

//--------------------------------- Place global variable code below here ---------------------------------
boolean PowerOutage=false; 
boolean DelayedPowerOutage=false;
// Globals for Params on Custom Main
byte x,y;
char text[10];

//--------------------------------- Custom Menu  ---------------------------------
#include <avr/pgmspace.h>
prog_char menu0_label[] PROGMEM = "Turn Lights On";
prog_char menu1_label[] PROGMEM = "Turn Lights Off";
prog_char menu2_label[] PROGMEM = "Start Feeding";
prog_char menu3_label[] PROGMEM = "Start Water Change";
prog_char menu4_label[] PROGMEM = "Clear Overheat";
prog_char menu5_label[] PROGMEM = "Calibrate pH";
prog_char menu6_label[] PROGMEM = "Display Version";
PROGMEM const char *menu_items[] = {
menu0_label, menu1_label, menu2_label, menu3_label, menu4_label, menu5_label, menu6_label  };

void MenuEntry1()
{
ReefAngel.DisplayMenuEntry("Item 1");ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
#ifdef RelayExp
for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
{
    ReefAngel.Relay.RelayMaskOnE[i] = ReefAngel.LightsOnPortsE[i];
}
#endif  // RelayExp
ReefAngel.Relay.Write();

}
void MenuEntry2()
{
ReefAngel.DisplayMenuEntry("Item 2");ReefAngel.Relay.RelayMaskOn = 0;
#ifdef RelayExp
for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
{
    ReefAngel.Relay.RelayMaskOnE[i] = 0;
}
#endif  // RelayExp
ReefAngel.Relay.Write();

}
void MenuEntry3()
{
ReefAngel.DisplayMenuEntry("Item 3");ReefAngel.FeedingModeStart();

}
void MenuEntry4()
{
ReefAngel.DisplayMenuEntry("Item 4");ReefAngel.WaterChangeModeStart();

}
void MenuEntry5()
{
ReefAngel.DisplayMenuEntry("Item 5");ReefAngel.OverheatClear();

}
void MenuEntry6()
{
ReefAngel.DisplayMenuEntry("Item 6");ReefAngel.SetupCalibratePH();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;

}
void MenuEntry7()
{
ReefAngel.DisplayMenuEntry("Item 7");ReefAngel.DisplayVersion();

}
//--------------------------------- End Custom Menu Globals ---------------------------------
//--------------------------------- Place global variable code above here ---------------------------------
//--------------------------------- Begin Custom Main ---------------------------------
void DrawCustomMain()
{
ReefAngel.LCD.DrawDate(5, 2);
ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
pingSerial();

// Display T1 Probe Value
ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
ReefAngel.LCD.DrawHugeNumbers(COLOR_CRIMSON, 255, 5, 14, text);
pingSerial();

// Display pH Text
ReefAngel.LCD.DrawText(COLOR_INDIGO,255,80,14,"pH");
// Display pH Value
ConvertNumToString(text, ReefAngel.Params.PH, 100);
ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 95, 14, text, Num8x16);
pingSerial();

// Display T3 Probe Text
ReefAngel.LCD.DrawText(COLOR_ROYALBLUE,255,80,24,"Rm");
// Display T3 Probe Value
ConvertNumToString(text, ReefAngel.Params.Temp[T3_PROBE], 10);
ReefAngel.LCD.DrawLargeText(COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16);
pingSerial();
//Moon Phase
ReefAngel.LCD.Clear(DefaultBGColor,5,88,95,95);
ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,5,88,MoonPhaseLabel());
//Dimmable Moon LEDs
ReefAngel.LCD.DrawText(COLOR_NAVY,255,5,98, "MoonLEDs:");
ReefAngel.LCD.Clear(DefaultBGColor,59,98,75,106);
ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,59,98, ReefAngel.PWM.GetActinicValue());
ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,75,98, "%");
  
// Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();

// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();

}

void DrawCustomGraph()
{}
//--------------------------------- End Custom Main ---------------------------------
//--------------------------------- Begin Setup ---------------------------------
void setup()
{
    // This must be the first line
    ReefAngel.Init(); //Initialize controller
    ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items)); // Initialize the menu
    
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit; //Flow1-3,Return,Skimmer
    ReefAngel.FeedingModePortsE[0] = Port2Bit | Port7Bit | Port8Bit; //FrontT5,FanSump,SumpHeater
    
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit; // Flow1-3,Return,Skimmer,DispHeater
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port7Bit | Port8Bit; //Front+BackT5,FanSump,SumpHeater
    
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5
    
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //DispHeater
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port8Bit; //Center+Front+BackT5,SumpHeater
    
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );
    
    //--------------------------------- Place additional initialization code below here ---------------------------------
    ReefAngel.Timer[1].SetInterval(5);
    //--------------------------------- Place additional initialization code above here ---------------------------------
}
//--------------------------------- End Setup ---------------------------------
//--------------------------------- Begin Loop ---------------------------------
void loop()
{
    // Ports that are always on
    ReefAngel.Relay.On( Flow1 );
    ReefAngel.Relay.On( Flow2 );
    ReefAngel.Relay.On( Flow3 );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    
    // Ports that are delayed on Power Cycle & Feeding & Water Change
    ReefAngel.Relay.DelayedOn( Skimmer,1 );
    
    //Vortech
    ReefAngel.RF.UseMemory = false;
    ReefAngel.RF.SetMode( ReefCrest,30,10 );

    /*Feed Mode Delay on Pump
    static boolean feeding=true;
    static unsigned long feedingstarted = 0;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE)
    {
      if (!feeding)
      {
      feeding=true;
      feedingstarted = now();
      }
    } else {
      feeding=false;
    }
    
    int pumpdelay=InternalMemory.FeedingTimer_read()-240; // 4 minute delay
    if (now()-feedingstarted<=pumpdelay) {
      ReefAngel.Relay.Off( Flow1 );
      ReefAngel.Relay.Off( Flow2 );
      ReefAngel.Relay.Off( Flow3 );
    }
    */
       
    // Temperature
    ReefAngel.StandardHeater( HeaterDisp,770,774 );
    ReefAngel.StandardHeater( HeaterSump,768,772 );
    ReefAngel.StandardFan( FanSump,812,814 );
    
    // Light Schedule
    ReefAngel.StandardLights( CenterT5,9,0,20,0 ); //CenterT5 9a-8p
    if (hour()==12 && minute()>=30 && minute()<=45) ReefAngel.Relay.Off(CenterT5);
    if (hour()==16 && minute()>=30 && minute()<=45) ReefAngel.Relay.Off(CenterT5);
    
    ReefAngel.StandardLights( FrontT5,10,0,18,0 ); //FrontT5 10a-6p
    if (hour()==13 && minute()>=15 && minute()<=30) ReefAngel.Relay.Off(FrontT5);
    if (hour()==16 && minute()>=15 && minute()<=30) ReefAngel.Relay.Off(FrontT5);
    
    ReefAngel.StandardLights( BackT5,10,30,18,45 ); //BackT5 1030a-645p
    if (hour()==13 && minute()>=45 && minute()<=0) ReefAngel.Relay.Off(BackT5);
    if (hour()==13 && minute()>=45 && minute()<=0) ReefAngel.Relay.Off(BackT5);
    
    // RSMLED Moonlight Schedule
    if (hour()>=6 && hour()<=8) ReefAngel.StandardLights( MoonLED,6,0,8,59 ); //RSMLED Morning 6a-9a
    else if(hour()>=20 && hour()<=23) ReefAngel.StandardLights( MoonLED,20,0,23,45 ); //RSMLED Evening 8p-1145p
    else if(hour()>=23 || hour()<=4) if (MoonPhase()>=90) ReefAngel.StandardLights( MoonLED,23,46,4,0 ); //RSMLED on for Full Moon 1146p-4a
    
    // PWM Dimmable Moonlights Schedule
    if (hour()>=21 || hour()<4) // Turn Dimmable Moonlights on 9p & off 4a
    {
      ReefAngel.PWM.SetActinic(MoonPhase());
      ReefAngel.PWM.SetDaylight(MoonPhase());
    }
    else
    {
      ReefAngel.PWM.SetActinic(0);
      ReefAngel.PWM.SetDaylight(0);
    }
    
    //--------------------------------- Place your custom code below here ---------------------------------
    // Turn on Fuge light during water change mode
    //if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.On(Box1_Port5);
    
    if (PowerOutage && ReefAngel.Relay.IsRelayPresent(EXP1_RELAY))
    {
      PowerOutage=false;
      DelayedPowerOutage=false;
      LastStart=now();
    }
    
    // Power Outage
    if (!ReefAngel.Relay.IsRelayPresent(EXP1_RELAY)) PowerOutage=true; //Expansion Relay 1 has lost power
    if (!PowerOutage)
    { 
      ReefAngel.Timer[1].Start();
    } 
    if (ReefAngel.Timer[1].IsTriggered())
    { 
      DelayedPowerOutage=true;
    }
    if (DelayedPowerOutage)
    {
    ReefAngel.Relay.Off (Flow1);
    ReefAngel.Relay.Off (Flow2);
    ReefAngel.Relay.Off (Flow3);
    ReefAngel.Relay.Off (Return);
    ReefAngel.Relay.Off (Skimmer);
    ReefAngel.Relay.Off (VortechL);
    ReefAngel.Relay.Off (HeaterDisp);
    }
    
    // When Return pump is off shut off Skimmer & FanSump
    if (!ReefAngel.Relay.Status(Return)) {
      ReefAngel.Relay.Override(Skimmer,0); 
      ReefAngel.Relay.Override(FanSump,0);
    }
   
    //--------------------------------- Place your custom code above here --------------------------------- 

    // This should always be the last line
    ReefAngel.Portal( "modulok" );
    ReefAngel.ShowInterface();
}
//--------------------------------- End Loop ---------------------------------
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Went back to old code and it looks like its stable again. I got scared when I saw the heater light turn on, but the RA and app wasn't aware of that!

On the setup for both Vortech MP40s...I did the reset on each unit and hooked the BOTH to the RF unit. Each pump is either white or orange (when pressing mode).

Is this correct? Do the pumps think the RF module is the master pump, and you can set the left or right pump to sync/anti-sync?
ie: Left Vortech white driver and Right Vortech orange driver for anti-sync/opposite side as master.

EDIT: Also, why does the app show this?
Mode Reef Crest
Speed 20%
Duration 20%

Isn't the code below stating 10 duration?
ReefAngel.RF.UseMemory = false;
ReefAngel.RF.SetMode( ReefCrest,20,10 );
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

I uploaded new code, still stuck with ReefCrest, 20, 10. Had the same issue with the blinking red light on controller, and no response from android app.

I commented out the RF lines and reuploaded. Now both MP40s are in Nutrient Mode, at 50% power and 10ms. I NEVER set a mode other than ReefCrest. What is going on here?

Edit: Red blinking light is back! Cannot control anything again, will need to power cycle the head unit.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

Yes, the pumps will think that the RF module is master and each pump can be setup as sync (white) or anti-sync(orange).
If you use ReefAngel.RF.UseMemory = true;, that's when the controller will use the settings shown in the app or portal.
If you use ReefAngel.RF.UseMemory = false;, it will ignore the memory settings and use your hard coded settings
In my case, I use memory settings (long pulse at 75% with 300s pulse) during the day. I change to UseMemory = false at night to slow down the pumps and also at 3pm through 6pm when it runs long pulse at 100% with 3s pulse.
This is the code for your reference:

Code: Select all

  if (ReefAngel.DisplayedMenu!=FEEDING_MODE || ReefAngel.DisplayedMenu!=WATERCHANGE_MODE)
  {
    if (hour()>=15 && hour()<=17)
    {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(LongWave,100,3);
    }
    else if (hour()>=22 || hour()<7)
    {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(ReefCrest,40,0);
    }
    else
    {
      ReefAngel.RF.UseMemory=true;
    }
  }
The red blinking is being cause by noise or bad connection somewhere in the expansion bus.
Can you check your connections and see if you've got any cables going too close to any ballasts/drivers?
If that doesn't work, we can try changing the firmware of the rf module.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

What do you mean by ballasts/drivers? I have both relay boxes, expansion, relay exp,and RF exp in close proximity, and the wifi exp is the only one next to the RA head unit. The two MP40 drivers are 2-3 feet from other equip right now.

I am thinking that when I commented out the RF lines the internal memory setting took over. On the portal it does say Nutrient @ 50%...
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

I meant LED drivers/MH ballasts.
They generate quite a bit of noise and interference that can be picked up by the bus if place too close to them.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

OK, only LEDs I have are the moonlights on the PWM, which have been in the same location since January.

I will replug everything and see if issue persists...if that's not it, how do I do firmware for RF exp?
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

OK, when I unplug the RF module the red light turns off. And I can control ports.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

Try this update.
You need to open the enclosure and connect the USB-TTL cable with the black wire on the GND pin.
Then, you need to edit the file update.bat to use whatever com port you are using.
Double-click the update.bat file to start updating.
Attachments
update.zip
(427.13 KiB) Downloaded 505 times
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Which is the ground pin?
Image
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

Sorry, I forgot to say to remove the RF module too.
RF.png
RF.png (18.62 KiB) Viewed 8639 times
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

libusb0.dll is missing error when I run the bat file (avrdude.exe)

EDIT:Got the fix...Had to copy that file to c:\Windows\syswow64
RF firmware should be updated now. Going to plug it back in and see what happens.
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Same issue....after a bit red light comes on and relays don't toggle on/off. When I unplug RF module the relays toggle (even when I manually toggle when red light is blinking).

Is my RF module a dud?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

Ok, are you sure you got it updated?
Did it go through the % from 0 to 100?
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

OK, I didn't see any percentage...the command window closed when it was finished. I just re-ran the update by running it manually so the window didn't auto exit.

EDIT: My RA just had two power outage scenarios (code that was working fine), when power was fine (relay exp never lost power). Could the root cause be the new Expansion Hub?

Code: Select all

avrdude -Cavrdude.conf -v -patmega328p
-carduino -P\\.\COM6 -b115200 -D -Uflash:w:RF_Update_WDT_modified.hex:i

avrdude: Version 6.0, compiled on Apr  6 2012 at 19:29:19
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "avrdude.conf"

         Using Port                    : \\.\COM6
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
Rebooting Reef Angel Controller
avrdude: stk500_getsync(): not in sync: resp=0x64

avrdude done.  Thank you.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

No, it didn't upload.
It needs to upload just like in RA.
It will flash the red led for a few seconds and there will be a % bar.
Did you remove the Ecotech RF module?
It won't work with the RF module plugged into the board.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

I don't think I understand...here is what I did.

I unplugged the RF Exp Module and removed the board from the plastic case. Hooked up the USB TTL to the RF board (pic I posted above) black wire to ground pin. Connect USB end to computer and run the command.

Sent from my Nexus 7 using Tapatalk 4
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

You must also remove the Ecotech RF module before you can upload or it will thing the serial data is supposed to be sent to the vortech drivers.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

It's been awhile since I have needed to update code, but the power outage function wasn't working.

Not sure why but the power outage was below "// This should always be the last line" When I moved it up I couldn't compile. What did I do wrong here?

Thanks!

Getting the following compile error at: void CheckPower() {

Code: Select all

updated_code.cpp: In function 'void loop()':
updated_code:165: error: a function-definition is not allowed here before '{' token
updated_code:257: error: expected `}' at end of input

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 <ReefAngel.h>

// Define Named Relay Ports
#define Flow1           1
#define Flow2           2
#define Flow3           3
#define Return          4
#define Skimmer         5
#define VortechL        6
#define VortechR        7
#define HeaterDisp      8

#define CenterT5        Box1_Port1
#define FrontT5         Box1_Port2
#define BackT5          Box1_Port3
#define MoonLED         Box1_Port4
#define Unused          Box1_Port5
#define Reactor         Box1_Port6
#define Fan             Box1_Port7
#define HeaterSump      Box1_Port8

////// Place global variable code below here
// Custom Main
byte x,y;
char text[10];

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

////// Setup Begin
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    
    // Controlled Modes Toggled Ports
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit; //Fan,HeaterSump
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit; // Flow1-3,Return,Skimmer,HeaterDisp
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; //Front+BackT5,Reactor,Fan,HeaterSump
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5
    
    // Water Temperature Settings & Overheat
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 820 );
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterDisp
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port8Bit; //Front+BackT5,HeaterSump

    // Ports that are always on
    ReefAngel.Relay.On( Flow1 );
    ReefAngel.Relay.On( Flow2 );
    ReefAngel.Relay.On( Flow3 );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    ReefAngel.Relay.On( Reactor );
    // Ports that are always off
    ReefAngel.Relay.Off(Unused);

    ////// Place additional initialization code below here
    
    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval(5);
    
    ////// Place additional initialization code above here
}
////// Setup End

////// Loop Begin
void loop()
{
    // Ports that are Delayed
    ReefAngel.Relay.DelayedOn( Skimmer,2 );
    // Temperature Control
    ReefAngel.StandardHeater( HeaterSump,770,773 );
    ReefAngel.StandardHeater( HeaterDisp,767,770 );
    ReefAngel.StandardFan( Fan,810,814 );
    // T5 Light Schedule
    ReefAngel.StandardLights( CenterT5,9,0,20,0 );
        if (hour()==14 && minute()>=0 && minute()<=59) ReefAngel.Relay.Off(CenterT5);
    ReefAngel.StandardLights( FrontT5,10,0,18,0 );
	if (hour()==15 && minute()>=0 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    ReefAngel.StandardLights( BackT5,11,0,19,0 );
        if (hour()==16 && minute()>=0 && minute()<=29) ReefAngel.Relay.Off(BackT5);

////// Place your custom code below here
    
    // RSM MoonLED Schedule
    if (hour()>=6 && hour()<=8) ReefAngel.StandardLights( MoonLED,6,0,8,59 ); //Morning
    else if(hour()>=20 && hour()<=23) ReefAngel.StandardLights( MoonLED,20,0,23,45 ); //Evening
    else if(hour()>=23 || hour()<=4) if (MoonPhase()>=90) ReefAngel.StandardLights( MoonLED,23,46,4,0 ); //Full Moon
    
    // Moonphase LED Schedule
    if (hour()>=20 || hour()<4)
    {
      ReefAngel.PWM.SetActinic(MoonPhase());
      ReefAngel.PWM.SetDaylight(MoonPhase());
    }
    else
    {
      ReefAngel.PWM.SetActinic(0);
      ReefAngel.PWM.SetDaylight(0);
    }
    //T5 Light Off Variable
    //if (hour()==12 && minute()>=30 && minute()<=44) ReefAngel.Relay.Off(CenterT5);
    //if (hour()==12 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==16 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5); 
    //if (hour()==13 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    //if (hour()==16 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    
    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if (ReefAngel.DisplayedMenu!=FEEDING_MODE || ReefAngel.DisplayedMenu!=WATERCHANGE_MODE)
    {
      if (hour()>=16 && hour()<=19)
      {
        ReefAngel.RF.UseMemory=false;
        ReefAngel.RF.SetMode(LongWave,50,30);
      }
        else if (hour()>=20 || hour()<7)
        {
          ReefAngel.RF.UseMemory=false;
          ReefAngel.RF.SetMode(Lagoon,25,0);
        }
        else
        {
          ReefAngel.RF.UseMemory=true;
        }
     }

    // When Return pump is off so is Skimmer
    if (!ReefAngel.Relay.Status(Return)) {
      ReefAngel.Relay.Override(Skimmer,0); 
    }

void CheckPower() {
  static boolean PowerOutage=false;
  static boolean DelayedPowerOutage=false;
    
    // Power Outage - Leave Single Flow Pump Powered
    if (!ReefAngel.Relay.IsRelayPresent(EXP1_RELAY)) PowerOutage=true; //Expansion Relay 1 has lost power
    if (!PowerOutage)
    { 
      ReefAngel.Timer[1].Start();
    } 
    if (ReefAngel.Timer[1].IsTriggered())
    { 
      DelayedPowerOutage=true;
    }
    if (DelayedPowerOutage)
    {
    ReefAngel.Relay.Off (Flow1);
    ReefAngel.Relay.Off (Flow2);
    ReefAngel.Relay.Off (Flow3);
    ReefAngel.Relay.Off (Return);
    ReefAngel.Relay.Off (Skimmer);
    ReefAngel.Relay.Off (HeaterDisp);
    //set vortechs to low power
    }
    
    // Power Restored
    if (PowerOutage && ReefAngel.Relay.IsRelayPresent(EXP1_RELAY))
    {
      PowerOutage=false;
      DelayedPowerOutage=false;
      LastStart=now();
    }
}
////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "*****","*****" );
    ReefAngel.ShowInterface();
}
////// Loop End

////// Custom Main Begin
void DrawCustomMain()
{
// Display Date & Time
    ReefAngel.LCD.DrawDate(5, 2);
    ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
    pingSerial();

// Display Water Temp Value
    ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
    ReefAngel.LCD.DrawHugeNumbers(COLOR_CRIMSON, 255, 5, 14, text);
    pingSerial();
// Display pH Text
    ReefAngel.LCD.DrawText(COLOR_INDIGO,255,80,14,"pH");
// Display pH Value
    ConvertNumToString(text, ReefAngel.Params.PH, 100);
    ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 95, 14, text, Num8x16);
    pingSerial();
// Display Room Temp Text
    ReefAngel.LCD.DrawText(COLOR_ROYALBLUE,255,80,24,"Rm");
// Display Room Temp Value
    ConvertNumToString(text, ReefAngel.Params.Temp[T3_PROBE], 10);
    ReefAngel.LCD.DrawLargeText(COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16);
    pingSerial();
// Vortech Info

//Moon Phase
    ReefAngel.LCD.Clear(DefaultBGColor,5,88,95,95);
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,5,88,MoonPhaseLabel());
//Dimmable Moon LEDs
    ReefAngel.LCD.DrawText(COLOR_NAVY,255,5,98, "MoonLEDs:");
    ReefAngel.LCD.Clear(DefaultBGColor,59,98,75,106);
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,59,98, ReefAngel.PWM.GetActinicValue());
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,75,98, "%");
  // Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();
// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();
}
////// Custom Main End

////// Custom Graph Begin
void DrawCustomGraph()
{}
///// Custom Graph End
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

you cannot define a function within another function. your checkpower function is being defined inside the loop function code.
move it out and that should help.


Sent from my Nexus 7
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

I went ahead and updated your code and moved everything around how it should be. I test compiled and everything compiles just fine. I did not upload the code to a controller though.

The formatting is updated too. You will also need to put your portal information back in since you removed it before.
Hope this helps.

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 <ReefAngel.h>

// Define Named Relay Ports
#define Flow1           1
#define Flow2           2
#define Flow3           3
#define Return          4
#define Skimmer         5
#define VortechL        6
#define VortechR        7
#define HeaterDisp      8

#define CenterT5        Box1_Port1
#define FrontT5         Box1_Port2
#define BackT5          Box1_Port3
#define MoonLED         Box1_Port4
#define Unused          Box1_Port5
#define Reactor         Box1_Port6
#define Fan             Box1_Port7
#define HeaterSump      Box1_Port8

////// Place global variable code below here
// Custom Main
byte x, y;
char text[10];

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

////// Setup Begin
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller

    // Controlled Modes Toggled Ports
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit; //Fan,HeaterSump
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit; // Flow1-3,Return,Skimmer,HeaterDisp
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; //Front+BackT5,Reactor,Fan,HeaterSump
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5

    // Water Temperature Settings & Overheat
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 820 );
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterDisp
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port8Bit; //Front+BackT5,HeaterSump

    // Ports that are always on
    ReefAngel.Relay.On( Flow1 );
    ReefAngel.Relay.On( Flow2 );
    ReefAngel.Relay.On( Flow3 );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    ReefAngel.Relay.On( Reactor );
    // Ports that are always off
    ReefAngel.Relay.Off( Unused );

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

    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval( 5 );

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

////// Loop Begin
void loop()
{
    // Ports that are Delayed
    ReefAngel.Relay.DelayedOn( Skimmer, 2 );
    // Temperature Control
    ReefAngel.StandardHeater( HeaterSump, 770, 773 );
    ReefAngel.StandardHeater( HeaterDisp, 767, 770 );
    ReefAngel.StandardFan( Fan, 810, 814 );
    // T5 Light Schedule
    ReefAngel.StandardLights( CenterT5, 9, 0, 20, 0 );

    if ( hour() == 14 && minute() >= 0 && minute() <= 59 ) {
        ReefAngel.Relay.Off( CenterT5 );
    }

    ReefAngel.StandardLights( FrontT5, 10, 0, 18, 0 );

    if ( hour() == 15 && minute() >= 0 && minute() <= 29 ) {
        ReefAngel.Relay.Off( FrontT5 );
    }

    ReefAngel.StandardLights( BackT5, 11, 0, 19, 0 );

    if ( hour() == 16 && minute() >= 0 && minute() <= 29 ) {
        ReefAngel.Relay.Off( BackT5 );
    }

////// Place your custom code below here

    // RSM MoonLED Schedule
    if ( hour() >= 6 && hour() <= 8 ) {
        ReefAngel.StandardLights( MoonLED, 6, 0, 8, 59 );    //Morning
    } else if( hour() >= 20 && hour() <= 23 ) {
        ReefAngel.StandardLights( MoonLED, 20, 0, 23, 45 );    //Evening
    } else if( hour() >= 23 || hour() <= 4 ) if ( MoonPhase() >= 90 ) {
            ReefAngel.StandardLights( MoonLED, 23, 46, 4, 0 );    //Full Moon
        }

    // Moonphase LED Schedule
    if ( hour() >= 20 || hour() < 4 ) {
        ReefAngel.PWM.SetActinic( MoonPhase() );
        ReefAngel.PWM.SetDaylight( MoonPhase() );
    } else {
        ReefAngel.PWM.SetActinic( 0 );
        ReefAngel.PWM.SetDaylight( 0 );
    }

    //T5 Light Off Variable
    //if (hour()==12 && minute()>=30 && minute()<=44) ReefAngel.Relay.Off(CenterT5);
    //if (hour()==12 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==16 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==13 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    //if (hour()==16 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);

    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
        if ( hour() >= 16 && hour() <= 19 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( LongWave, 50, 30 );
        } else if ( hour() >= 20 || hour() < 7 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( Lagoon, 25, 0 );
        } else {
            ReefAngel.RF.UseMemory = true;
        }
    }

    // When Return pump is off so is Skimmer
    if ( !ReefAngel.Relay.Status( Return ) ) {
        ReefAngel.Relay.Override( Skimmer, 0 );
    }
    
    // Check the power here, the function is defined below
    CheckPower();

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

    // This should always be the last line
    ReefAngel.Portal( "*****", "*****" );
    ReefAngel.ShowInterface();
}
////// Loop End

////// Custom Function
void CheckPower()
{
    static boolean PowerOutage = false;
    static boolean DelayedPowerOutage = false;

    // Power Outage - Leave Single Flow Pump Powered
    if ( !ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = true;    //Expansion Relay 1 has lost power
    }

    if ( !PowerOutage ) {
        ReefAngel.Timer[1].Start();
    }

    if ( ReefAngel.Timer[1].IsTriggered() ) {
        DelayedPowerOutage = true;
    }

    if ( DelayedPowerOutage ) {
        ReefAngel.Relay.Off ( Flow1 );
        ReefAngel.Relay.Off ( Flow2 );
        ReefAngel.Relay.Off ( Flow3 );
        ReefAngel.Relay.Off ( Return );
        ReefAngel.Relay.Off ( Skimmer );
        ReefAngel.Relay.Off ( HeaterDisp );
        //set vortechs to low power
    }

    // Power Restored
    if ( PowerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = false;
        DelayedPowerOutage = false;
        LastStart = now();
    }
}
////// Custom Function End

////// Custom Main Begin
void DrawCustomMain()
{
// Display Date & Time
    ReefAngel.LCD.DrawDate( 5, 2 );
    ReefAngel.LCD.Clear( COLOR_BLACK, 1, 11, 132, 11 );
    pingSerial();

// Display Water Temp Value
    ConvertNumToString( text, ReefAngel.Params.Temp[T1_PROBE], 10 );
    ReefAngel.LCD.DrawHugeNumbers( COLOR_CRIMSON, 255, 5, 14, text );
    pingSerial();
// Display pH Text
    ReefAngel.LCD.DrawText( COLOR_INDIGO, 255, 80, 14, "pH" );
// Display pH Value
    ConvertNumToString( text, ReefAngel.Params.PH, 100 );
    ReefAngel.LCD.DrawLargeText( COLOR_INDIGO, 255, 95, 14, text, Num8x16 );
    pingSerial();
// Display Room Temp Text
    ReefAngel.LCD.DrawText( COLOR_ROYALBLUE, 255, 80, 24, "Rm" );
// Display Room Temp Value
    ConvertNumToString( text, ReefAngel.Params.Temp[T3_PROBE], 10 );
    ReefAngel.LCD.DrawLargeText( COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16 );
    pingSerial();
// Vortech Info

//Moon Phase
    ReefAngel.LCD.Clear( DefaultBGColor, 5, 88, 95, 95 );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 5, 88, MoonPhaseLabel() );
//Dimmable Moon LEDs
    ReefAngel.LCD.DrawText( COLOR_NAVY, 255, 5, 98, "MoonLEDs:" );
    ReefAngel.LCD.Clear( DefaultBGColor, 59, 98, 75, 106 );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 59, 98, ReefAngel.PWM.GetActinicValue() );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 75, 98, "%" );
    // Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();
// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();
}
////// Custom Main End

////// Custom Graph Begin
void DrawCustomGraph()
{}
///// Custom Graph End

modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Thanks a lot!

I uploaded the updated code and the power outage is working now.

Strange thing is that the overheat function isn't working now...I did a full power off and it temp is 82.0 and the overheat light isn't coming on and the ports aren't shutting off....any ideas?
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

hmmm...more checking is needed. nothing is standing out to me at quick glance.


Sent from my iPad mini
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

So I recalibrated my pH probe for the first time since I set it up (Nov 2012). Before the calibration I had a pH or 8.34 and now after its at 7.75.

Could the pH be off by that much after about 2.5 years?
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Forgot to mention that I moved the pH probe from the back of the display tank to the sump, could that be the difference? I'll move it back tonight and report back.

Any ideas on the overheat function not working?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

If you get T1 above 82F, nothing happens?
Not even the status LED?
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Correct, last week t1 was at 82 and ports did not shut off and the red light did not come on. I could try and get t1 above 82.

Sent from my HTC One_M8 using Tapatalk
Image
Post Reply