Sanity check please

Do you have a question on how to do something.
Ask in here.
Post Reply
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Sanity check please

Post by sabo »

I've added some code for my chiller that I am about to set up, however it appears I have it around the wrong way, though it looks correct to me. What I want is the chiller pump to run at idle when the temp is less than 26.6c and when above to go to full power. The power settings are read from internal memory. My tank temp is less than 26.6, yet the pwm value is set to the value it should be if the temp was above that. I'll include the my whole ino.

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

// Define Custome Memory Locations

#define Mem_B_SkimmerWL      100
#define Mem_B_PHDayPower     101
#define Mem_B_PHNightPower   102
#define Mem_B_PHDuration     103
#define Mem_I_ChillerPumpT   104
#define Mem_B_CPumpMax       106
#define Mem_B_CPumpMin       107

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

#define Return       1
#define Pwm_Exp      2
#define Unused       3
#define ATI          4
#define Jebao1_Rhs   5
#define Jebao2_Rhs   6
#define Jebao1_Lhs   7
#define Jebao2_Lhs   8

#define ATO         Box1_Port1
#define Fuge_Led    Box1_Port2
#define Heater1     Box1_Port3
#define Skimmer     Box1_Port4
#define Heater2     Box1_Port5
#define Kamoar      Box1_Port6
#define Swabby      Box1_Port7
#define CPump       Box1_Port8

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


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.SetTemperatureUnit( Celsius );  // set to Celsius Temperature
    
    ReefAngel.AddStandardMenu();  // Add Standard Menu

    ReefAngel.Use2014Screen();  // Let's use 2014 Screen
    ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = 0;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    ReefAngel.WaterChangePortsE[0] = 0;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port4Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port5Bit;
    // Use T2 probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T2_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 280 );


    // Ports that are always on
    ReefAngel.Relay.On( Pwm_Exp );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( ATI );
    ReefAngel.Relay.On( Kamoar );
    ReefAngel.Relay.On( CPump );

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

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

void loop()
{
    ReefAngel.DayLights( Fuge_Led );
    ReefAngel.Relay.DelayedOn( Skimmer );
    ReefAngel.StandardHeater( Heater1 );
    ReefAngel.StandardHeater( Heater2 ); 
    ReefAngel.WaterLevelATO( ATO );
    

    ////// Place your custom code below here
    
    CheckPower();
    
    if (ReefAngel.WaterLevel.GetLevel() < InternalMemory.read(Mem_B_SkimmerWL) ) ReefAngel.Relay.Override(Skimmer, 0);
    
    if (ReefAngel.LowATO.IsActive() && ReefAngel.HighATO.IsActive())
      {
        ReefAngel.Relay.Override(Skimmer,2);
      }
     else
      {
        ReefAngel.Relay.Override(Skimmer,0);
      }
      
    ReefAngel.DosingPumpRepeat1(Swabby);
    
    if (ReefAngel.Params.Temp[T2_PROBE] < InternalMemory.read(Mem_I_ChillerPumpT))  //if temp less that set temp, chiller
      {                                                                             //pump to idle, otherwise set power
         ReefAngel.PWM.SetChannel(5, InternalMemory.read(Mem_B_CPumpMin) );
      }
    else
      {
         ReefAngel.PWM.SetChannel(5, InternalMemory.read(Mem_B_CPumpMax) );
      }
         
    if (hour()>=6 && hour()<12)
      {
         ReefAngel.PWM.SetDaylight( ReefCrestMode(InternalMemory.read(Mem_B_PHDayPower),InternalMemory.read(Mem_B_PHDuration),true) );
         ReefAngel.PWM.SetActinic( ReefCrestMode(InternalMemory.read(Mem_B_PHDayPower),InternalMemory.read(Mem_B_PHDuration),true) );
         ReefAngel.Relay.Off( Jebao1_Lhs );
         ReefAngel.Relay.Off( Jebao2_Lhs );
         ReefAngel.Relay.On( Jebao1_Rhs );
         ReefAngel.Relay.On( Jebao2_Rhs );
      }
    else if (hour()>=12 && hour()<18)
      {
        ReefAngel.PWM.SetChannel( 0, ReefCrestMode(InternalMemory.read(Mem_B_PHDayPower),InternalMemory.read(Mem_B_PHDuration),true) );
        ReefAngel.PWM.SetChannel( 1, ReefCrestMode(InternalMemory.read(Mem_B_PHDayPower),InternalMemory.read(Mem_B_PHDuration),true) );
        ReefAngel.Relay.Off( Jebao1_Rhs );
        ReefAngel.Relay.Off( Jebao2_Rhs );
        ReefAngel.Relay.On( Jebao1_Lhs );
        ReefAngel.Relay.On( Jebao2_Lhs );
      }
    else if (hour()>=18 && hour()<24)
      {
        ReefAngel.PWM.SetDaylight( ReefCrestMode(InternalMemory.read(Mem_B_PHNightPower),InternalMemory.read(Mem_B_PHDuration),true) );
        ReefAngel.PWM.SetActinic( ReefCrestMode(InternalMemory.read(Mem_B_PHNightPower),InternalMemory.read(Mem_B_PHDuration),true) );
        ReefAngel.Relay.Off( Jebao1_Lhs );
        ReefAngel.Relay.Off( Jebao2_Lhs );
        ReefAngel.Relay.On( Jebao1_Rhs );
        ReefAngel.Relay.On( Jebao2_Rhs );
      }
    else
      {
        ReefAngel.PWM.SetChannel( 0, ReefCrestMode(InternalMemory.read(Mem_B_PHNightPower),InternalMemory.read(Mem_B_PHDuration),true) );
        ReefAngel.PWM.SetChannel( 1, ReefCrestMode(InternalMemory.read(Mem_B_PHNightPower),InternalMemory.read(Mem_B_PHDuration),true) );
        ReefAngel.Relay.Off( Jebao1_Rhs );
        ReefAngel.Relay.Off( Jebao2_Rhs );
        ReefAngel.Relay.On( Jebao1_Lhs );
        ReefAngel.Relay.On( Jebao2_Lhs );
      }


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

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

void CheckPower() {
  static boolean powerOutage=false;
  static WiFiAlert powerAlert;

  // Power Outage - turn off everything
  if (!ReefAngel.Relay.IsRelayPresent(EXP1_RELAY)) // Expansion Relay NOT present
  {
    powerOutage=true;
    ReefAngel.Relay.Off(ATI);
    powerAlert.Send("Power+outage!");
  }

  // Power Restored - Turn things back on
  if (powerOutage && ReefAngel.Relay.IsRelayPresent(EXP1_RELAY))
  {
    LastStart=now();
    powerOutage=false;
    ReefAngel.Relay.On(ATI);
    powerAlert.Send("Power+restored.",true);
  }
}
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Sanity check please

Post by cosmith71 »

Make sure you've set your internal memory value to 266 and not 26.6.

Also, it would be better if you added a hysteresis. Instead of turning on at >26.6 and off at <26.6, have it turn on at >26.8 so it doesn't switch on and off rapidly when it's sitting right at 26.6.

Otherwise looks fine to me.

--Colin
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Re: Sanity check please

Post by sabo »

Yep, have it set to 266. Don't understand why its set to the high power setting when it should be at the low power setting. High is set to 80, low is 30, and the channel shows 80.
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Sanity check please

Post by cosmith71 »

Just for kicks, take out your variable reads and hard code the temps. See what that does.

--Colin
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Re: Sanity check please

Post by sabo »

Good idea Will give that a go.
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Re: Sanity check please

Post by sabo »

OK, just hard coded the temp in, and it works as it should. Have I got my int set in a wrong address or something? I don't understand why it wasn't working as the android app reads the address correctly.
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Re: Sanity check please

Post by sabo »

Something else that's weird is that when I change my code, sometimes my water level expansion goes crazy. It reads extremely high, then reads zero. What could cause this when I don't touch the ato code?
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Sanity check please

Post by cosmith71 »

It looks good to me, but I'm no expert.

What is Mem_B_PHDuration set to? Any chance it could be overwriting Mem_I_ChillerPumpT?

You could also output your memory reads to serial so you can see what they actually are. Is it failing the if/then, or is it setting a wrong value?

--Colin
sabo
Posts: 129
Joined: Tue Sep 24, 2013 3:18 am

Re: Sanity check please

Post by sabo »

The duration is set to 20. The into reads properly in the android app and when its hard coded it all works as it should, so the if/else is correct. Got me scratching my head. I might try another address and see what happens.
Post Reply