Page 1 of 2

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Thu Aug 24, 2017 7:40 pm
by binder
I had to scrap what I did partially due to a nuance with Arduino and sketches. Anyways, this function works but it's currently hard coded to ATO2. We can change it for future improvements if it works properly for you.

Code: Select all

#include <Salinity.h>
#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 <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

// CustomMainscreen_IOExpansion
byte x,y;
byte bkcolor;


void DrawCustomMain()
{
  // the graph is drawn/updated when we exit the main menu &
  // when the parameters are saved
  ReefAngel.LCD.DrawDate(6, 112);
  pingSerial();
#if defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params);
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
  y=10;
  x=15;
  for (int a=0;a<6;a++)
  {
    if(ReefAngel.IO.GetChannel(a)) bkcolor=COLOR_RED;
    else bkcolor=COLOR_GREEN;
    if (a>2) x=75;
    if (a==3) y=10;
    ReefAngel.LCD.Clear(bkcolor, x, y-3, x+40,y-1);
    ReefAngel.LCD.Clear(bkcolor, x, y+8, x+40,y+10);
    ReefAngel.LCD.Clear(bkcolor, x, y, x+3,y+8);
    ReefAngel.LCD.Clear(bkcolor, x+37, y, x+40,y+8);
    ReefAngel.LCD.DrawText(COLOR_WHITE, bkcolor, x+3, y, "Input");
    ReefAngel.LCD.DrawText(COLOR_WHITE, bkcolor, x+32, y, a);
    y+=15;
  }
}

void DrawCustomGraph()
{
}

/*

 For more information about custom main screen: http://forum.reefangel.com/viewtopic.php?f=14&t=109

 */

// Define Relay Ports By Name
#define ATO1               1
#define ATO2               2
#define Skimmer            3
#define Daylights          4
#define Flowpumps1         5
#define Flowpumps2         6
#define Heaters            7
#define Return             8

// Custom ATO Functions
unsigned long ATO2_timer = 0;
boolean ATO2_topping = false;
void ATOoverIO(byte relay, int timeout, byte low_ioport, byte high_ioport){
   unsigned long TempTimeout = timeout;
   TempTimeout *= 1000;

   //Is the low switch active (meaning we need to top off) and are we not currently topping off
   //Then we set the timer to be now and start the topping pump

  if ( ReefAngel.IO.GetChannel(low_ioport) && (!ATO2_topping)) {
    ATO2_timer = millis();
    ATO2_topping = true;
    ReefAngel.Relay.On(relay);
  }

   // If the high switch is activated, this is a safeguard to prevent over running of the top off pump
  if ( ReefAngel.IO.GetChannel(high_ioport) ) {
    ATO2_topping = false;
    ReefAngel.Relay.Off(relay);
  }

    // If the current time minus the start time of the ATO pump is greater than the specified timeout value
    // AND the ATO pump is currently running:
    // We turn on the status LED and shut off the ATO pump
    // This prevents the ATO pump from continuously running.

  if ( (millis() - ATO2_timer > TempTimeout) && ATO2_topping ) {
    ReefAngel.LED.On();
    // Verify the bitset function works properly
    //bitSet(ReefAngel.AlertFlags, ReefAngel.ATOTimeOutFlag);
    ReefAngel.Relay.Off(relay);
  }
}

void setup()
{
  ReefAngel.Init(); // Initialize Controller
  ReefAngel.AddDateTimeMenu();
  ReefAngel.AddStandardMenu();
  ReefAngel.SetTemperatureUnit(Celsius);  // set Temperature to Celsius
  ReefAngel.FeedingModePorts = Port5Bit | Port6Bit; // Turn off Ports 5 and 6 when Feeding Mode is activated
  ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit; // Turn off Ports 1, 2, 3, 5, 6, 7 and 8 when Water Change Mode is activated
  ReefAngel.OverheatShutoffPorts = Port4Bit | Port7Bit; // Turn off Ports 4 and 7 when Overheat Occurs
  ReefAngel.LightsOnPorts = Port4Bit; // Turn on/off Ports 4 when Turn Lights On/Off is activated
  ReefAngel.OverheatProbe = T1_PROBE; // Use Temperature probe 1, 2 and 3 to check for overheat
  ReefAngel.TempProbe = T1_PROBE; // Use Temperature probe 1, 2 and 3 to check temperature

  // Always on
  ReefAngel.Relay.On(Return);
  ReefAngel.Relay.On(Skimmer);
  ReefAngel.Relay.On(Flowpumps1);
  ReefAngel.Relay.On(Flowpumps2);

  // Initialize ATO2 values
  ATO2_timer = 0;  // always initialize to 0
  ATO2_topping = false;  // always initialize to false
}

void loop()
{
  ReefAngel.StandardATO(ATO1); // Standard ATO
  // ATOoverIO(Relay, Timeout, low io port, high io port)
  ATOoverIO(ATO2, 150, 0, 1); // Alternate ATO2
  ReefAngel.StandardLights(Daylights); // Daylight Lights
  ReefAngel.StandardHeater(Heaters); // Heater
  ReefAngel.PWM.StandardDaylight(); // Dimming for Daylight Channel
  ReefAngel.PWM.StandardActinic(30); // Dimming for Actinic Channel
  ReefAngel.ShowInterface(); // Display everything on the LCD screen
}

It compiles and will need tested. So give it a test and see how it does for you.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Thu Aug 24, 2017 10:58 pm
by JclaasSA
OK cool thanks will do so now as soon as possible should be this morning! Let you know...

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Fri Aug 25, 2017 2:58 am
by JclaasSA
Now this code compiles, that's great !

BUT am I too much of a perfectionist here or what buddy?? We are trying to have the standard ato funtion but just on the i/o expansion. I tested it using the same orientation of the floats as required in standard ato.

Standard ATO
Here is the way the Stand ardATO function works:
High switch mounted with wires at the bottom
Low switch mounted with the wires at the top
When water level lowers all the way to cause the low switch to be active (float is touching the end opposite from 2
wires coming out of it), the ATO pump/specified relay is turned on.
The ATO pump runs until the water level raises the low switch up from making contact, continues to raise the water
level until the high switch is active (float is touching the end opposite of the 2 wires coming out of it). The ATO pump
shuts off when the high switch is active OR if the ATO Timeout value is exceeded. The timeout prevents the pump
from running too long in case the reservoir runs dry or something else happens.
Water then evaporates out of the tank and lowers until the low switch is active.
Repeat process

The closest I get is with channel 0 float with wires at the bottom and channel 1 float with wires at the top but it turns the relay on and off without influence from float on channel 0.

Can you have a look at this again please with floats in standard ato orientation and revert back if i am talking nonsense!

Thanks.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Fri Aug 25, 2017 10:30 am
by JclaasSA
You have already been a big help @binder - it's much appreciated! !

I look forward to your answer.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 6:19 am
by JclaasSA
@rimai

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 6:19 am
by JclaasSA
@binder

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 6:47 am
by rimai
Probably you have the channels in the wrong position.
Try switching 0 on top and 1 at the bottom

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 8:07 am
by JclaasSA
rimai wrote:Probably you have the channels in the wrong position.
Try switching 0 on top and 1 at the bottom
Please upload this on your side and just test it for me. It appears to be code issue.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 8:17 am
by JclaasSA
rimai wrote:Probably you have the channels in the wrong position.
Try switching 0 on top and 1 at the bottom
I did this.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 10:43 am
by JclaasSA
@rimai please reply to my posts.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 10:47 am
by rimai
What do you mean? I just did.
And then you asked to try to upload and replicate the problem here.
You have to wait until I find some time to do that.
You just requested that a couple of hours ago.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sat Aug 26, 2017 8:19 pm
by JclaasSA
Float switches were tried in various positions including that way you advised that is why I am asking that the problem is replicated on your side please and I hear you @rimai.

Re: WIFI Cloud and WIFI Attachment on 2 RA plusses

Posted: Sun Aug 27, 2017 9:01 am
by JclaasSA
Howzit @binder, @rimai, @Inevo. . will you guys upload that ato code your side and replicate to see if you also getting a different functionality please?

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Sun Aug 27, 2017 11:38 am
by rimai
Why don't you just start simple and use a simple on/off instead?
Much simpler and you can work on anything you want to add later.

Code: Select all

if (ReefAngel.IO.GetChannel(0)) then ReefAngel.Relay.On(Port2);
if (!ReefAngel.IO.GetChannel(1)) then ReefAngel.Relay.Off(Port2);
You will need to play around with the ! sign in the code, which means "NOT" depending on how you orient the float switches.
Basically the code reads is the channel 0 is active, turn on port 2 and if channel 1 is not active, turn off port 2.

Re: I/O Expansion and ATO 1, 2, 3, 4....

Posted: Mon Aug 28, 2017 4:58 am
by binder
agreed. one thing I learned from working with the code is make sure you understand it and test it out. so do like Roberto says, test out simple. first just have 1 float switch toggle a relay. this let's us know if you have the float switches working properly and connected properly. once you know both switches can control a port individually, then start combining them.

Sent from my XT1585 using Tapatalk