Page 1 of 1

Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 4:48 am
by sabo
I finally have things mostly set up. My long probe which is the one that goes into the sump and is the overheat probe, seems to be T2. So I changed my code to suit, but when I hold it so it heats up over the threshold, instead of the two appropriate heater relays going off, the first 4 on the second box goes off. I thought it may had been something to do with my defines, but even setting the actual box ports it still does it. Quite odd. I can turn those relays off with the app and everything else seems normal. Heres the 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 <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>

////// 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 Unused      Box1_Port6
#define Swabby      Box1_Port7
#define Unused      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.Use2014Screen();  // Let's use 2014 Screen 
    ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
    ReefAngel.AddPHExpansion();  // pH Expansion Module
    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 = 0;
    ReefAngel.OverheatShutoffPortsE[0] = Box1_Port3 | Box1_Port5;
    // Use T1 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( Fuge_Led );
    ReefAngel.Relay.On( Heater1 );
    ReefAngel.Relay.On( Heater2 );
    ReefAngel.Relay.On( Skimmer );

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

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

void loop()
{
    ReefAngel.WaterLevelATO( ATO,180,70,90 );
    if (ReefAngel.LowATO.IsActive() && ReefAngel.HighATO.IsActive())
      {
        ReefAngel.Relay.On(Skimmer);
      }
     else
      {
        ReefAngel.Relay.Off(Skimmer);
      } 
    ReefAngel.DosingPumpRepeat( Swabby,0,360,120 );

    ////// Place your custom code below here
    
    if (hour()>=6 && hour()<12)
{
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 60% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,true) ); // ReefCrest at 60% +/- 20% on anti-sync mode
  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(70,20,true) ); // ReefCrest at 60% +/- 20% on sync mode
  ReefAngel.PWM.SetChannel( 1, ReefCrestMode(70,20,true) ); // ReefCrest at 60% +/- 20% on anti-sync mode
  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(50,20,true) ); // ReefCrest at 60% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(50,20,true) ); // ReefCrest at 60% +/- 20% on anti-sync mode
  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(50,20,true) ); // ReefCrest at 60% +/- 20% on sync mode
  ReefAngel.PWM.SetChannel( 1, ReefCrestMode(50,20,true) ); // ReefCrest at 60% +/- 20% on anti-sync mode
  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" );
    ReefAngel.ShowInterface();
}


Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 5:39 am
by lnevo

Code: Select all

ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port5Bit;
This is bit math not straight definitions so you need to use Port3Bit and Port5Bit to reference those ports. And the E[0] part references Box1.

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 6:07 am
by sabo
Great, that sorted it. Is there some docs that explain this a bit? Or could you give me a quick run down on this? I did see someones ino that was doing bit shifting in his defines and it made me wonder why he had done it like that. Is making my defines like I have done going to catch me out in other instances? Thanks very much for your help.

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 7:40 am
by sabo
Also, is my swabby code right? Its hard to tell as I keep reuploding my controller so I guess the 6 hours keeps getting reset. But I want it on for two minutes every six hours.

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 8:21 am
by rimai
Looks good.

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 8:27 am
by sabo
Cool. will keep an eye on it for the next day to see if it works.

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 9:38 am
by lnevo
I'll give a better explanation of how it works when I have a bit more time. You should be fine though with the rest. I might start a new thread though because I think it would be useful for a lot of people.

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 9:48 am
by sabo
That would be great. There seems to be a few gotchas and documenting them would be good for newbies. A wiki is really needed IMO.

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 9:50 am
by rimai
Do you want to help and contribute? :)
https://github.com/reefangel/Libraries/wiki

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 11:37 am
by lnevo
Didn't we make one on the forum?

Re: Oveheat turning off wrong ports

Posted: Sun Apr 06, 2014 9:04 pm
by sabo
Yep. I'll try and add a bit to it.