Page 1 of 1

Water Level Expansion

Posted: Mon Sep 24, 2012 1:55 pm
by alexwbush
First off, this thing is awesome!! It's going to make auto water change programming very easy!

I have programmed a basic ATO (where Port5 is my top off pump relay) along with a basic pump shut off if water is low (where Port8 is my return pump relay):

Code: Select all

  // If water level less than 60, turn on auto top off relay; else, keep it off
  if (ReefAngel.WaterLevel.GetLevel()<60) ReefAngel.Relay.On(Port5);
  else ReefAngel.Relay.Off(Port5);
  // If water level equals 0, turn off return relay; else, keep it on  
  if (ReefAngel.WaterLevel.GetLevel()==0) ReefAngel.Relay.Off(Port8);
  else ReefAngel.Relay.On(Port8);
But I want to work with a timeout feature and I think maybe something similar to the heater or just make it turn on for a set number of seconds so that it isn't flipping the switch off and on when the water is fluctuating when topping off (i.e. water level is 60, top off until 62, then wait for 60 again). I am also wondering if there is an internal memory I plug into my functions and be able to adjust in portal or android (just like timeouts and changing times for lights).

Here is my full code if needed. Side note, I am trying to keep it on a standard RA board:

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

#include <WaterLevel.h> //Added for water level

// Initialize Buzzer variables
byte buzzer=0;
byte overheatflag=0;
byte atoflag=0;
////// Place global variable code below here

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

void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port4Bit | Port7Bit | Port8Bit;
  ReefAngel.FeedingModePortsE[0] = 0;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port7Bit | Port8Bit;
  ReefAngel.WaterChangePortsE[0] = Port5Bit | Port6Bit;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port6Bit;
  ReefAngel.LightsOnPortsE[0] = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port7Bit;
  ReefAngel.OverheatShutoffPortsE[0] = 0;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // Ports that are always on
  ReefAngel.Relay.On( Port1 ); //left radion
  ReefAngel.Relay.On( Port2 ); //right radion
  ReefAngel.Relay.On( Port8 ); //return
  ReefAngel.Relay.On( Box1_Port7 ); //TBD
  ReefAngel.Relay.On( Box1_Port8 ); //TBD
  ////// Place additional initialization code below here
  InternalMemory.ATOHourInterval_write(0);
  ////// Place additional initialization code above here
}
void loop()
{
  ReefAngel.StandardHeater( Port3 );
  ReefAngel.Relay.DelayedOn( Port7 );

  overheatflag = InternalMemory.read( Overheat_Exceed_Flag );
  atoflag = InternalMemory.read( ATO_Exceed_Flag );
  ////// Place your custom code below here

  /* Auto feeding mode starts.  
   Feeder set for 17:30, start feeding mode at 17:25. */
  if ( hour() == 17 && minute() == 25 && second() ==0 ) //if time is 17:25:00
  {
    ReefAngel.FeedingModeStart(); //start feeding mode
  }

  // Run Vortech during day only.  Vortech is on from 09:00-20:00.
  ReefAngel.StandardLights(Port4,9,0,20,0);
  
  // If in water change mode, turn on the light in the cabinet (so I can see!)
  if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.On(Port8);
  
  // If water level less than 60, turn on auto top off relay; else, keep it off
  if (ReefAngel.WaterLevel.GetLevel()<60) ReefAngel.Relay.On(Port5);
  else ReefAngel.Relay.Off(Port5);
  // If water level equals 0, turn off return relay; else, keep it on  
  if (ReefAngel.WaterLevel.GetLevel()==0) ReefAngel.Relay.Off(Port8);
  else ReefAngel.Relay.On(Port8);
  
  ////// Place your custom code above here
  // This should always be the last line
  ReefAngel.Portal( "wolfpack" );
  ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
  byte x = 6;
  byte y = 2;
  byte t;
  char text[7];

  /* Drawing this:
   
   01/01/12 00:00:00 AM
   ----------------------
   Disp 79.9  pH     8.00
   Sump 79.9  Sal    0.60
   Room 77.7  WtrLvl Ok
   
   1 2 3 4 5 6 7 8
   1 2 3 4 5 6 7 8
   
   Moon Waning Crescent
   Intensity 88%
   Sunrise   06:15
   Sunset    18:12
  */
   
  /* Colors used in this script:
     DefaultFGColor   - For basic font and line
     DefaultBGColor   - For background color
     PHColor          - For values that may change
     OutletOnBGColor  - For okay water level
     OutletOffBGColor - For low water level
     
     To change colors, modify these values in ReefAngel_CustomColors.h file
  */

  ReefAngel.LCD.DrawDate(6, 2);
  ReefAngel.LCD.Clear(DefaultFGColor, 1, 11, 128, 11);
  pingSerial();

  //ReefAngel.LCD.DrawText(fcolor,bcolor,x,y,"text");

  //Line 1 - Display Temp & pH
  x = 8;
  y = 15;
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Disp");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T1_PROBE], PHColor, x, y, 10);
  x = 70; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"pH");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, PHColor, x, y, 100);

  //Line 2 - Sump & Salinity
  x = 8;
  y += 10; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Sump");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], PHColor, x, y, 10);
  x = 70; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Sal");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Salinity, PHColor, x, y, 10);

  //Line 3 - Room
  x = 8;
  y += 10; 
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Room");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], PHColor, x, y, 10);
  x = 70;
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,x,y,"Lvl");
  x += 30;
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.WaterLevel.GetLevel(), PHColor, x, y, 1);

  //Lines 4 and 5 - Relays
  x = 12; 
  y += 15;
  // draw main relay
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(x, y, TempRelay);

  pingSerial();
}
void DrawCustomGraph()
{
}

Re: Water Level Expansion

Posted: Mon Sep 24, 2012 2:06 pm
by rimai
No, no memory locations for that, but it's a good idea.
I think I'll add a new ATO function. What do you think of WaterLevelATO(byte Port, byte LowLevel, byte HighLevel, int ATOTimeOut)?

Re: Water Level Expansion

Posted: Mon Sep 24, 2012 2:18 pm
by alexwbush
Where LowLevel is when it triggers the ATO and HighLevel is where it stops? If so, PERFECT. I assume the ATOTimeOut would be the same memory adjustable variable that is in the portal and apps?

If you decide you want to release the ATO function to beta testers, send it this way before Thursday! That starts my 5 weeks away. Currently I have it set to turn on if the level goes below 60. I also have a wired floatswitch setup plugged in between the relay and pump that I bought a while before my RA as a backup.

Re: Water Level Expansion

Posted: Mon Sep 24, 2012 2:22 pm
by rimai
Yes, you got the idea :)
I don't think it will be good out before Thursday, though.

Re: Water Level Expansion

Posted: Mon Sep 24, 2012 2:28 pm
by alexwbush
Any ideas on temporary solutions?

I was thinking:

Code: Select all

  byte topofflevel=60;
  // If water level less than 60, turn on auto top off relay; else, keep it off
  if (ReefAngel.WaterLevel.GetLevel()<topofflevel)
  {
     topofflevel=62;
     ReefAngel.Relay.On(Port5);
  }
  else
  {
     topofflevel=60;
     ReefAngel.Relay.Off(Port5);
   }
  // If water level equals 0, turn off return relay; else, keep it on  
  if (ReefAngel.WaterLevel.GetLevel()==0) ReefAngel.Relay.Off(Port8);
  else ReefAngel.Relay.On(Port8);
But I don't think that's going to work. [UPDATE] Nevermind, I just tested it and IT DOES WORK! This will work until I get back from my trip (unless you get timeout working earlier) Still interested if there is a function I can use to turn on the port for X seconds at a time.

Also, brilliant idea!! Is there another memory variable I could run in the meantime?? One where I can store my top off amount? I don't use chiller, wavemaker, or any of the standard or dimming expansion values.

Re: Water Level Expansion

Posted: Mon Sep 24, 2012 2:47 pm
by rimai
Yeah, you can use any of the ones you are not using, or you can use a custom one.
For example, pick memory location 1000 for low level and 1001 for high level.
Use Android to set those custom memories and use InternalMemory.read(1000) in your code instead of your hard coded value.

Re: Water Level Expansion

Posted: Mon Sep 24, 2012 2:51 pm
by alexwbush
rimai wrote:Yeah, you can use any of the ones you are not using, or you can use a custom one.
For example, pick memory location 1000 for low level and 1001 for high level.
Use Android to set those custom memories and use InternalMemory.read(1000) in your code instead of your hard coded value.
Awesome! I'll do that. I didn't think my coding would work :lol: I'm a little rusty from my C++ days.

Looking at the android app, I see

Water Level Max Value (Location 327) Current Value: 2623
Water Level Min Value (Location 325) Current Value: 954

Nevermind, I can't use these, they're for calibrating the water level :lol:

I'll stick to 1000 and 1001