Code Almost there but problems

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Code Almost there but problems

Post by mvwise »

Hello, I have mostly completed my code by using RAGen and copying bits and pieces from around the forum. For the most part my code works, but I am having trouble with the RF functions and module after feeding mode.

I am trying to use a pice of code that put the Vortech MP10 into Nutrient Transport Mode for 15 minutes after feeding mode. Once the 15 minutes were up it should revert back to the default mode (Reef Crest) as set in the memory settings. However, after feeding mode ends it reverts back to the memory settings and bypasses the NTM.

Attached is my code to date. Any suggestions would be helpful.

Code: Select all

// Autogenerated file by RAGen (v1.2.1.158), (03/08/2012 22:54)
// RA_030812_2254.ino
//
// This version designed for v0.9.0 or later
//
// Sketch borrowed from TanksNStuff

/* 
The following features are enabled for this File: 
#define DisplayImages
#define OverheatSetup
#define DateTimeSetup
#define VersionMenu
#define DirectTempSensor
#define DisplayLEDPWM
#define wifi
#define SaveRelayState
#define WDT
#define PWMEXPANSION
#define CUSTOM_MAIN
#define COLORS_PDE
#define SALINITYEXPANSION
#define RFEXPANSION
#define FONT_8x8
#define FONT_8x16

Ports assignment:
Port1 - Return Pump
Port2 - Circulation Pumps
Port3 - Heater
Port4 - Skimmer 
Port5 - Tunze ATO
Port6 - PWM Expansion Power Supply
Port7 - Fuge Light
Port8 - Fuge Moonlight
*/

#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 <Salinity>
#include <Memory.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <ReefAngel.h>

//*********************************************************************************************************************************
//--------------------------------------------------- Start of Global Variables ---------------------------------------------------

// Globals Needed for Params on Custom Main
byte x,y;
char text[10];
int v;

// Globals Needed for RF Mode on Custom Main
byte vtechmode;
byte vtechspeed;
byte vtechpercent;
boolean bFeeding=false;

//------------------------------------------------------ End of Global Variables --------------------------------------------------
//*********************************************************************************************************************************
//---------------------------------------------Custom Main for PWM Expansion Module------------------------------------------------

void DrawCustomMain()
{
        //Top Banner
        ReefAngel.LCD.DrawLargeText(COLOR_BLACK, 255, 9, 2, "WISEGUYS' REEF"); 
        ReefAngel.LCD.Clear(DefaultFGColor,3,11,126,11);
        
        //Clear Screen for Refresh
        //ReefAngel.LCD.Clear(255,1,12,128,128);
        
        // Display T1 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,10,15,"Tank");
        char text[7];
  
        // Display the T1 Temp Value
        ReefAngel.LCD.Clear(255,4,26,125,41);
        ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 4, 26, text, Font8x16);
        pingSerial();

        // Display the Salinity Header Text
        ReefAngel.LCD.DrawText(COLOR_CRIMSON,255,55,15,"Sal.");
  
        // Display the Salinity Value
        // ConvertNumToString(text, ReefAngel.Params.Salinity, 100);
        // ReefAngel.LCD.DrawLargeText(COLOR_CRIMSON, 255, 57, 26, text, Num8x16);
        ReefAngel.LCD.DrawLargeText(COLOR_CRIMSON, 255, 57, 26, "35", Font8x16); // Temporary Placeholder
        pingSerial();

        // Display pH Header Text
        ReefAngel.LCD.DrawText(COLOR_INDIGO,255,105,15,"pH");
  
        // Display pH Value
        ConvertNumToString(text, ReefAngel.Params.PH, 100);
        ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 94, 26, text, Font8x16);
        pingSerial();
        
        //Display Alternate Temp Parameters
        ReefAngel.LCD.DrawText(0,255,8,45,"Sump");
        ReefAngel.LCD.Clear(255,36,45,57,52);
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], COLOR_CORNFLOWERBLUE, 36, 45, 10);

        ReefAngel.LCD.DrawText(0,255,72,45,"Hood");
        ReefAngel.LCD.Clear(255,100,45,119,52);
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], COLOR_CORNFLOWERBLUE, 100, 45, 10);

        // Display Vortech MP10wES Mode Header Text
        ReefAngel.LCD.Clear(DefaultFGColor,3,56,126,56);
        ReefAngel.LCD.DrawText(0,255,18,60,"Vortech EcoSmart");
        pingSerial();

        // Display EcoSmart Mode Value & Speed %     
        ReefAngel.LCD.Clear(255,1,71,128,78);
        vtechspeed = InternalMemory.RFSpeed_read();
        vtechpercent = vtechspeed * 0.39215;  
        ConvertNumToString(text, vtechpercent, 1);
        if (vtechmode == 0)
        {
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,16,71,"Constant-");
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,89,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,106,71,"%");
        }
        else if(vtechmode == 1) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,20,71,"Lagoon-");
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,85,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,102,71,"%");
        }
        else if (vtechmode == 2) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,8,71,"Reef Crest-");
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,97,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,114,71,"%");
        }
        else if (vtechmode == 3) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,4,71,"Short Pulse-");
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,101,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,118,71,"%");
        }
        else if (vtechmode == 4) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,8,71,"Long Pulse-");
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,97,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,114,71,"%");
        }
        else if (vtechmode == 5) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,71,"Nutrient TM-");
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,71,"%");
        }
        else if (vtechmode == 6) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,71,"Tidal Swell-");
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,71,"%");
        }
        else if (vtechmode == 9) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,28,71,"Night-");
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,77,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,94,71,"%");
        }

        // Display PMW Expansion Channel Headers and % Values
        ReefAngel.LCD.Clear(DefaultFGColor,3,82,126,82);
        
        ReefAngel.LCD.DrawText(0,255,27,85,"Daylight:");
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetDaylightValue(), COLOR_CORNFLOWERBLUE, 81, 85, 1);
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,100,85,"%");

        ReefAngel.LCD.DrawText(0,255,27,94,"Actinic:");
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(), COLOR_CORNFLOWERBLUE, 81, 94, 1);
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,100,94,"%");

        pingSerial();
        
        // Display Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox(13, 104, TempRelay);
        pingSerial();

        //Draw Date & Time
        
        ReefAngel.LCD.Clear(DefaultFGColor,3,118,126,118);
        ReefAngel.LCD.DrawDate(6, 120);
        pingSerial();
}

void DrawCustomGraph()  // Not Used
{
}
//------------------------------------------------------ End Custom Main ----------------------------------------------------------
//*********************************************************************************************************************************
//-------------------------------------------------------- Begin Setup ------------------------------------------------------------
void setup()
{
    ReefAngel.Init();  //Initialize controller

    ReefAngel.FeedingModePorts = Port2Bit | Port4Bit; // Turn off Port2 and Port4 when feeding mode is activated
    ReefAngel.WaterChangePorts = Port2Bit | Port4Bit | Port5Bit; // Turn off Port2, Port4 and Port5 when water change mode is actived
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port7Bit;
    ReefAngel.LightsOnPorts = Port7Bit;

    // Ports that are always on
    ReefAngel.Relay.On(Port1);
    ReefAngel.Relay.On(Port2);
    ReefAngel.Relay.On(Port3);
    ReefAngel.Relay.On(Port6);
 
    // RF Module Start
    ReefAngel.RF.SetMode(Slave_Start,0,0);
    ReefAngel.RF.UseMemory=true;  
}
//---------------------------------------------------------- End Setup ------------------------------------------------------------
//*********************************************************************************************************************************
//--------------------------------------------------------- Begin Loop ------------------------------------------------------------
void loop()
{
    // Specific functions
    ReefAngel.Refresh();  //WDT check
    ReefAngel.Relay.DelayedOn(Port4, 1); // Turn on Port 4 (Skimmer) with 1 minute delay
    ReefAngel.Relay.DelayedOn(Port5, 2); // Turn on Port 5 (Tunze ATO) with 2 minute delay
    ReefAngel.StandardLights(Port8); //Fuge Moonlight on when main lights are on
    ReefAngel.StandardLights(Port7,20,30,8,30); //Fuge Light on at night
    ReefAngel.StandardHeater(Port3); // Standard Heater Using Internal Memory
    ReefAngel.Portal("mvwise");
    
    // LED FunctionsPWMSlope based on Internal Memory values for Standard Lights
    ReefAngel.PWM.ActinicPWMSlope(15); //Set Blue LED to Internal Memory Values with 15 minute offset from Daylight
    ReefAngel.PWM.DaylightPWMSlope(); //Set White LED to Internal Memory Values
    if (ReefAngel.Relay.Status(Port8))
      ReefAngel.PWM.SetChannel(0,MoonPhase()); // Set Moonlights to MoonPhase during night hours  
    else
      ReefAngel.PWM.SetChannel(0,0);
 
    // Fan Speed Functions
    byte HoodFanSpeed;
    HoodFanSpeed=map(ReefAngel.Params.Temp[3],780,790,30,100); // Calculate Hood Fan speed
    HoodFanSpeed=constrain(HoodFanSpeed,0,100);
    ReefAngel.PWM.SetChannel(2,HoodFanSpeed);

    byte BlowerFanSpeed;
    BlowerFanSpeed=map(ReefAngel.Params.Temp[1],780,790,30,100); // Calculate Blower Fan speed
    BlowerFanSpeed=constrain(BlowerFanSpeed,0,100);
    ReefAngel.PWM.SetChannel(3,BlowerFanSpeed);
    
/*
------------------------------------------------ Start Time-of-Day Based Functions ----------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These are the mode numbers for the RF Expansion Module for reference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #define Constant      0
    #define Random1       1 // Lagoonal
    #define Random2       2 // Reef Crest
    #define ShortWave     3
    #define LongWave      4
    #define Smart_NTM     5 // Nutrient Transport Mode
    #define Smart_TSM     6 // Tidal Swell Mode
    #define Feeding_Start 7
    #define Feeding_Stop  8
    #define Night         9
    #define Slave_Start   97
    #define Slave_Stop    98
    #define None          99
    
    RF Mode
    http://YOURIPADDRESS:2000/mb855,X

    RF Speed
    http://YOURIPADDRESS:2000/mb856,X

    RF Duration
    http://YOURIPADDRESS:2000/mb857,X
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

//-------------------------------------------------------- Start RF Smart Nutrient Mode After Feeding ---------------------------
  if (hour() >=8 && hour() <= 21)
  {  
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding)
    {
      bFeeding=false; 
      ReefAngel.Timer[4].SetInterval(900); // Timer for 15min
      ReefAngel.Timer[4].Start();
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,170,6);
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[4].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }  
  }
  
//---------------------------------------------------------- End RF Smart Nutrient Mode After Feeding -----------------------------   

//-------------------------------------------------------- Start RF Nightmode Control ---------------------------------------------    

  if (hour()>20 || hour()<8) // Defining "Nightmode" hours for VorTech = between 9 PM and 8 AM
    {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
    }
  else
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    } 
//---------------------------------------------------------- End RF Nightmode Control ---------------------------------------------

    ReefAngel.ShowInterface();

}

//--------------------------------------------------------------- End Loop --------------------------------------------------------
//*********************************************************************************************************************************
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

Your if statement was messing up the override of mode.
I changed your code a little bit. Removed unneeded code and moved Portal to end of code.
Try this:

Code: Select all

// Autogenerated file by RAGen (v1.2.1.158), (03/08/2012 22:54)
// RA_030812_2254.ino
//
// This version designed for v0.9.0 or later
//
// Sketch borrowed from TanksNStuff

/* 
The following features are enabled for this File: 
#define DisplayImages
#define OverheatSetup
#define DateTimeSetup
#define VersionMenu
#define DirectTempSensor
#define DisplayLEDPWM
#define wifi
#define SaveRelayState
#define WDT
#define PWMEXPANSION
#define CUSTOM_MAIN
#define COLORS_PDE
#define SALINITYEXPANSION
#define RFEXPANSION
#define FONT_8x8
#define FONT_8x16

Ports assignment:
Port1 - Return Pump
Port2 - Circulation Pumps
Port3 - Heater
Port4 - Skimmer 
Port5 - Tunze ATO
Port6 - PWM Expansion Power Supply
Port7 - Fuge Light
Port8 - Fuge Moonlight
*/

#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 <Salinity>
#include <Memory.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <ReefAngel.h>

//*********************************************************************************************************************************
//--------------------------------------------------- Start of Global Variables ---------------------------------------------------

// Globals Needed for Params on Custom Main
byte x,y;
char text[10];
int v;

// Globals Needed for RF Mode on Custom Main
byte vtechmode;
byte vtechspeed;
byte vtechpercent;
boolean bFeeding=false;

//------------------------------------------------------ End of Global Variables --------------------------------------------------
//*********************************************************************************************************************************
//---------------------------------------------Custom Main for PWM Expansion Module------------------------------------------------

void DrawCustomMain()
{
        //Top Banner
        ReefAngel.LCD.DrawLargeText(COLOR_BLACK, 255, 9, 2, "WISEGUYS' REEF"); 
        ReefAngel.LCD.Clear(DefaultFGColor,3,11,126,11);
        
        //Clear Screen for Refresh
        //ReefAngel.LCD.Clear(255,1,12,128,128);
        
        // Display T1 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,10,15,"Tank");
        char text[7];
  
        // Display the T1 Temp Value
        ReefAngel.LCD.Clear(255,4,26,125,41);
        ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 4, 26, text, Font8x16);
        pingSerial();

        // Display the Salinity Header Text
        ReefAngel.LCD.DrawText(COLOR_CRIMSON,255,55,15,"Sal.");
  
        // Display the Salinity Value
        // ConvertNumToString(text, ReefAngel.Params.Salinity, 100);
        // ReefAngel.LCD.DrawLargeText(COLOR_CRIMSON, 255, 57, 26, text, Num8x16);
        ReefAngel.LCD.DrawLargeText(COLOR_CRIMSON, 255, 57, 26, "35", Font8x16); // Temporary Placeholder
        pingSerial();

        // Display pH Header Text
        ReefAngel.LCD.DrawText(COLOR_INDIGO,255,105,15,"pH");
  
        // Display pH Value
        ConvertNumToString(text, ReefAngel.Params.PH, 100);
        ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 94, 26, text, Font8x16);
        pingSerial();
        
        //Display Alternate Temp Parameters
        ReefAngel.LCD.DrawText(0,255,8,45,"Sump");
        ReefAngel.LCD.Clear(255,36,45,57,52);
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], COLOR_CORNFLOWERBLUE, 36, 45, 10);

        ReefAngel.LCD.DrawText(0,255,72,45,"Hood");
        ReefAngel.LCD.Clear(255,100,45,119,52);
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], COLOR_CORNFLOWERBLUE, 100, 45, 10);

        // Display Vortech MP10wES Mode Header Text
        ReefAngel.LCD.Clear(DefaultFGColor,3,56,126,56);
        ReefAngel.LCD.DrawText(0,255,18,60,"Vortech EcoSmart");
        pingSerial();

        // Display EcoSmart Mode Value & Speed %     
        ReefAngel.LCD.Clear(255,1,71,128,78);
        vtechspeed = InternalMemory.RFSpeed_read();
        vtechpercent = vtechspeed * 0.39215;  
        ConvertNumToString(text, vtechpercent, 1);
        if (vtechmode == 0)
        {
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,16,71,"Constant-");
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,89,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,106,71,"%");
          pingSerial();
        }
        else if(vtechmode == 1) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,20,71,"Lagoon-");
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,85,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,102,71,"%");
          pingSerial();
        }
        else if (vtechmode == 2) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,8,71,"Reef Crest-");
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,97,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,114,71,"%");
          pingSerial();
        }
        else if (vtechmode == 3) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,4,71,"Short Pulse-");
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,101,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,118,71,"%");
          pingSerial();
        }
        else if (vtechmode == 4) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,8,71,"Long Pulse-");
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,97,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,114,71,"%");
          pingSerial();
        }
        else if (vtechmode == 5) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,71,"Nutrient TM-");
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,71,"%");
          pingSerial();
        }
        else if (vtechmode == 6) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,71,"Tidal Swell-");
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,71,"%");
          pingSerial();
        }
        else if (vtechmode == 9) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,28,71,"Night-");
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,77,71,text);
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,94,71,"%");
          pingSerial();
        }

        // Display PMW Expansion Channel Headers and % Values
        ReefAngel.LCD.Clear(DefaultFGColor,3,82,126,82);
        
        ReefAngel.LCD.DrawText(0,255,27,85,"Daylight:");
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetDaylightValue(), COLOR_CORNFLOWERBLUE, 81, 85, 1);
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,100,85,"%");
        pingSerial();

        ReefAngel.LCD.DrawText(0,255,27,94,"Actinic:");
        ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(), COLOR_CORNFLOWERBLUE, 81, 94, 1);
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,100,94,"%");

        pingSerial();
        
        // Display Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox(13, 104, TempRelay);
        pingSerial();

        //Draw Date & Time
        
        ReefAngel.LCD.Clear(DefaultFGColor,3,118,126,118);
        ReefAngel.LCD.DrawDate(6, 120);
        pingSerial();
}

void DrawCustomGraph()  // Not Used
{
}
//------------------------------------------------------ End Custom Main ----------------------------------------------------------
//*********************************************************************************************************************************
//-------------------------------------------------------- Begin Setup ------------------------------------------------------------
void setup()
{
    ReefAngel.Init();  //Initialize controller

    ReefAngel.FeedingModePorts = Port2Bit | Port4Bit; // Turn off Port2 and Port4 when feeding mode is activated
    ReefAngel.WaterChangePorts = Port2Bit | Port4Bit | Port5Bit; // Turn off Port2, Port4 and Port5 when water change mode is actived
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port7Bit;
    ReefAngel.LightsOnPorts = Port7Bit;

    // Ports that are always on
    ReefAngel.Relay.On(Port1);
    ReefAngel.Relay.On(Port2);
    ReefAngel.Relay.On(Port3);
    ReefAngel.Relay.On(Port6);
}
//---------------------------------------------------------- End Setup ------------------------------------------------------------
//*********************************************************************************************************************************
//--------------------------------------------------------- Begin Loop ------------------------------------------------------------
void loop()
{
    // Specific functions
    ReefAngel.Relay.DelayedOn(Port4, 1); // Turn on Port 4 (Skimmer) with 1 minute delay
    ReefAngel.Relay.DelayedOn(Port5, 2); // Turn on Port 5 (Tunze ATO) with 2 minute delay
    ReefAngel.StandardLights(Port8); //Fuge Moonlight on when main lights are on
    ReefAngel.StandardLights(Port7,20,30,8,30); //Fuge Light on at night
    ReefAngel.StandardHeater(Port3); // Standard Heater Using Internal Memory
    
    // LED FunctionsPWMSlope based on Internal Memory values for Standard Lights
    ReefAngel.PWM.ActinicPWMSlope(15); //Set Blue LED to Internal Memory Values with 15 minute offset from Daylight
    ReefAngel.PWM.DaylightPWMSlope(); //Set White LED to Internal Memory Values
    if (ReefAngel.Relay.Status(Port8))
      ReefAngel.PWM.SetChannel(0,MoonPhase()); // Set Moonlights to MoonPhase during night hours  
    else
      ReefAngel.PWM.SetChannel(0,0);
 
    // Fan Speed Functions
    byte HoodFanSpeed;
    HoodFanSpeed=map(ReefAngel.Params.Temp[3],780,790,30,100); // Calculate Hood Fan speed
    HoodFanSpeed=constrain(HoodFanSpeed,0,100);
    ReefAngel.PWM.SetChannel(2,HoodFanSpeed);

    byte BlowerFanSpeed;
    BlowerFanSpeed=map(ReefAngel.Params.Temp[1],780,790,30,100); // Calculate Blower Fan speed
    BlowerFanSpeed=constrain(BlowerFanSpeed,0,100);
    ReefAngel.PWM.SetChannel(3,BlowerFanSpeed);
    
/*
------------------------------------------------ Start Time-of-Day Based Functions ----------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These are the mode numbers for the RF Expansion Module for reference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #define Constant      0
    #define Random1       1 // Lagoonal
    #define Random2       2 // Reef Crest
    #define ShortWave     3
    #define LongWave      4
    #define Smart_NTM     5 // Nutrient Transport Mode
    #define Smart_TSM     6 // Tidal Swell Mode
    #define Feeding_Start 7
    #define Feeding_Stop  8
    #define Night         9
    #define Slave_Start   97
    #define Slave_Stop    98
    #define None          99
    
    RF Mode
    http://YOURIPADDRESS:2000/mb855,X

    RF Speed
    http://YOURIPADDRESS:2000/mb856,X

    RF Duration
    http://YOURIPADDRESS:2000/mb857,X
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

//-------------------------------------------------------- Start RF Smart Nutrient Mode After Feeding ---------------------------
  if (hour() >=8 && hour() <= 21)
  {  
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding)
    {
      bFeeding=false; 
      ReefAngel.Timer[1].SetInterval(5); // Timer for 15min
      ReefAngel.Timer[1].Start();
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,170,6);
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[1].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }
  }
  else
  {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
  }
  
//---------------------------------------------------------- End RF Smart Nutrient Mode After Feeding -----------------------------   

    ReefAngel.Portal("mvwise");

    ReefAngel.ShowInterface();

}

//--------------------------------------------------------------- End Loop --------------------------------------------------------
//*********************************************************************************************************************************
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

Roberto, thanks!

However I uploaded your revisions this morning and still no go. Bear in mind that I have the RF module running but not yet synced with my MP10. I am just in testing mode to make sure everything is working well. However, after feeding mode ends, the Vortech Mode on the display does not change from Reef Crest to NTM as desired. I'm not sure what the internal memory setting is and how to check that to see if it is just a graphical issue.

Is there any way to check the RF mode from any of the remote apps?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

That's ok. You don't need it synced.
The light indication on the RF module itself uses the same color scheme.
ReefCrest is a yelowish color and the NTM is a pinkish color.
Did the display on the screen change?
I was actually testing, so I decreased the time and forgot to return back.
The NTM mode is only running for 5 seconds.
Please change this line:

Code: Select all

      ReefAngel.Timer[1].SetInterval(5); // Timer for 15min
I can see on the screen that it changes modes.
I haven't hooked up an RF module, but I see no reason why it wouldn't work.
Can you try again with this short time in mind?
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

Perfect, thanks! I guess I wasn't seeing the change since it was only for 5 seconds.

Quick question relating to PWN module. I am waiting for delivery of the expansion module and moonlight kits. I have three PWM capable fans for the hood and tank. Can the fans be connected to the PWN expansion so that they are powered by the PWN power supply or should I power them separately? If they can, do I wire at the PWN expansion block or splice into the power supply before the block?

Thanks again!
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

Are the fans 12VDC?
If so, yes you can and should be fine using the terminal block :)
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

Okay most of it seems to be working. The only issue I am having is with the fan speed calculation. The only place I can see the fan speed is on the Portal and it is showing values of greater than 100% in some instances. Since I have not set up the RA on my tank and am only running in test mode, my temps are all in the low 70's, which are lower than the map settings. As I understand it the lowest setting for temperatures under those thresholds would be 30%, so all fans should be operating at 30% of their capacity all of the time.

I am alos interested in using the parabola for the lights. In another post this format is mentioned:
Use this, instead of the PWMSlope() function, I use PWMParabola()

CODE: SELECT ALL
CODE: SELECT ALL
PWMParabola(9,0,21,0,15,75,0);


Parabola starts at 9:00am, ends at 9:00pm.
Instensity grows from 15 to 75 and back down to 15.
Returns 0 when not within the time schedule.

The 0 at the end of the function forces the Driver to switch off.
I have changed the functions in my sketch to the following:
ReefAngel.PWM.ActinicPWMParabola(); //Set Blue LED to Internal Memory Values
ReefAngel.PWM.DaylightPWMParabola(); //Set White LED to Internal Memory Values
if (ReefAngel.Relay.Status(Port7))
ReefAngel.PWM.SetChannel(0,MoonPhase()); // Set Moonlights to MoonPhase during night hours
else
ReefAngel.PWM.SetChannel(0,0);
However, when this runs I start and end with my internal memory settings of 35% and 40% respectively. Is there a way to code in the final 0 at the end of the function to shut the lights off at night time while still using the internal memory settings? Also, how would you code the parabola function into the moonlights?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

Very strange it go above 100% on your fan speed.

Code: Select all

BlowerFanSpeed=constrain(BlowerFanSpeed,0,100);
This forces the value to be constrained between 0 and 100 no matter what the map function plots.
Can you temporarily draw the fan speed on your screen to confirm?
Now to the Parabola.
If you want it to be 0 at night, you will need to force a 0% when lights are off.
Place this after your Parabola:

Code: Select all

if (hour()>=21 || hour() <9)
{
  ReefAngel.PWM.SetActinic(0);
  ReefAngel.PWM.SetDaylight(0);
}
This will force 0% between 9pm and 9am

I don't know if it would work for moonlights though. I think it would break when it goes past midnight into a new day.
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Code Almost there but problems

Post by mvwise »

Okay I'll give it a try later when home. What would the code look like to pull the fan speed data from the expansion PWM?

You can see the existing speeds on my portal page, but can easily add the temporary code to my display to get real time feedback.


---
I am here: http://tapatalk.com/map.php?31edky
Sent from my Matthew's iPhone using Tapatalk
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

I see that it did it in the past and seems to have gone away.
http://forum.reefangel.com/status/chart ... lter=pwme3
Keep an eye and let me know if it still goes above 100.
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

You can use something like this to get the value:

Code: Select all

  ReefAngel.LCD.DrawText(0,255,10,10,ReefAngel.PWM.GetChannelValue(2));
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

The values seem to behave the way I would like as long as they are within my temperature range in this code:

Code: Select all

// Fan Speed Functions
    byte HoodFanSpeed;
    HoodFanSpeed=map(ReefAngel.Params.Temp[3],750,850,25,100); // Calculate Hood Fan speed
    HoodFanSpeed=constrain(HoodFanSpeed,0,100);
    ReefAngel.PWM.SetChannel(1,HoodFanSpeed);

    byte BlowerFanSpeed;
    BlowerFanSpeed=map(ReefAngel.Params.Temp[1],750,800,25,100); // Calculate Blower Fan speed
    BlowerFanSpeed=constrain(BlowerFanSpeed,0,100);
    ReefAngel.PWM.SetChannel(2,BlowerFanSpeed);
So as long as the temps are within the range of 75 to 85 (or 75 to 80 for Channel 2) they are reporting the correct, raw, numbers on my display. If divided by 2.55 I get the correct percentages. However, when the temperatures drop out of this range they seem to hit 100% regardless of which side they fall on.

I would think that given the making and the constraints, that if the temperature fell on the low side it would be set at the minimum of 25% or somewhere between 0% and 25%. I'm not sure what the resolution would be, but perhaps it needs a little more logic?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

Ah...
You need to change the variable type if you are going way off your temperature range.
Byte variable can't be negative and can't be more than 255 before the constrain calculation.
By bumping the variable to signed int, you can go negative and above 255.

Code: Select all

signed int HoodFanSpeed;
singed int BlowerFanSpeed;
Here is what my log shows:
T1=690, %=0
T1=703, %=0
T1=726, %=7
T1=755, %=28
T1=780, %=47
T1=802, %=64
T1=818, %=76
T1=833, %=87
T1=843, %=94
T1=852, %=100
T1=861, %=100
T1=869, %=100
T1=874, %=100
T1=879, %=100
T1=883, %=100
T1=888, %=100
T1=892, %=100
T1=896, %=100
T1=899, %=100
T1=903, %=100
T1=906, %=100
T1=910, %=100
T1=912, %=100
T1=914, %=100
T1=917, %=100
T1=919, %=100
T1=923, %=100
T1=923, %=100
T1=924, %=100
T1=928, %=100
T1=930, %=100
T1=933, %=100
T1=937, %=100
T1=941, %=100
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

That did it! Thank you for your help!
Image
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Code Almost there but problems

Post by mvwise »

Can you explain what the value obtained by MoonPhase() is? Does it represent the % of the moon on the given day or some other value?


---
I am here: http://tapatalk.com/map.php?23idjl
Sent from my Matthew's iPhone using Tapatalk
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

Correct. % of the moon for a particular day.
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

Roberto, Sorry, I've been tied up with work and haven't been on top of my RA for a week or so.

I've been monitoring the performance of the coding to date, but for some reason when I modified the feeding / NTM code you provided earlier:

Code: Select all

//-------------------------------------------------------- Start RF Smart Nutrient Mode After Feeding ---------------------------
  if (hour() >=8 && hour() <= 21)
  {  
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding)
    {
      bFeeding=false; 
      ReefAngel.Timer[1].SetInterval(5); // Timer for 15min
      ReefAngel.Timer[1].Start();
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,170,6);
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[1].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }
  }
  else
  {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
  }
  
//---------------------------------------------------------- End RF Smart Nutrient Mode After Feeding ----------------------------- 
everything works fine until night. It then goes into night mode and never comes out. The only way for me to bring it out of night mode is to enter feeding mode, which then causes the other relation to work, but once in night mode ReefAngel.RF.UseMemory is set to false and night mode is switched on, but then there is nowhere in your code that forces ReefAngel.RF.UseMemory back to true during the daytime (unless feed mode is triggered).

I think it has something to do with the line:

Code: Select all

if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[1].IsTriggered())
I'm not sure how the IsTriggered() command works and if that is true whenever the timer is not running or if there is another statement that can be used. I presume that essentially we want this statement to be true when the default menu is displayed and when Timer[1] is not running?

Any thoughts?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

You are correct.
I forgot to account for that one.
I think this should work:

Code: Select all

//-------------------------------------------------------- Start RF Smart Nutrient Mode After Feeding ---------------------------
  if (hour() >=8 && hour() <= 21)
  {
    if (vtechmode == 9)
    {
      ReefAngel.RF.UseMemory=true;  
      vtechmode = InternalMemory.RFMode_read();
    }
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding)
    {
      bFeeding=false; 
      ReefAngel.Timer[1].SetInterval(5); // Timer for 15min
      ReefAngel.Timer[1].Start();
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,170,6);
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[1].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }
  }
  else
  {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
  }
  
//---------------------------------------------------------- End RF Smart Nutrient Mode After Feeding ----------------------------- 
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

Roberto, I'm still in test mode (slow progress due to work schedule), but getting closer to the final setup that I'd like to be using. I have hooked up the PWN expansion to the controller and using my code to control fan speed I'm getting low voltage reports from the PWN module on a voltmeter. However I'm failing to be able to get the fans up and working.

I have PWM fans with four leads - red (+12v), black (Ground), blue (PWM), yellow (speed sensor). I have the 2nd generation PWM. What is the best way to wire up the fan to the PWM? Do I need a separate power supply for the fan to run. I might be missing something very easy here, but connecting the + and - to the terminal ends of a 9v battery causes the fan to run. If I connect the pam to the - on the battery as well, the speed is reduced to what I would imagine is a 9v speed, however connecting the same leads to the PWM block I get nothing, even though there appears to be voltage running between the connectors.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

If you look closely, the 2nd generation pinout is different and doesn't have a +12VDC for you to connect the red wire.
I would advise not to use the same power supply anyway.
You should use an external power supply to energize your fans and then use the black and blue to conenct to the dimming module.
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Code Almost there but problems

Post by mvwise »

Okay, no problem. So the external power supply +'ve connects to the red on the fan, what would the -'ve on the power supply connect to?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Code Almost there but problems

Post by rimai »

It need to connect to both black on fan and GND on dimming module, so they all have the same GND reference.
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Code Almost there but problems

Post by mvwise »

Cool, thanks!


Sent from my Matthew's iPhone using Tapatalk
Image
Post Reply