Feeding mode using Memory

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
Rodasphoto
Posts: 187
Joined: Wed Apr 10, 2013 2:48 pm
Location: Athens, Ga
Contact:

Feeding mode using Memory

Post by Rodasphoto »

How do I code a feeding mode that turns my main pump and RW8 off and turns on my feeder (http://www.super-feed.com/product.html) for a minute or so. I would like to be able to adjust the time of when the mode initiates and number of times using the memory input in android app. Later on when I get the right cable I would like my RW8 to initiate nutrient transport mode when finished with feeding mode then go back to what ever mode I had previously. Many thanks for your help.

Main Relay
1. Skimmer
2. LED fan
3. LED power supply 1
4. LED power supply 2
5. RW8
6. MJ1200 water mixing station
7. Heater
8. DC3000

Expansion Relay 1
1. ATO
2. Not Used
3. Not Used
4. Not Used
5. Autowater change 1
6. Autowater change 2
7. Not Used
8. Not Used

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 <PAR.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.Use2014Screen(); // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port8Bit;
    ReefAngel.FeedingModePortsE[0] = Port1Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit;
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port4Bit | Port7Bit;
    // 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 = Port2Bit | Port3Bit | Port4Bit | Port8Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port7Bit;
    // 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 );
    ReefAngel.Relay.On( Port8 );

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

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

void loop()
{
    ReefAngel.DayLights( Port2 );
    ReefAngel.DayLights( Port3 );
    ReefAngel.DayLights( Port4 );
    ReefAngel.DayLights( Port5 );
    ReefAngel.DosingPumpRepeat1( Port6 );
    ReefAngel.StandardHeater( Port7 );
    ReefAngel.DayLights( Box1_Port1 );
    ReefAngel.PWM.Channel0PWMParabola();
    ReefAngel.PWM.Channel1PWMParabola();
    ReefAngel.PWM.Channel2PWMParabola();
    ReefAngel.PWM.Channel3PWMParabola();
    ReefAngel.PWM.Channel4PWMParabola();
    ReefAngel.PWM.Channel5PWMParabola();
    ////// Place your custom code below here
    ReefAngel.Relay.On( Box1_Port1 ); // ATO port is always on
    ReefAngel.DosingPumpRepeat1(Box1_Port6); // AWC change 2 (add)
    ReefAngel.DosingPumpRepeat2(Box1_Port5); // AWC change 1 (drain)

    ////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "Rodasphoto" );
    ReefAngel.ShowInterface();
}
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Feeding mode using Memory

Post by binder »

It looks like you already have the pumps being turned off during feeding mode.
Are you wanting to create a completely separate feeding mode (like feeding mode 2 or alternate feeding mode)?
User avatar
Rodasphoto
Posts: 187
Joined: Wed Apr 10, 2013 2:48 pm
Location: Athens, Ga
Contact:

Re: Feeding mode using Memory

Post by Rodasphoto »

binder wrote:It looks like you already have the pumps being turned off during feeding mode.
Are you wanting to create a completely separate feeding mode (like feeding mode 2 or alternate feeding mode)?
No I just want to be able to enter feeding mode automatically and trigger my feeder. I would need for it to be on for a minute or so. Right now I would only need this to happen once a day or every other day. When I get my trio of anthias it will need to occur 3 times a day.
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Feeding mode using Memory

Post by binder »

Here are 2 posts that will be doing exactly what you want:
http://forum.reefangel.com/viewtopic.ph ... lly#p43169
http://forum.reefangel.com/viewtopic.ph ... lly#p41920

They both trigger feeding mode based on a specific time of day. The first one shows how to activate feeding mode at 2 different times of day. The concept for it should be straight forward once you see it.

To address your comment about only running feeding mode for a minute or so, you would need to change the "Feeding Mode Timer" value from 900 seconds (which is 15 minutes) down to 60 seconds (for 1 minute) or whatever duration you want it to be.
User avatar
Rodasphoto
Posts: 187
Joined: Wed Apr 10, 2013 2:48 pm
Location: Athens, Ga
Contact:

Re: Feeding mode using Memory

Post by Rodasphoto »

Code: Select all

if (ReefAngel.Relay.isMaskOn(Box1_Port8))
if (ReefAngel.DisplayedMenu!=FEEDING_MODE) feedStart=false; // Reset the flag...
if (ReefAngel.DisplayedMenu==FEEDING_MODE && feedStart==false) {
  feedStart=true; // So we don't start the timer more than once per feeding mode.
  feedTimer=now(); // We're going to use this time to see if 2 minutes is up before we trigger the feeder.
}

if ( now()-feedTimer == 120) // 2 min later activate auto feeder

// Start feed mode once per day at 12pm. 
if (hour()==12 && minute()==0 && second()==0) ReefAngel.FeedingModeStart();
So I used a combination of both post's code and hopefully changed the time it will trigger to noon and every time I override Box1_Port8(Hopefully this is the on my 2nd relay box) to always on with the smartphone app, it will not trigger the feeding modes automatically. Also it hopefully activate autofeeder 2 minutes after the ports I have set to turn off are off. Returning Box1_Port8 to auto will make the controller start feeding automatically again. I also deleted the part of the feeder being triggered by PWM.

Does this look correct?
How will I get this to trigger a relay to be ON during feeding mode?
Can I change how I turn off the auto feed mode to a virtual relay so I don't lose an outlet?

Many thanks for all your help.
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Feeding mode using Memory

Post by binder »

Rodasphoto wrote:

Code: Select all

if (ReefAngel.Relay.isMaskOn(Box1_Port8))
if (ReefAngel.DisplayedMenu!=FEEDING_MODE) feedStart=false; // Reset the flag...
if (ReefAngel.DisplayedMenu==FEEDING_MODE && feedStart==false) {
  feedStart=true; // So we don't start the timer more than once per feeding mode.
  feedTimer=now(); // We're going to use this time to see if 2 minutes is up before we trigger the feeder.
}

if ( now()-feedTimer == 120) // 2 min later activate auto feeder

// Start feed mode once per day at 12pm. 
if (hour()==12 && minute()==0 && second()==0) ReefAngel.FeedingModeStart();
So I used a combination of both post's code and hopefully changed the time it will trigger to noon and every time I override Box1_Port8(Hopefully this is the on my 2nd relay box) to always on with the smartphone app, it will not trigger the feeding modes automatically. Also it hopefully activate autofeeder 2 minutes after the ports I have set to turn off are off. Returning Box1_Port8 to auto will make the controller start feeding automatically again. I also deleted the part of the feeder being triggered by PWM.

Does this look correct?
How will I get this to trigger a relay to be ON during feeding mode?
Can I change how I turn off the auto feed mode to a virtual relay so I don't lose an outlet?

Many thanks for all your help.
the formatting on the code makes it hard to follow, but here's how it reads to me.
  • If Box1_Port8 is masked on AND you are not in FEEDING_MODE, you reset the feedStart flag to false
  • If you are in FEEDING_MODE AND feedStart flag is false, you flip feedStart flag to true and you grab the start of the feeding mode
  • You check if 120 seconds have elapsed and once they have elapse, you check if it is noon. If it is noon, then you start your FeedingMode, which triggers your autofeeder I presume.
Based on the code you just posted, your autofeeder ONLY starts if you manually put the controller in FEEDING_MODE.

The reason it reads this way is because of your IF statements. The problem with IF statements is that the next expression right after the condition will only be executed if the condition is true. You do not have anything right after the

Code: Select all

if ( now()-feedTimer == 120)
line. So that means the next line is your if statement for starting the feeding mode. The "smarter" way to write the code is to always use the curly braces {} so there is no confusion as to what code is associated with the IF statements.

I just want to make sure I'm following your logic of what you want to do.
  • Trigger feeding mode every day at noon
  • IF you have Box1_Port8 masked on, DO NOT let feeding mode start
  • wait 2 minutes after feeding mode starts before you activate your auto feeder
I took some time and changed things around to make them simpler to follow (hopefully). Here's what I came up with (and it has not been tested, just written). You will also have to put in the code to start your autofeeder...I do not know how you do that.

Code: Select all

// outside setup
boolean feedStart;
Timer feederDelayTimer;

// inside setup
feedStart = true;
// set the interval to 120 seconds (or 2 minutes)
feederDelayTimer.setInterval(120);

// inside loop
if (ReefAngel.Relay.isMaskOn(Box1_Port8)) {
	// disable auto feeding mode by masking ON the port
	feedStart = false; 
} else {
	// reset the feedStart variable and allow feeding mode to start again once
	// the port is NOT masked on
	feedStart = true;
}

// Check if we are in the feeding mode
if ( ReefAngel.DisplayedMenu == FEEDING_MODE ) {
	// We are in feeding mode, let's see if our timer delay has expired
	if ( feederDelayTimer.isTriggered() ) {
		// delay timer is activated / expired, so we can activate the auto feeder
		// ACTIVATE AUTO FEEDER
	}
}

// Start feed mode once per day at 12pm AND only if we are able to start feeding mode
// this means that feedStart is true and not turned off by the Box1_Port8 being turned on
if ((hour()==12 && minute()==0 && second()==0) && feedStart) {
	ReefAngel.FeedingModeStart();  // start feeding mode
	// Start the auto feeder delay timer
	feederDelayTimer.Start();
}
hopefully this is easy to follow. you will want to test it, but I think it should work ok for you.
User avatar
Rodasphoto
Posts: 187
Joined: Wed Apr 10, 2013 2:48 pm
Location: Athens, Ga
Contact:

Re: Feeding mode using Memory

Post by Rodasphoto »

That is exactly what I would like to do. I also would like to be able to initiate the feeding mode by choosing the mode on my phone. I also do not know how to turn on a relay port to trigger my timer. Many thanks for fixing the code for me.
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Feeding mode using Memory

Post by binder »

Rodasphoto wrote:That is exactly what I would like to do. I also would like to be able to initiate the feeding mode by choosing the mode on my phone. I also do not know how to turn on a relay port to trigger my timer. Many thanks for fixing the code for me.
You still can initiate the feeding mode from your phone BUT it will not trigger the 2 minute delay to turn on your autofeeder. That functionality will require a little more thought.

Ok. I had to go back and re-read your previous posts to make sure I follow you correctly. I had skipped over a few things because I wanted to focus on the main topic at hand. I also misread your part about removing the code to trigger your autofeeder when I did my breakdown of your original code. So part of my explanation of how I interpreted your code was off....my bad. The end result though with my revised code for you still holds true.

Now on to these questions:
How will I get this to trigger a relay to be ON during feeding mode?
If you want to turn on a port during feeding mode, you would just issue the command ReefAngel.Relay.On(Port8) (to turn on port 8).
I'm going to use an example building on my previous code. Let's say you wanted to turn on Port 7 on the main relay and Port 6 of your expansion relay when you enter feeding mode and have them both be off otherwise. This also assumes that they are not turned off when feeding mode is activated (by using the FeedingModePorts value in setup).
Here's what you would have:

Code: Select all

// Check if we are in the feeding mode
if ( ReefAngel.DisplayedMenu == FEEDING_MODE ) {
	// We are in feeding mode, let's see if our timer delay has expired
	if ( feederDelayTimer.isTriggered() ) {
		// delay timer is activated / expired, so we can activate the auto feeder
		// ACTIVATE AUTO FEEDER

		// Turn on these ports when the AutoFeeder is activated
		ReefAngel.Relay.On(Port1);
	}
	// Turn on these ports when we are in feeding mode, no matter how it is triggered
	ReefAngel.Relay.On(Port7);
	ReefAngel.Relay.On(Box1_Port6);
} else {
	// Turn off these ports when we are not in Feeding Mode
	ReefAngel.Relay.Off(Port1);
	ReefAngel.Relay.Off(Port7);
	ReefAngel.Relay.Off(Box1_Port6);
}
Now, it gets a little more complicated if the ports get toggled ON/OFF in other parts of the code. That can be handled though. However, I started with a simple answer and we can always build on it or adapt it as needed.
Can I change how I turn off the auto feed mode to a virtual relay so I don't lose an outlet?
Yes, you can do this rather easily. We just need to check the status of the relay and that will enable it. Again, I'm going to modify the code that I posted and show the change. I'm not going to repeat all the code from above, I'm just going to show what has changed.

Code: Select all

// outside of setup, towards the top
// This is the first port of the second relay box, which is non-existant
#define VO_DISABLE_AUTO_FEEDER    Box2_Port1

// inside loop...the Box1_Port8 was changed to the virtual outlet
if (ReefAngel.Relay.isMaskOn(VO_DISABLE_AUTO_FEEDER)) {
   // disable auto feeding mode by masking ON the port
   feedStart = false; 
} else {
   // reset the feedStart variable and allow feeding mode to start again once
   // the port is NOT masked on
   feedStart = true;
}
Now, once you load this code on your controller, it will give you 2 expansion relay boxes. When you refresh the android app, it will show both of the expansion relay boxes. The first port on the second expansion box will allow you to disable the auto feeder. So I would change the name to be something like "Disable Auto Feeder". Then whenever you have it forced / masked on (where it shows the port ON and there is a green dot next to it), it will disable your autofeeder from activating at noon.

Here's the complete code with all these changes described above in it:

Code: Select all

// outside setup
#define VO_DISABLE_AUTO_FEEDER Box2_Port1
boolean feedStart;
Timer feederDelayTimer;

// inside setup
feedStart = true;
// set the interval to 120 seconds (or 2 minutes)
feederDelayTimer.setInterval(120);

// inside loop
if (ReefAngel.Relay.isMaskOn(VO_DISABLE_AUTO_FEEDER)) {
   // disable auto feeding mode by masking ON the port
   feedStart = false; 
} else {
   // reset the feedStart variable and allow feeding mode to start again once
   // the port is NOT masked on
   feedStart = true;
}

// Check if we are in the feeding mode
if ( ReefAngel.DisplayedMenu == FEEDING_MODE ) {
	// We are in feeding mode, let's see if our timer delay has expired
	if ( feederDelayTimer.isTriggered() ) {
		// delay timer is activated / expired, so we can activate the auto feeder
		// ACTIVATE AUTO FEEDER

		// Turn on these ports when the AutoFeeder is activated
		ReefAngel.Relay.On(Port1);
	}
	// Turn on these ports when we are in feeding mode, no matter how it is triggered
	ReefAngel.Relay.On(Port7);
	ReefAngel.Relay.On(Box1_Port6);
} else {
	// Turn off these ports when we are not in Feeding Mode
	ReefAngel.Relay.Off(Port1);
	ReefAngel.Relay.Off(Port7);
	ReefAngel.Relay.Off(Box1_Port6);
}

// Start feed mode once per day at 12pm AND only if we are able to start feeding mode
// this means that feedStart is true and not turned off by the Box1_Port8 being turned on
if ((hour()==12 && minute()==0 && second()==0) && feedStart) {
   ReefAngel.FeedingModeStart();  // start feeding mode
   // Start the auto feeder delay timer
   feederDelayTimer.Start();
}
I think that should answer your questions except for the one about using the Feeding Mode button on your phone to trigger everything that your autofeed mode at noon does. I'm still thinking on it.

Otherwise, let me know if you still have questions.
jgwinner
Posts: 16
Joined: Fri Dec 27, 2013 8:22 pm

Re: Feeding mode using Memory

Post by jgwinner »

Just wanted to post a quick note - love this fix! I'm using the same feeder, and this has enabled me to travel out of town for 3 weeks. Thank you!

Had to make a few changes to the code, however.

Timer is actually TimerClass now as near as I can tell. I cut that part out while debugging the code.

I'm also adding a 'pulse' timer, so that after say 2 minutes (the original delay), the pumps will turn on for just a couple of seconds. This spreads the food all through the tank. I have some very stupid fish that won't go up to the surface. You'd think they would after they are hungry, but the blue Tang really does have the personality of Dory. More importantly, I lost a diamond headed goby as he just hung around the sand - never got fed with the automatic feeder.

== John ==
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Feeding mode using Memory

Post by binder »

jgwinner wrote:Just wanted to post a quick note - love this fix! I'm using the same feeder, and this has enabled me to travel out of town for 3 weeks. Thank you!

Had to make a few changes to the code, however.

Timer is actually TimerClass now as near as I can tell. I cut that part out while debugging the code.

I'm also adding a 'pulse' timer, so that after say 2 minutes (the original delay), the pumps will turn on for just a couple of seconds. This spreads the food all through the tank. I have some very stupid fish that won't go up to the surface. You'd think they would after they are hungry, but the blue Tang really does have the personality of Dory. More importantly, I lost a diamond headed goby as he just hung around the sand - never got fed with the automatic feeder.

== John ==
awesome. glad it has helped you out. gotta keep those finicky fish happy. lol


Sent from my iPad mini
User avatar
Rodasphoto
Posts: 187
Joined: Wed Apr 10, 2013 2:48 pm
Location: Athens, Ga
Contact:

Re: Feeding mode using Memory

Post by Rodasphoto »

jgwinner wrote:Just wanted to post a quick note - love this fix! I'm using the same feeder, and this has enabled me to travel out of town for 3 weeks. Thank you!

Had to make a few changes to the code, however.

Timer is actually TimerClass now as near as I can tell. I cut that part out while debugging the code.

I'm also adding a 'pulse' timer, so that after say 2 minutes (the original delay), the pumps will turn on for just a couple of seconds. This spreads the food all through the tank. I have some very stupid fish that won't go up to the surface. You'd think they would after they are hungry, but the blue Tang really does have the personality of Dory. More importantly, I lost a diamond headed goby as he just hung around the sand - never got fed with the automatic feeder.

== John ==
Nice. I lost a fish because the food not dispersing fast enough. Would you mind posting your code?
Image
Post Reply