Two code issues

Do you have a question on how to do something.
Ask in here.

Posts: 24
Joined: Tue May 21, 2013 6:18 pm
PostPosted: Mon Jun 02, 2014 3:02 pm
There are two issues I'm having with my code right now. The first one is that I have a delayed start command in my code, but for some reason anytime I go into feeding mode my skimmer on port 7 starts up immediately instead of waiting for two minutes.

The next issue is with the WP10 I have on the daylight phase of the relay box. I sometimes find the powerhead turned off and I need to unplug it and plug it back in to get it started again. Not sure why it is doing that. Here is my current code:

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

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


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


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

// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port7Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port6Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit | Port8Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 869 );


// Ports that are always on
ReefAngel.Relay.On( Port8 );

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


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

void loop()
{
ReefAngel.StandardHeater( Port3,781,790 );
ReefAngel.StandardFan( Port1,791,801 );
ReefAngel.Relay.DelayedOn( Port7,2 );
////// Place your custom code below here
ReefAngel.DosingPumpRepeat(Port4,0,360,300);
ReefAngel.WaterLevelATO(Port6,40,43,90);
if (ReefAngel.HighATO.IsActive())
{
ReefAngel.Relay.On(Port7);
}
else
{
ReefAngel.Relay.Off(Port7);
}
if (hour()>=8 && hour()<12)
{
ReefAngel.PWM.SetDaylight( TidalSwellMode(60,true) ); // Tidal Swell at 60% on sync mode
ReefAngel.PWM.SetActinic( TidalSwellMode(60,false) ); // Tidal Swell at 60% on anti-sync mode
}
else if (hour()>=12 && hour()<16)
{
ReefAngel.PWM.SetDaylight( ReefCrestMode(80,20,true) ); // ReefCrest at 80% + - 20 on sync mode
ReefAngel.PWM.SetActinic( ReefCrestMode(80,20,false) ); // ReefCrest at 80% + - 20 on anti-sync mode
}
else if (hour()>=16 && hour()<17)
{
ReefAngel.PWM.SetDaylight( NutrientTransportMode(75,90,2000,true) ); // Nutrient Transport on sync mode
ReefAngel.PWM.SetActinic( NutrientTransportMode(75,90,2000,false) ); // Nutrient Transport on anti-sync mode
}
else if (hour()>=17 && hour()<20)
{
ReefAngel.PWM.SetDaylight( ReefCrestMode(80,20,true) ); // ReefCrest at 75% + - 20 on sync mode
ReefAngel.PWM.SetActinic( ReefCrestMode(80,20,false) ); // ReefCrest at 75% + - 20 on anti-sync mode
}
else if (hour()>=20 && hour()<24)
{
ReefAngel.PWM.SetDaylight( TidalSwellMode(60,true) ); // Tidal Swell at 60% on sync mode
ReefAngel.PWM.SetActinic( TidalSwellMode(60,false) ); // Tidal Swell at 60% on anti-sync mode
}
else
{
ReefAngel.PWM.SetDaylight( LongPulseMode(0,40,10,true) ); // Long pulse at 40% with 10s pulse on sync mode
ReefAngel.PWM.SetActinic( LongPulseMode(0,40,10,false) ); // Long pulse at 40% with 10s pulse on anti sync mode
}
if( ReefAngel.DisplayedMenu==FEEDING_MODE ) ReefAngel.PWM.SetActinic(0);
static byte WC_status=0;
/*
0- No WC mode
1- WC started, so port5 is on
2- WC started and water has reached 5%, so port 5 is off and port2 is on
3- WC started and water has reached 43%, so port 2 is off
*/

if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE && WC_status==0)
{
ReefAngel.Relay.On(Port5);
WC_status=1;
}
if (ReefAngel.WaterLevel.GetLevel()<=5 && WC_status==1)
{
ReefAngel.Relay.Off(Port5);
ReefAngel.Relay.On(Port2);
WC_status=2;
}
if (ReefAngel.WaterLevel.GetLevel()>=43 && WC_status==2)
{
ReefAngel.Relay.Off(Port2);
ButtonPress++;
WC_status=3;
}
if (ReefAngel.DisplayedMenu!=WATERCHANGE_MODE)
{
WC_status=0;
}
////// Place your custom code above here

// This should always be the last line
ReefAngel.ShowInterface();
}

void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();

// Water Level
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,75,66, "WL:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,66, ReefAngel.WaterLevel.GetLevel() );
pingSerial();

// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 92, TempRelay );
pingSerial();

// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}

void DrawCustomGraph()
{
}

Posts: 12327
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Mon Jun 02, 2014 3:36 pm
You are overriding the delayedon with your float switch check
Try this instead:
Code: Select all
if (ReefAngel.HighATO.IsActive())
{
 ReefAngel.Relay.DelayedOn( Port7,2 );
}
else
{
 ReefAngel.Relay.Off(Port7);
}
Roberto.
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Jun 02, 2014 3:39 pm
The skimmer is turning on because you have a high float switch statement saying to turn it on if its active. I would make that condition just turn off if not active instead of doing on and off.

The pump is probably close to the minimum amount that these drivers handle which is usually around 30-40%


Do you know around when it shuts down?

Posts: 24
Joined: Tue May 21, 2013 6:18 pm
PostPosted: Mon Jun 02, 2014 5:50 pm
I figured that might be the skimmer issue. I'll give it a shot. I wanted to code it to turn it off if not active because that made more sense in my head but I could not find the appropriate coding in order to do that. I only found the statement IsActive())

I think the pump is shutting off at night and then not turning back on in the morning, but I'm not certain of that. I was going to check tomorrow morning. I may just end up using it in a different mode eventually as the pumps are actually in two separate tanks so they don't need to work in conjunction with each other. I just wanted to make sure it was changing intensities to provide some turbulent flow in my frag tank. I may actually need to run it at higher speeds anyway as it is the only pump in my frag tank.
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Jun 02, 2014 6:55 pm
Use ! To get the opposite result from IsActive.

I think speed increase will solve the issue. The next version will have a minimum speed you can set so this doesn't happen.

Posts: 24
Joined: Tue May 21, 2013 6:18 pm
PostPosted: Tue Jun 03, 2014 7:46 am
Yeah the pump shut off just a few minutes ago this morning. So I'm guessing it shut off while in long pulse mode and the speed got a bit too low. Admittedly I just borrowed that code for the pumps from someone else so I don't fully understand the workings of it.

Also the ! would have never thought of that. Learn something new everyday!
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Jun 03, 2014 7:58 am
The other thing you can do is instead of having the On for the skimmer in that check, you can just move the DelayedOn command into the if statement without changing any of the code logic :)

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 3 guests