Sacohen's Current code

Share you PDE file with our community

Posts: 144
Joined: Tue Aug 14, 2012 1:11 pm
PostPosted: Mon Dec 01, 2014 3:33 pm
here is the whole code.

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 <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.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
    ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
    ReefAngel.AddMultiChannelWaterLevelExpansion();  // Water Level Expansion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port4Bit | Port6Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port4Bit | Port6Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port3Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    ReefAngel.UseFlexiblePhCalibration();
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.

    // Ports that are always on
    ReefAngel.Relay.On( Port1 );
    ReefAngel.Relay.On( Port6 );
    ReefAngel.Relay.On( Port7 );
    ReefAngel.Relay.On( Box1_Port1 );
    ReefAngel.Relay.On( Box1_Port2 );
    ReefAngel.Relay.On( Box1_Port3 );
    ReefAngel.Relay.On( Box1_Port4 );
    ReefAngel.Relay.On( Box1_Port5 );
    ReefAngel.Relay.On( Box1_Port6 );
    ReefAngel.Relay.On( Box1_Port7 );
    ReefAngel.Relay.On( Box1_Port3 );
    ////// Place additional initialization code below here
     //Use PH Flexible Calibration
    ReefAngel.UseFlexiblePhCalibration(); 


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

void loop()
{
    ReefAngel.Relay.DelayedOn( Port2 );
    ReefAngel.StandardHeater( Port3 );
    ReefAngel.WaterLevelATO( Port4 );
    ReefAngel.Wavemaker1( Port5 );
    ReefAngel.DayLights( Port8 );
    ReefAngel.PWM.Channel0PWMSlope();
    ReefAngel.PWM.Channel1PWMSlope();
    ReefAngel.PWM.Channel2PWMSlope();
    ReefAngel.PWM.Channel3PWMSlope();
    ReefAngel.PWM.Channel4PWMSlope();
    ////// Place your custom code below here
    // Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;


// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Lagoon, Constant, TidalSwell, ShortPulse, LongPulse, Else, Gyre };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<3600) {
// Continue NTM for the 60 minutes
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<43200 || now()%SECS_PER_DAY>=79200) { // 12pm / 10pm
// Night mode (go to 30%)
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
ReefAngel.DCPump.Mode=Constant;
ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) {
// Custom Mode and nothing else going on
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
} else {
ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
    ////// Place your custom code above here

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

Adam
58 Gal
Image

Posts: 144
Joined: Tue Aug 14, 2012 1:11 pm
PostPosted: Mon Dec 01, 2014 3:34 pm
Here is the libraries version

Reef Angel Libraries Found: Development
Reef Angel Libraries Version: 1.1.0
Adam
58 Gal
Image
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Mon Dec 01, 2014 3:35 pm
This is for the developmental code (11).
For the currently released code (10) the original post that was in red will work.
The part to remove would be the same part that is in blue.

Posts: 144
Joined: Tue Aug 14, 2012 1:11 pm
PostPosted: Mon Dec 01, 2014 4:37 pm
Still same error with

ElseMode
Adam
58 Gal
Image
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Tue Dec 02, 2014 4:31 pm
Are you using the the libraries that are part of the Arduino Controller or did you go to GitHub and download the dev libraries from there (https://github.com/reefangel/Libraries/archive/dev.zip)?

Posts: 144
Joined: Tue Aug 14, 2012 1:11 pm
PostPosted: Tue Dec 02, 2014 7:54 pm
part of arduino, didn't know I had to download from github..

NVM, i figuired it out
Adam
58 Gal
Image
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Wed Dec 03, 2014 8:10 am
You don't have to download the dev files.
You are either using the currently released version the Roberto had tweaked, approved and release or you are using a beta version that people are adding things to and making adjustments.

Glad you got it working.
Please post what you did to get it working so others can benefit from it.

Posts: 213
Joined: Mon Apr 01, 2013 7:58 pm
PostPosted: Tue Apr 07, 2015 10:37 pm
Sacohen wrote:This is a copy of my current code basically as a backup, but feel free to look over it and use what you may feel fits your needs.

The system includes...
RA +
Relay(original included)'
Standard ATO High and Low
Expansion Hub
Dimming Expansion
Power Control Expansion
Water Level Expansion
Salinity Expansion
ATO Pump
WiFi module
Bluetooth module
2 Jebao Cables (WP-25, WP-40)

3 Temp Sensors
Dimmable Lunar Hub & 2 Moonlights

Basic control of the following.
Daylight
Actinic
Moonlight
Pumps
2 Jebao pumps (WP40 & WP25)
Control of my NatuReef DeNitrification chamber.
(Thanks to lnevo for help with this coding)

Random Jebao modes that lnevo did for PaulTurner911.

12/21/13
Changed the Speed for the Jebao pumps from 30% to 0% during feeding.

3/22/14
Added AutoFeeder triggered by Reef Angel.
How to modify the Eheim 3581 are here. http://wamas.org/forums/blog/13/entry-4 ... ontroller/

Added Dimmable Lunar Hub. Right now I'm just using the MoonPhase with an on and off time that coincide with my lighting. I added a slope to it so it seems like a moonrise and set

4/8/14 Added some code to turn a pump on every 8 hours for 15 min to stir my Kalkwasser.

5/26/14 Removed code to mix Kalkwasser.

8/1/14 Modified the Denitrification code to use variables instead of hard times. (Thanks to lnevo again for this)

8/4/14 Added Kalk Mixing Code. When the ATO reservoir is at 100% or above the pump in the reservoir turns on for 1 hr to mix the Kalkwasser in the reservoir and then turns off to let the unsaturated Kalk settle to bottom before use as ATO water.

9/11 Updated code for 1.1.1 Libraries. Added DNS server name and Server Authentication. Removed the Else Mode wave function code since it is now incorporated in to the libraries and added the Gyre Wave mode to the choice of Random Waves. Made some slight changes to the ATO code that had to be done because of the new libraries.

1/26/15 Added RA Net and Relay.

2/27/15 Added code to auto flush my RO/DI unit 3 times a week.

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>
#include <SoftwareSerial.h>

// Define Relay Ports by Name
#define Actinic_Lights     1
#define Day_Lights         2
#define Kalkwasser         3
#define Pumps              4
#define Unused             5
#define DeNit_Doser        6
#define DeNit_Pump         7
#define ATO_Pump           8

#define Unused             Box1_Port1
#define Feeder             Box1_Port2
#define Unused             Box1_Port3
#define Unused             Box1_Port4
#define Unused             Box1_Port5
#define Unused             Box1_Port6
#define Main_RODI        Box1_Port7
#define Dummy              Box1_Port8


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

// Does not need to be global.
// unsigned long ATOUpdate=0;

////// 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 = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port4Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 825 );
//Set Standard Menu
ReefAngel.AddStandardMenu();
//Water Level
ReefAngel.AddMultiChannelWaterLevelExpansion();
//Webserver Authentication
ReefAngel.Network.WifiAuthentication("Sacohen:xxxxxxxx");
//DDNS Server
ReefAngel.DDNS("myreeftank");
ReefAngel.AddRANet();

// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.
//ReefAngel.DCPump.DaylightChannel=AntiSync; // Now you're pump will be affected by the portal settings.
//ReefAngel.DCPump.AntiSyncOffset=85;

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

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


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

void loop()
{
  ReefAngel.StandardLights( Actinic_Lights,12,0,22,0 );
  ReefAngel.StandardLights( Day_Lights,13,0,21,0 );
  ReefAngel.WaterLevelATO(0,ATO_Pump,720,34,36);
  if ( hour()>=13 && hour()<21 )
  ReefAngel.PWM.SetChannel( 5, 0 );
  else
  ReefAngel.PWM.SetChannel( 5, PWMSlope(21,0,13,0,0,MoonPhase() ,60,0) );
 
  ////// Place your custom code below here

  //Flush RO/DI Membrane 3 times a week @ 9pm.
ReefAngel.Relay.Set(Main_RODI,(now()+10800)%(SECS_PER_DAY*3)<300);
 
  //Mix Kalkwasser
static unsigned long Kalk_Mixing = 0;

static unsigned long stopTime = 0;
static byte prevWL=0;

if (ReefAngel.WaterLevel.GetLevel(1)==100 && prevWL<100) {   
  stopTime=now()+3600; // Get time one hour from now.
}
prevWL = ReefAngel.WaterLevel.GetLevel(1); // Store the water level

if (now() < stopTime) { ReefAngel.Relay.On(Kalkwasser); } else { ReefAngel.Relay.Off(Kalkwasser); }
 
  //AutoFeeder
static unsigned long autofeeding = 0;

if ((now()%SECS_PER_DAY==64800)) //if it is 6 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( autofeeding == 0 ) {
autofeeding = now(); //set the time of the start of feeding to variable feeding
}

if ((now()-autofeeding>=60) && (now()-autofeeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Feeder); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Feeder); //TURN FEEDER RELAY OFF
}
} else {
if ( autofeeding > 0 ) {
autofeeding = 0;
}
}
  // DeNitrate Routine
int DeNit_Offset=3600;
int DeNit_Repeat=21600;
int DeNit_Doser_Offset=1200;
int DeNit_Doser_Runtime=600;
int DeNit_Pump_Runtime=1200;
int DeNit_ATO_Offtime=1500;

// Pump comes on first
ReefAngel.Relay.Set(DeNit_Pump,(now()-DeNit_Offset)%DeNit_Repeat<DeNit_Pump_Runtime);  // Runs denitrator pump
// Doser comes on second
ReefAngel.Relay.Set(DeNit_Doser,((now()-DeNit_Offset)-DeNit_Doser_Offset)%DeNit_Repeat<DeNit_Doser_Runtime); // Runs denitrator doser
   
  // Disable ATO
if ( (now()-3600)%21600<DeNit_ATO_Offtime) ReefAngel.WaterLevelATO(0,ATO_Pump,720,0,1);

  // Delay WL ATO after water change and DeNit_Dosing
  static time_t wcTimer=0;
  if (ReefAngel.DisplayedMenu == WATERCHANGE_MODE) wcTimer=now();

  // First 10 minutes after WC disable ATO
  if (now()-wcTimer >= 0 && now()-wcTimer < 600)
    ReefAngel.WaterLevelATO(0,ATO_Pump,720,0,1);

    // Track Salinity low duration
    static unsigned long lastGoodSal;
    static boolean lowSalFlag;
   
    // Salinity is good, update counter
    if (ReefAngel.Params.Salinity>=335) lastGoodSal=now();
   
    // Counter hasn't been updating in 300 seconds..
    if (now()-lastGoodSal>300) {
      lowSalFlag=true; // Salinity is definitely below 33.5
    } else {
      lowSalFlag=false; // Salinity back to normal
    }
   
    // Disable ATO if lowSalFlag is true
   //if (lowSalFlag) ReefAngel.WaterLevelATO(0,ATO_Pump,720,0,1);
   
  // Disable ATO if ATO High IsActive()
  if (ReefAngel.HighATO.IsActive())
    ReefAngel.WaterLevelATO(0,ATO_Pump,720,0,1);
   

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;


// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Gyre, Lagoon, Constant, TidalSwell, ShortPulse, LongPulse, Else, };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<3600) {
  // Continue NTM for the 60 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<43200 || now()%SECS_PER_DAY>=79200) { // 12pm / 10pm
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=Constant;
  ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) {
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}

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

  // This should always be the last line
  ReefAngel.Portal( "Sacohen","xxxxxxxx" );
  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,57, "WL:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,57, ReefAngel.WaterLevel.GetLevel() );

ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,66,66, "WL 1:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,66, ReefAngel.WaterLevel.GetLevel(1) );

//Salinity 
  ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
  strcat(text,"  ");
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,39,75,"Salinity:");
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,99,75,text);
pingSerial();

// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 92, TempRelay );
pingSerial();
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox(12, 104, TempRelay);

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

void DrawCustomGraph()
{
}


sorry steve couldn't find it, but what valve did you use to flush your ro/di?
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Wed Apr 08, 2015 5:44 am
I got a 1/2" Normally Closed Pneumatic Plastic Air Water Electric Solenoid Valve 12V DC off Ebay (http://www.ebay.com/itm/1-2-Inch-Normal ... 1c4fff435f) plumbed it into my line that feeds my RO/Di system and then plugged it into my RANet Relay in the garage.

I got the 12v version because I was originally going to run Cat 5 wir back to my 12v Power Expansion module and running from there, but I had problems with the power expansion module and when Roberto released the RANet Relay I got that instead.

The valve is just running ordinary house water thru it so you don't need to worry about it being OK for salt water and corrosion.

This is the code I'm using to turning on 3 days a week for 5 min at 9PM.

Code: Select all
  //Flush RO/DI Membrane 3 times a week @ 9pm.
ReefAngel.Relay.Set(Main_RODI,(now()+10800)%(SECS_PER_DAY*3)<300);


I'm trying to figure out how to get it to run Monday, Wednesday and Friday rather than every 3 days.

Roberto gave me this for 3 specific days, but it didn't seems to work.

Code: Select all
ReefAngel.Relay.Set(Main_RODI, ((weekday()==dowMonday || weekday()==dowWednesday || weekday()==dowFriday) && (now()+10800)<300 ));


I'm not real good at coding so I can't figure out why it wasn't working.

Posts: 102
Joined: Wed Nov 18, 2015 9:16 pm
PostPosted: Wed Dec 09, 2015 2:19 pm
is there a way to have a random mode from, lets say, 10 am to 6 pm and then run a set mode over night?
PreviousNext

Return to My PDE/INO file

Who is online

Users browsing this forum: No registered users and 1 guest