Page 3 of 4

Re: New System

Posted: Tue Jan 22, 2013 8:09 pm
by rimai
Try this:

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 <AI.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <Salinity.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.WaterChangePorts= Port1Bit | Port2Bit | Port3Bit | Port5Bit | Port6Bit;

  // Ports that are always on
  ReefAngel.Relay.On(Port1);
  ReefAngel.Relay.On(Port2);
  ReefAngel.Relay.On(Port3);
  ReefAngel.Relay.On(Port4);
  ////// Place additional initialization code below here


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

void loop()
{
  // Specific functions that use Internal Memory values
  ReefAngel.Wavemaker(Port5,60);
  ReefAngel.Wavemaker(Port6,120);
  ReefAngel.StandardHeater(Port7,757,763);
//  ReefAngel.StandardLights(Port8,17,0,13,0);
  ReefAngel.WaterLevelATO(Port8,60,70,75); // 60 seconds timeout, turn on at 70% and turn off at 75%
  ReefAngel.PWM.SetDaylight( MoonPhase() );
  ReefAngel.PWM.SetActinic( MoonPhase() );
  ////// Place your custom code below here


    ////// 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, 14, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 14, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();

  // Salinity
  ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,54, "SAL:" );
  ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,54, ReefAngel.Params.Salinity );
  pingSerial();

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

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

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

void DrawCustomGraph()
{
}


Re: New System

Posted: Tue Jan 22, 2013 8:21 pm
by smcglaughn
When I verified this code it said "class reefangelclass has no memeber named waterlevelATO


#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 <AI.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <Salinity.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.WaterChangePorts= Port1Bit | Port2Bit | Port3Bit | Port5Bit | Port6Bit;

  // Ports that are always on
  ReefAngel.Relay.On(Port1);
  ReefAngel.Relay.On(Port2);
  ReefAngel.Relay.On(Port3);
  ReefAngel.Relay.On(Port4);
  ////// Place additional initialization code below here


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

void loop()
{
  // Specific functions that use Internal Memory values
  ReefAngel.Wavemaker(Port5,60);
  ReefAngel.Wavemaker(Port6,120);
  ReefAngel.StandardHeater(Port7,757,763);
//  ReefAngel.StandardLights(Port8,17,0,13,0);
  ReefAngel.WaterLevelATO(Port8,60,70,75); // 60 seconds timeout, turn on at 70% and turn off at 75%
  ReefAngel.PWM.SetDaylight( MoonPhase() );
  ReefAngel.PWM.SetActinic( MoonPhase() );
  ////// Place your custom code below here


    ////// 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, 14, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 14, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();

  // Salinity
  ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,54, "SAL:" );
  ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,54, ReefAngel.Params.Salinity );
  pingSerial();

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

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

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

void DrawCustomGraph()
{
}

Re: New System

Posted: Tue Jan 22, 2013 8:37 pm
by smcglaughn
I had a light in outlet 8 before. could that be the problem?

Re: New System

Posted: Tue Jan 22, 2013 9:18 pm
by Piper
What version of the libs do you have? Go to Tools -> Reef Angel Libraries Version. Sounds like you might need to update to the latest libs, 1.0.3.

~Charlie

Re: New System

Posted: Wed Jan 23, 2013 10:20 am
by smcglaughn
The head unit shows version 1.0.2

New System

Posted: Wed Jan 23, 2013 11:45 am
by lnevo
http://forum.reefangel.com/viewtopic.php?p=15603#p15603

Or make sure your arduino has updated the libraries to latest version...

The feature was added between 1.0.2 and 1.0.3

Re: New System

Posted: Wed Jan 23, 2013 12:21 pm
by smcglaughn
How do I do that?

Re: New System

Posted: Wed Jan 23, 2013 12:33 pm
by rimai
Didn't your Arduino ask you to update libraries?

Re: New System

Posted: Wed Jan 23, 2013 1:57 pm
by smcglaughn
No sir it didnt.

Re: New System

Posted: Wed Jan 23, 2013 2:32 pm
by rimai
It should have asked you. If it didn't, you will need to uninstall the RA installer, download it from the website and install again.

Re: New System

Posted: Wed Jan 23, 2013 5:32 pm
by smcglaughn
I did as suggested and it worked.
The additions appear to be working.
Thanks for your help!

Re: New System

Posted: Thu Jan 24, 2013 5:09 pm
by smcglaughn
Well I was to quick . The moonlights stay on all the time. I calibrated the salinity probe, but on the main screen it shows "SAL 239"

Re: New System

Posted: Thu Jan 24, 2013 5:22 pm
by rimai
That's how we coded your moonlights. Do you have a specific time you want them on?
Make sure the calibration happens at the same temperature as your tank.
1 degree difference and your calibration is off.

New System

Posted: Thu Jan 24, 2013 5:25 pm
by lnevo
When do you want your moonlights on?

Do you want it to ramp up to the
Moonphase % ? how long of a ramp up/down? or a parabola effect with the moonphase % as a peak? Or just on/off?

Re: New System

Posted: Thu Jan 24, 2013 5:36 pm
by smcglaughn
I have the calibration solution bottle floating in the tank. I will retry but 240 is a long way from 35?
I would like the moonlights to have a parabola effect with the moon phase. To simulate natural moonlight.
Also my ATO pump seems like it is running to much. It turns on about every minute or two for a fraction of a second. It seems that it has a very small water level range that it is operating in. It isn't overflowing my tank.

New System

Posted: Thu Jan 24, 2013 5:43 pm
by lnevo
Still need to know times you want moonlight on..

The waterlevelato line controls the ato pump...the numbers are 70 and 75 represent the on/off times...you can make it longer by changing those numbers further apart...but then you will have a larger swing in salinity...on/off more frequently for shorter time is good..

Your other option is to adjust the flow on your ato pump...if you have that capability to slow it down...

Re: New System

Posted: Thu Jan 24, 2013 5:46 pm
by smcglaughn
Moonlights on at 10 PM off at 6 AM

New System

Posted: Thu Jan 24, 2013 5:59 pm
by lnevo
I'll let roberto answer on the code because doing the parabola over night requires a helper function not in the library...

Sorry to make it more confusing...

If you just want it on and off for change the setdaylight/setactinitic functions to this instead

If ( (hour()>=22) || (hour()<6) ) {
ReefAngel.PWM.SetDaylight( MoonPhase() );
ReefAngel.PWM.SetActinic( MoonPhase() );
}

Re: New System

Posted: Thu Jan 24, 2013 6:31 pm
by smcglaughn
I did the calibration of the salinity probe again. Temps were the same. The head unit still shows SAL 260
Ill just wait on the moon lights. I would like a natural cycle.

New System

Posted: Thu Jan 24, 2013 6:33 pm
by lnevo
Lol

Good...cause I forgot a paren.,,

Re: New System

Posted: Thu Jan 24, 2013 7:07 pm
by smcglaughn
What about the salinity probe?

Re: New System

Posted: Thu Jan 24, 2013 8:46 pm
by rimai
What do you get when you finish calibration and the probe is still inside the solution?

Re: New System

Posted: Thu Jan 24, 2013 8:47 pm
by rimai
260 is really 26.0
It's a display bug that doesn't draw the decimal point.

Re: New System

Posted: Fri Jan 25, 2013 7:33 am
by smcglaughn
Thats fine. Ill revisit later. It showed 350. I used the calibration fluid on my refractometer and it was way off. What about my moonlights

Re: New System

Posted: Fri Jan 25, 2013 9:20 am
by rimai
Parabola won't cross over to next day :(
Maybe we can steal the code from another user :twisted:
http://forum.reefangel.com/viewtopic.php?f=2&t=2386

This is the code we need to adapt:

Code: Select all

byte TunzeSineWave(boolean isleftpump, byte minspeed, byte maxspeed, int period_sec) {
  double x,y;

  x=double(now()%(period_sec));
  x/=period_sec;
  x*=2.0*PI;
  if (!isleftpump) x+=PI; // shift the sine wave for the right pump 

  y=sin(x);// y is now between -1 and 1
  y+=1.0; // y is now between 0 and 2
  y/=2.0; // y is now between 0 and 1  
  
  // now compute the tunze speed
  y*=double(maxspeed-minspeed);
  y+=double(minspeed); 
  
  y+=0.5; // for proper rounding
  
  // y is now between minspeed and maxspeed, constrain for safety  
  return constrain(byte(y),30,100); 
}
Are you good with math? :)
The idea is to create a sine wave that will cycle through with a total phase of 16 hours.
This will create the first half phase of 8 hrs, which is what you want, right?
Then we can just offset it by 79200 seconds, which represents 22 hours of the day and make the cycle start at 10pm.
Does it make sense?

Re: New System

Posted: Fri Jan 25, 2013 9:52 am
by lnevo
An easier route if you don't mind making some compromise.... Moonrise/Set isn't so much like Sunrise / Set, so if you use the slope, here's the PWMSlopeOvernight function and how you would use it...

ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(22,0,6,0,0,MoonPhase(),30,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(22,0,6,0,0,MoonPhase(),30,0));

byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte
endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{

unsigned long Start = previousMidnight(now())+((unsigned long)NumMins(startHour, startMinute)*60);
if (hour()<startHour) Start-=86400;
unsigned long StartD = Start + (Duration*60);
unsigned long End = nextMidnight(now())+((unsigned long)NumMins(endHour, endMinute)*60);
if (hour()<startHour) End-=86400;
unsigned long StopD = End - (Duration*60);
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM,
endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM,
endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;

// lastly return the existing value
return oldValue;
}

Re: New System

Posted: Fri Jan 25, 2013 3:40 pm
by smcglaughn
Where do I put this code? Im good with either one. I would like it to be variable. It doesnt have to be perfect.

Re: New System

Posted: Fri Jan 25, 2013 4:01 pm
by lnevo
put this part

ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(22,0,6,0,0,MoonPhase(),30,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(22,0,6,0,0,MoonPhase(),30,0));

where you had the ReefAngel.PWM.SetDaylight/SetActinic functions...

put the rest at the bottom after the last } in your code.

The 30 toward the end of those lines btw is a 30 minute ramp up/down. If you want it longer you can change that to 60 or 90 or whatever minutes you want....

Re: New System

Posted: Fri Jan 25, 2013 4:07 pm
by rimai
Hey lnevo, just curious to know if you've been using the overnight function.
How's it working out?
I wanted to confirm that it works so I can put it in the libraries.

Re: New System

Posted: Fri Jan 25, 2013 4:44 pm
by lnevo
Good question... I haven't been up between 3 and 5 am to check on it... but according to the status chart... it looks like it is working..

http://forum.reefangel.com/status/chart ... ilter=pwma