TanksNStuff's 120G Upgrade Code

Share you PDE file with our community
Post Reply
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

I've had an RA Plus running my 75G tank for over 2 years and haven't had the need to change anything until my recent upgrade to a 120G tank with some equipment changes.

For now, I'm going to provide what I have so far, and note what I want to change/add ASAP.

First, my system info:
RA+
Expansion Hub
Expansion Relay
WiFi Module
VorTech RF Module
Dimming Expansion

Standard ATO (Low)
pH Probe
3 Temp Probes (Tank/Sump/Room)

Tank Equipment:
2 Apollo Reef LED Fixtures (Blue/White's dimmable, ML is On/Off)
Waveline DC6000 Return Pump (Do not have DC controller cable as these apparently don't work well with them)
2 VorTech MP40WES
BM CS180 Skimmer
Aqua UV 25watt UV Filter
Avast Marine Pressure Sensor (used in skimmate collection container to shut off skimmer if full)
Finnex 300W Heater
Tunze ATO Pump (the controller failed on me, so I hard wired to the power plug and control it thru RA float)
Refugium Light - Standard clip on HD fixture with a 38 PAR LED bulb

Here are the basic control features I have included in my code and should be working (not uploaded yet, but it compiles):
NOTE - Everything setup for internal memory settings so I can have on-demand control/adjustment with the Android App

- Parabola slope for Actinic/Daylight LED's on Dimmer Expansion Module - Future addition of Cloud/Storm effects
----LED 1 Blue = Channel 0
----LED 2 Blue = Channel 1
----LED 1 White = Channel 2
----LED 2 White = Channel 3
---- Channel 4 & 5 are not used
------Blue Schedule is On 8 AM / Off 9 PM (3 Hour offset)
------White Schedule is On 11 AM / Off 6 PM

- Moon Lights - Schedule is opposite Daylights, but modified to turn off from Midnight to 7:30 AM (They are too bright and non-dimmable) So basically, they turn on from 6 PM and turn off at Midnight, then come on at 7:30 AM and stay on until 11 AM. I may add code to turn them off from 8AM thru 11 AM since they aren't needed while Blues are on.

- Refugium Light - Opposite of Daylights (not modified)
----Also set to turn On during WC Mode (I think my code will do this, but not tested yet.)

- Lights On Mode - Set to turn on all Blue/White/ML Leds and Refugium Light (Blue/Whites brightness controlled by Dimmer, so ML will assure some light even at night... and Refugium Light tagged here as backup in case it doesn't come on during WC Mode)

- ATO controlled by float switch in Return chamber of sump, controlled by Single ATO (Low)

- Temp controlled by T1 Temp Probe (Tank temp)

- Feeding Mode - Will turn off Skimmer, ATO, and Return Pumps. VorTechs should go into Feeding Mode

- WC Mode - Will turn off VorTech Pumps, Skimmer, ATO, and Heater. I left Return pump on because I have a manifold on it and use my valves to use return pump to take out water. In doing this, I need to use the Android App to control the Return Pump port manually. I plan to turn off the Return port to let sump fill up a bit, then go into WC Mode, set up my bucket and valves for the WC, then manually turn the Return port back on (and off again if/when the return section gets too low or as I need to change buckets, etc.

- Overheat Mode - Unlikely to happen with LED's and the DC return pump... but just in case, this will shutoff all LED's except moonlights, Refugium Light, and the Heater.

- VorTech MP40's - Have a schedule for daytime operation (Between 8 AM and 10 PM) and nighttime operation (Between 11 AM and 7 AM)
----Daytime should run as per the internal memory selection for the most part. I have added (what I think) should put them in Nutrient Transport Mode for 30 minutes after Feeding Mode ends. Have not uploaded the code yet to test it.
----Nighttime should basically just set the time range for Night Mode on the VorTechs (15% speed)

- Dosing Pumps - As of right now, I have Pump1 set to dose every 32 minutes for 60 seconds, Pump2 the same (with 5 minute offset). These are brand new and I have yet to calibrate them, nor figure out my tru dosing needs, so I'll leave this alone for now until I see what I need to change.

Here are a few things I want to add ASAP:
- Dosing Pumps - As I figure out the proper dosage rates I need, I'll adjust these memory locations. Also, I may decide to adjust it so that Alk runs only at night, and Cal runs only in day. Thoughts on this?

- Storm effects - Would really like to figure out how to convert Colin's cloud/lightning code to the dimmer expansion. Will work on that when I get some time.

I think that's about it for now. If I think of more, I'll update the post later.

Updated 10/13/14:
- Added #Define statements to name all my ports / Removed Commented section that did this before.
- Used the port names in lieu of default port naming scheme throughout most of the code (Mostly on custom stuff) as per LNevo's suggestion.
- Replaced the RF Daytime / Nightime control coding that used "Timer[1]" also as per LNevo's suggestion. I borrowed code found in his .INO thread and it looks much cleaner and works great!
- Uploaded the Vortech Setup code and synced up both of my MP40's, set 1 as sync and 1 as anti-sync.
- Uploaded this code and rearranged my equipment plugs to the correct (new) ports.
- Decided to add both MP40's to same port (using a plug splitter) since they don't draw much power and I don't need independent control of them power-wise. If I need to change this in the future, I have 1 open port that I can use.
- Dosing pumps are not physically online yet because I didn't have time to test/calibrate them and still need to get all the tubing mounting, etc. situated. Have checked that the port get's activated per the schedule I setup though.
- Everything seems to be working fine but will likely tweek things as I monitor it.


Updated 10/16/14:
- Added command: ReefAngel.RF.SetMode(Feeding_Stop,0,0); just before the UseMemory=true line to fix the issue with the RF module failing to reset. I had thought this issue was fixed and didn't add the workaround this time, but it appears it's still needed. At least LNevo was kind enough to help clear that one up.
- I also changed the VorTech mode change commands (after Feeding Mode and custom "Night mode") because the original version didn't include speed commands. I basically went back to the version I had in my previous code and the 1-line command seems to be working fine.


OK, here is my updated / current INO:

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

// Define Relay Ports by Name
//Main Relay Box
#define DPump1            1
#define DPump2            2
#define Skimmer           3
#define Fan               4
#define Vortechs          5
#define Open              6
#define Refugium          7
#define Topoff            8

//Expansion Relay Box 1
#define LED1B             Box1_Port1
#define LED2B             Box1_Port2
#define LED1W             Box1_Port3
#define LED2W             Box1_Port4
#define LED1M             Box1_Port5
#define LED2M             Box1_Port6
#define Return            Box1_Port7
#define Heater            Box1_Port8

////// 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 = Port3Bit | Port8Bit;
    ReefAngel.FeedingModePortsE[0] = Port7Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port3Bit | Port5Bit | Port8Bit;
    ReefAngel.WaterChangePortsE[0] = Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port7Bit;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port4Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port7Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port8Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;


    // Ports that are always on
    ReefAngel.Relay.On( Vortechs );
    ReefAngel.Relay.On( Open );
    ReefAngel.Relay.On( Return );

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

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

void loop()
{
    ReefAngel.DosingPumpRepeat1( DPump1 );
    ReefAngel.DosingPumpRepeat2( DPump2 );
    ReefAngel.Relay.DelayedOn( Skimmer );
    ReefAngel.StandardFan( Fan );
    ReefAngel.MoonLights( Refugium );
    ReefAngel.SingleATOLow( Topoff );
    ReefAngel.ActinicLights( LED1B );
    ReefAngel.ActinicLights( LED2B );
    ReefAngel.DayLights( LED1W );
    ReefAngel.DayLights( LED2W );
    ReefAngel.MoonLights( LED1M );
    ReefAngel.MoonLights( LED2M );
    ReefAngel.StandardHeater( Heater );
    ReefAngel.PWM.Channel0PWMParabola();
    ReefAngel.PWM.Channel1PWMParabola();
    ReefAngel.PWM.Channel2PWMParabola();
    ReefAngel.PWM.Channel3PWMParabola();
    ReefAngel.RF.UseMemory = true;
    
    ////// Place your custom code below here
    
//----------------------------------- Custom Moon Light Schedule -------------------------------
    if ( NumMins(hour(),minute()) < 450 )  // Turn off Moonlights from Midnight to 7:30 AM
    {
      ReefAngel.Relay.Off( LED1M );
      ReefAngel.Relay.Off( LED2M );
    }
//------------------------------- End of Custom Moon Light Schedule ----------------------------
//------------------------------------ Fuge Light on for WC Mode -------------------------------
  if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) 
  {
    ReefAngel.Relay.On( Refugium );
  }
//---------------------------------- End Fuge Light on for WC Mode -----------------------------
//------------------------- Set NTM after Feeding Mode and Set Night Mode ----------------------
  static unsigned long FeedTime;
  if (ReefAngel.DisplayedMenu==FEEDING_MODE) FeedTime=now();
  
  if (now()-FeedTime>0 && now()-FeedTime<3600)
  {
    // Continue NTM for the 60 minutes
    ReefAngel.RF.UseMemory=false;
    ReefAngel.RF.SetMode(Smart_NTM,155,5);
  }
    else if (now()%SECS_PER_DAY<25200 || now()%SECS_PER_DAY>=82800) 
  { // 7:00am / 11:00pm
  // Night mode (go to 15%)
  ReefAngel.RF.UseMemory=false;
  ReefAngel.RF.SetMode(Night,15,0);
  }
  else 
  {
    ReefAngel.RF.SetMode(Feeding_Stop,0,0);
    ReefAngel.RF.UseMemory=true; // Will reset all values from memory
  }
//----------------------- End Set NTM after Feeding Mode and Set Night Mode --------------------     

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

    // This should always be the last line
    ReefAngel.Portal( "TanksNStuff" );
    ReefAngel.ShowInterface();
}
Last edited by TanksNStuff on Thu Oct 16, 2014 5:05 pm, edited 2 times in total.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: TanksNStuff's 120G Upgrade Code

Post by Sacohen »

TanksNStuff wrote:Waveline DC6000 Return Pump (Do not have DC controller cable as these apparently don't work well with them)
Looks like a nice setup.
Just a comment about this line above.

The DC return pumps work fine with the controller cable, but they don't work well as a wave generator. the pumps don't respond fast enough.

Roberto is using his DC return pump along with the controller cable and a water level sensor to adjust the speed of the pump and in turn the water level of his overflow. So there is no noise and bubbles in the water column.

Here is a the thread he started about it.
http://forum.reefangel.com/viewtopic.ph ... obertoflow.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: TanksNStuff's 120G Upgrade Code

Post by lnevo »

The Nutrient Transport function should work fine. I would recommend getting away from the Timer class though as it sucks :) Also you could easily conflict with the Portal timer, etc. In fact you might be conflicting, I forget...

It's much easier to just use "static unsigned long timer;" then start your timer by using timer=now();

Then to see if your in the timing you want... if (now()-timer < 1800) ... do whatever you want...

I don't see any issue to dose cal during the day and alk during the night. All you need to do is declare your dosing pumps first, then do your check for time of day and if it's not set to run, then turn off the relay...

i.e.

Code: Select all

if (hour()<8 || hour()>=20) ReefAngel.Relay.Off(Calcium_Port);
if (hour()>=8 || Hour()<20) ReefAngel.Relay.Off(Alk_Port);

Which comes to my next comment. Instead of having the big comment block defining what your ports are consider replacing it with something like this...

#define DosingPump1 Port1

Then in your code you can do this:

ReefAngel.DosingPumpRepeat1( DosingPump1 );
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

Sacohen wrote:
TanksNStuff wrote:Waveline DC6000 Return Pump (Do not have DC controller cable as these apparently don't work well with them)
Looks like a nice setup.
Just a comment about this line above.

The DC return pumps work fine with the controller cable, but they don't work well as a wave generator. the pumps don't respond fast enough.

Roberto is using his DC return pump along with the controller cable and a water level sensor to adjust the speed of the pump and in turn the water level of his overflow. So there is no noise and bubbles in the water column.

Here is a the thread he started about it.
http://forum.reefangel.com/viewtopic.ph ... obertoflow.
That's good to know. Thanks for the information on that Steve!
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

lnevo wrote:The Nutrient Transport function should work fine. I would recommend getting away from the Timer class though as it sucks :) Also you could easily conflict with the Portal timer, etc. In fact you might be conflicting, I forget...

It's much easier to just use "static unsigned long timer;" then start your timer by using timer=now();

Then to see if your in the timing you want... if (now()-timer < 1800) ... do whatever you want...

I don't see any issue to dose cal during the day and alk during the night. All you need to do is declare your dosing pumps first, then do your check for time of day and if it's not set to run, then turn off the relay...

i.e.

Code: Select all

if (hour()<8 || hour()>=20) ReefAngel.Relay.Off(Calcium_Port);
if (hour()>=8 || Hour()<20) ReefAngel.Relay.Off(Alk_Port);

Which comes to my next comment. Instead of having the big comment block defining what your ports are consider replacing it with something like this...

#define DosingPump1 Port1

Then in your code you can do this:

ReefAngel.DosingPumpRepeat1( DosingPump1 );[/quote]

Thanks Lee.  The code I was using for the nutrient mode was borrowed from my original setup (which I think I borrowed from you a couple years ago  :lol: ).  It seemed to be working at one point so I didn't bother to mess with it, but I knew there were some changes in the libraries and wasn't sure if it would still work.

I'll try to make the changes you suggested and see if that works better for the timer.  I'm not 100% sure on how to do it, but I can research that wording on these forums and find some examples to figure out how to use it properly.

Also, the big comment block designating the ports was merely for my own use and to show others viewing my code what I have plugged into which port.  I didn't intend for it to actually "define" anything in the code... but I may consider doing it the way you suggested so that I can simplify my port calls throughout the code.

Thank you for the tips!
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

This is still a work in progress, but here is a pic of my side cabinet that houses all of my controller equipment. I still need to upload my new code (above) when it's finished so that all my outlets are setup for the new equipment they will control. Also, I plan to organize all the wiring to keep it neat. I may even go with some electrical conduit or some sort of tracking to make it look even nicer.

Anyway, figured this would be a good place to show you all what I have so far. I'll update it when I got it all finalized.

----Picture is kind of big, so here's a link to it if you want to open in a new tab/window ----
http://www.njreefclub.com/HostedImages/ ... G_0115.JPG



Image

Below the shelf that you see, I'll have my 2 dosing pumps (right above the Cal/Alk holding containers) and my Carbon and GFO reactors. You can't see any of this in the pic, but wanted to give you an idea of what else was in the cabinet.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

Well, after loading my new code last night, most everything seems to be working fine. The only issue I encountered so far was that in the morning my VorTechs didn't revert back to normal. I have it set to "night" mode by making them go to Constant - 30% speed from 11 PM to 7 AM. However, at 8 AM this morning, it was still running at those settings.

NOTE - I did a hard reset on both VorTech drivers before syncing them up last night so they shouldn't have any "Night" mode settings on them directly... so that shouldn't be the problem.

I tried to manually adjust the VorTech pump settings via the Android App and although the controller head unit showed the change, the VorTechs did not show any response. Then I unplugged the RF module from the expansion hub and plugged it back in and they instantly changed.

Not sure if that was just a fluke issue with the RF module or if this is an issue with the code. I'll have to see if it happens again to know for sure.

Anyway, pretty happy with everything so far and now I'll see if I can figure out how to convert Colin's storm code over from the relay box dimmers to the expansion dimmer channels so I can get some cloud/lightning action going on. :D
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

OK, well after uploading the last version (10/13/14) I noticed I was having a few bugs that needed to be worked out.

For one thing, after feeding mode the VorTechs did go into Nutrient Transport Mode (NTM) for 1 hour as desired. However, the speed was set at 0 so basically this kept them from running at all for an hour after feeding... sort of defeating the purpose.

So, reviewing the code I borrowed from LNevo for this portion, I noticed that there was no code line to designate a speed for this mode. So I added a line similar to the one he had for the "Night Mode" portion and it now looks like this:

Code: Select all

//------------------------- Set NTM after Feeding Mode and Set Night Mode ----------------------
  static unsigned long FeedTime;
  if (ReefAngel.DisplayedMenu==FEEDING_MODE) FeedTime=now();
  
  if (now()-FeedTime>0 && now()-FeedTime<3600)
  {
    // Continue NTM for the 60 minutes
    ReefAngel.RF.UseMemory=false;
    ReefAngel.RF.Mode=NutrientTransport;
    ReefAngel.RF.Speed=100;
  }
    else if (now()%SECS_PER_DAY<25200 || now()%SECS_PER_DAY>=82800) 
  { // 7:00am / 11:00pm
  // Night mode (go to 30%)
  ReefAngel.RF.UseMemory=false;
  ReefAngel.RF.Mode=Constant;
  ReefAngel.RF.Speed=30;
  }
  else 
  {
    ReefAngel.RF.UseMemory=true; // Will reset all values from memory
  }
//----------------------- End Set NTM after Feeding Mode and Set Night Mode --------------------- 
Now, when I added this line and uploaded it to the head unit, it was pretty late and already into the "Night Mode" time frame. I don't know if that was the reason for the next issue or if it was a coincidence, but something weird happened. My controller head unit (and the Android App) said I was in NTM at 100%, but my VorTechs seemed to remain at the previous "Night Mode" (Constant, 30%) speed. And, to make matters worse, the RF Module light went off completely. My RF Module was not sending any signal at all.

I disconnected the RF module from my expansion hub, then plugged it back in. I got a quick green light, then 3 quick red flashes, then no light at all. I tried this several times and even tried rebooting the head unit, but it still did the same thing.

After this, I decided to reload the VorTech setup code and I re-synced everything to get it to work again. Then I re-uploaded my newly revised code and everything was working normally.

I didn't attempt to test the feeding mode again because I didn't want to go through all that again to get it working normally. I'll test the NTM switch function at feeding time tonight and report back. I have a feeling that if I ever attempt to go into feed mode when it's already in "Night Mode" I may have this issue again though.

If anyone can review the code and let me know if there's a way to skip the "Night Mode" functions if I go into Feed Mode or if I can skip the "NTM" mode part if I'm already in "Night Mode" that would probably be my best protection to avoid this happening in the future.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: TanksNStuff's 120G Upgrade Code

Post by lnevo »

I think your misunderstanding what the ecotech firmware does vs the rf module firmware. They are completely separate. We don't implement the ecotech driver code in the RF module but enough info to speak with their drivers. From what I remember the way to upgrade the ecotech drivers happens when you sync them to each other. The latest one will sync the older one up so they speak the same language. If you have different gens I don't think that even applies. None of that has anything to do with the Storm mode that Roberto added. You can use that regardless of which firmware you're using on the ecotech level. It's not a built-in mode on the ecotechs so its not saying hey ecotech go into storm mode. The RF module is telling each driver what to do manually. With the RF module you can do whatever you want. In fact I've implemented all the RA modes on my vortechs by using the Custom mode which lets you set each driver independently to whatever speed you want.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: TanksNStuff's 120G Upgrade Code

Post by lnevo »

As far as your bugs I think you need to declare your speed when going to NTM so your approach is OK. You need to get out if night mode by setting the mode to Feeding_Stop briefly, otherwise it waits for the built-in timer to elapse. I think the default is 10 hours.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

Gotcha Lee. I thought that Roberto was actually updating the firmware with the workaround found in the other post. If that's not the case, then no biggy. It will be nice to add the storm mode as another option to choose from though.

As to my bugs and your suggestion, I will do what you suggest and report back if it worked or not. I just got done dinner and went to feed the fish and even though it's not "Night Mode" the RF module light went out completely again when I ended Feeding Mode. Do I need to add a Feeding_Stop for that part too? I had to reboot my head unit to resolve the RF Module outage and luckily that's all it took to fix it. However, it wasn't in NTM, it reverted back to my default setting of Constant, 100%.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: TanksNStuff's 120G Upgrade Code

Post by TanksNStuff »

Feeding_Stop fixed the error with the RF module outage. I only added it once, right before the: ReefAngel.RF.UseMemory=true;

All seems to be working much better now. Thanks Lee!

Going to update my first post with the change(s).
Post Reply