Reversing the ATO code

Do you have a question on how to do something.
Ask in here.
Post Reply
alexwbush
Posts: 327
Joined: Tue Mar 22, 2011 12:45 am
Location: San Diego, CA

Re: Reversing the ATO code

Post by alexwbush »

I've been saying these switches were coded backwards for a while, but I think people thought I was that crazy old man in the village :lol:
astralmind
Posts: 98
Joined: Fri Apr 01, 2011 10:53 am

Re: Reversing the ATO code

Post by astralmind »

alexwbush wrote:I've been saying these switches were coded backwards for a while, but I think people thought I was that crazy old man in the village :lol:
make it 2 crazy old men in the village hehe :)

Having a great time learning about the code structure on this controller. I must say that the challenge is well worth the effort. I read through the Apex's 150 pages manual and found the "language" to be so restrictive and unclear at times.

Reef Angel sure rocks and the community behind it is a critical contributing factor. 8-)
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Re: Reversing the ATO code

Post by chase »

binder wrote: It sounds like you want the water level to be at the low switch with the high one as a backup. So going back to your initial request, here would be some logic for you: (This will assume both switches are wired with their wires at the top)

Code: Select all

void ATOFailSafe(byte port)
{
	// Check for the low switch
	/*
	If the Low switch is active, meaning the float is opposite the end with the two wires, 
        we are empty so we should turn on the pump.  Otherwise, we are full, so turn off the port.
	*/
	if ( ReefAngel.LowATO.IsActive() )
	{
		ReefAngel.LowATO.StartTopping();
		ReefAngel.Relay.On(port);
	}
	else
	{
		ReefAngel.LowATO.StopTopping();
		ReefAngel.Relay.Off(port);
	}

	if ( ReefAngel.LowATO.IsTopping() && ! ReefAngel.HighATO.IsActive() )
	{
		// We have a problem
		/*
		The pump is running and topping but the low switch isn't shutting off the port.
		We must shutoff the port ourself.
		*/
		ReefAngel.Relay.Off(port);
		// Trigger some sort of alert, maybe an email or text message

		/*
		We did not indicate that the port is not topping anymore, we could do that manually
		OR we could not do it and replace the switch and have the controller do it for us.
		It's completely up to the user.
		At this point, it shouldn't matter because there is a problem with the switch and that 
		needs to be addressed.
		*/

	}
}
You can just copy and paste this function into your PDE file. Then inside your loop function, you can call it like this:

Code: Select all

void loop()
{
  // other functions
  ATOFailSafe(Port1);
}
This should handle your failsafe redundancy.

NOTE: This code does not use the timeouts at all and it does not use the hour interval. You would use this function instead of using the SingleATO or StandardATO functions.

Edited to indicate proper functionality with both wires at the top (coming out of the water) which is the reverse of how the SingleATO function works. SingleATO was based off of the high switch mounting/positioning from the StandardATO function.


curt
Trying to get this working but I'm getting the following error when compiling:
(#define Refugium 8 is highlighted yellow)
default_ragen_pde_all_ato_test:42: error: expected ',' or '...' before numeric constant
default_ragen_pde_all_ato_test:45: error: expected initializer before 'void'

Here's my PDE:

Code: Select all

// Autogenerated file by RAGen (v1.0.4.92), (09/08/2011 09:54)
// default_ragen_pde_all_ato_test.pde
//
// This version designed for v0.8.5 Beta 12 or later

/* The following features are enabled for this PDE File: 
#define DisplayImages
#define WavemakerSetup
#define DateTimeSetup
#define VersionMenu
#define DirectTempSensor
#define DisplayLEDPWM
#define StandardLightSetup
*/

#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>

#define Daylight            1
#define ATO                 2
//#define Chiller             2
#define Heater              3
#define Return              4
#define WavemakerL          5
#define WavemakerR          6
#define LED                 7
#define Refugium            8

void setup()
void ATOFailSafe(byte ATO) //changed port to ATO
{
   // Check for the low switch
   /*
   If the Low switch is active, meaning the float is opposite the end with the two wires,
        we are empty so we should turn on the pump.  Otherwise, we are full, so turn off the port.
   */
   if ( ReefAngel.LowATO.IsActive() )
   {
      ReefAngel.LowATO.StartTopping();
      ReefAngel.Relay.On(ATO);
   }
   else
   {
      ReefAngel.LowATO.StopTopping();
      ReefAngel.Relay.Off(ATO);
   }

   if ( ReefAngel.LowATO.IsTopping() && ! ReefAngel.HighATO.IsActive() )
   {
      // We have a problem
      /*
      The pump is running and topping but the low switch isn't shutting off the port.
      We must shutoff the port ourself.
      */
      ReefAngel.Relay.Off(ATO);
      // Trigger some sort of alert, maybe an email or text message

      /*
      We did not indicate that the port is not topping anymore, we could do that manually
      OR we could not do it and replace the switch and have the controller do it for us.
      It's completely up to the user.
      At this point, it shouldn't matter because there is a problem with the switch and that
      needs to be addressed.
      */
 }

{
   randomSeed(analogRead(0)); //wm stuff  
    ReefAngel.Init();  //Initialize controller   
    ReefAngel.FeedingModePorts = B00001000;
    ReefAngel.WaterChangePorts = B00000000;
    ReefAngel.OverheatShutoffPorts = B00000101;
    ReefAngel.LightsOnPorts = B00000001;
    // Ports that are always on
    ReefAngel.Relay.On(Return); //port 4
   //wm stuff
    ReefAngel.Timer[1].SetInterval(random(15,35));
    ReefAngel.Timer[1].Start();  
    ReefAngel.Relay.On(WavemakerL);
}

}



void loop()
{
    ReefAngel.ShowInterface();
    ReefAngel.StandardGUI(); //web connection
//    ReefAngel.StandardFan(Chiller,775,783); Removed for ATO function
    ReefAngel.StandardHeater(Heater,768,771);
    ReefAngel.StandardLights(Daylight,9,0,19,30);  //Daylight schedule 9:00am - 7:30pm
    ReefAngel.StandardLights(Refugium,21,0,9,0);  //Refugium schedule 9:00pm - 9:00am
    ReefAngel.StandardLights(LED,8,30,22,0);  //LED schedule 8:30am - 10:00pm   
    ATOFailSafe(ATO); //ATO Stuff                       
    //Wavemaker stuff
    if ( ReefAngel.Timer[1].IsTriggered() )
      {
        ReefAngel.Timer[1].SetInterval(random(15,30));
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Toggle(WavemakerL); //port 5
        ReefAngel.Relay.Toggle(WavemakerR); //port 6
       }
/*    Old ATO stuff
     if(ReefAngel.LowATO.IsActive())
        {
            ReefAngel.Relay.On(ATO); //port 7
        }
        else
        {
            ReefAngel.Relay.Off(ATO);
        }    
*/
}
Thanks!!
Last edited by chase on Fri Oct 07, 2011 10:07 am, edited 1 time in total.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reversing the ATO code

Post by rimai »

You can't use:

Code: Select all

#define LED                 7
It's a reserved word for a the LED Class :( Sorry.
Choose a different name
Roberto.
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Re: Reversing the ATO code

Post by chase »

rimai wrote:You can't use:

Code: Select all

#define LED                 7
It's a reserved word for a the LED Class :( Sorry.
Choose a different name
Hmm, changed LED to Moonlight and I still get the same error(s). It compiles without the ATO code binder suggested (including the define LED reference) which is what I've been running for a while now with no issues.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reversing the ATO code

Post by rimai »

Ahhh...
After closer look, I had to change some stuff around.
Try this:

Code: Select all

// Autogenerated file by RAGen (v1.0.4.92), (09/08/2011 09:54)
// ATO_TEST.pde
//
// This version designed for v0.8.5 Beta 12 or later

/* The following features are enabled for this PDE File: 
#define DisplayImages
#define WavemakerSetup
#define DateTimeSetup
#define VersionMenu
#define DirectTempSensor
#define DisplayLEDPWM
#define StandardLightSetup
*/

#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>

#define Daylight            1
#define AutoTopOff          2
//#define Chiller             2
#define Heater              3
#define Return              4
#define WavemakerL          5
#define WavemakerR          6
#define LED1                7
#define Refugium            8

void setup()
{
   randomSeed(analogRead(0)); //wm stuff  
    ReefAngel.Init();  //Initialize controller   
    ReefAngel.FeedingModePorts = B00001000;
    ReefAngel.WaterChangePorts = B00000000;
    ReefAngel.OverheatShutoffPorts = B00000101;
    ReefAngel.LightsOnPorts = B00000001;
    // Ports that are always on
    ReefAngel.Relay.On(Return); //port 4
   //wm stuff
    ReefAngel.Timer[1].SetInterval(random(15,35));
    ReefAngel.Timer[1].Start();  
    ReefAngel.Relay.On(WavemakerL);
}

void loop()
{
    ReefAngel.ShowInterface();
//    ReefAngel.StandardFan(Chiller,775,783); Removed for ATO function
    ReefAngel.StandardHeater(Heater,768,771);
    ReefAngel.StandardLights(Daylight,9,0,19,30);  //Daylight schedule 9:00am - 7:30pm
    ReefAngel.StandardLights(Refugium,21,0,9,0);  //Refugium schedule 9:00pm - 9:00am
    ReefAngel.StandardLights(LED1,8,30,22,0);  //LED schedule 8:30am - 10:00pm   
    ATOFailSafe(AutoTopOff); //ATO Stuff                       
    //Wavemaker stuff
    if ( ReefAngel.Timer[1].IsTriggered() )
      {
        ReefAngel.Timer[1].SetInterval(random(15,30));
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Toggle(WavemakerL); //port 5
        ReefAngel.Relay.Toggle(WavemakerR); //port 6
       }
/*    Old ATO stuff
     if(ReefAngel.LowATO.IsActive())
        {
            ReefAngel.Relay.On(ATO); //port 7
        }
        else
        {
            ReefAngel.Relay.Off(ATO);
        }    
*/
}

void ATOFailSafe(byte ATO) //changed port to ATO
{
   // Check for the low switch
   /*
   If the Low switch is active, meaning the float is opposite the end with the two wires,
        we are empty so we should turn on the pump.  Otherwise, we are full, so turn off the port.
   */
   if ( ReefAngel.LowATO.IsActive() )
   {
      ReefAngel.LowATO.StartTopping();
      ReefAngel.Relay.On(ATO);
   }
   else
   {
      ReefAngel.LowATO.StopTopping();
      ReefAngel.Relay.Off(ATO);
   }

   if ( ReefAngel.LowATO.IsTopping() && ! ReefAngel.HighATO.IsActive() )
   {
      // We have a problem
      /*
      The pump is running and topping but the low switch isn't shutting off the port.
      We must shutoff the port ourself.
      */
      ReefAngel.Relay.Off(ATO);
      // Trigger some sort of alert, maybe an email or text message

      /*
      We did not indicate that the port is not topping anymore, we could do that manually
      OR we could not do it and replace the switch and have the controller do it for us.
      It's completely up to the user.
      At this point, it shouldn't matter because there is a problem with the switch and that
      needs to be addressed.
      */
  }
}
Roberto.
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Re: Reversing the ATO code

Post by chase »

Winner- TY much!! Gonna upload it now... :D
Image
Post Reply