Custom code, please help

Do you have a question on how to do something.
Ask in here.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

Code: Select all

ReefAngel.SingleATO(true,Box1_Port8,180,2);
This code only enables the ATO to work once every 2 hours. even if it works for only half a second, it would only allow to pump again after 2 hours.
To disable the 2 hour restriction, replace the 2 for 0.
To test the ports, you can use the ControllerTester code.
File->Sketchbook->Example Codes
Roberto.
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Thanks Roberto. Great support. I appreciate it.

I thought the last digit is for time-out in minutes.
How can I setup the ATO pump timeout, if the ato pump is on for more than X minutes to turn on the red light and to shutdown the ato pump?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

That's the 180 in that function.
Here is a reference of that function:
http://www.easte.net/RA/html/class_reef ... 545a376e92
Roberto.
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Also, since the latest library update, without modifying the code, I can't upload it to RA anymore, size too big.

here is the old code, including the wifi module. Is it possible to make it smaller, without losing the main functions? I'm not using the pH sensor anymore, so pH related code can go.

/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
void setup()
{
ReefAngel.Init();
ReefAngel.FeedingModePorts = Port6Bit;
ReefAngel.FeedingModePortsE[0] = Port4Bit | Port5Bit | Port8Bit;
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port6Bit | Port8Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit | Port4Bit | Port5Bit | Port8Bit;
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit;
ReefAngel.OverheatShutoffPortsE[0] = Port1Bit;
ReefAngel.LightsOnPorts = 0;
ReefAngel.Relay.On(Port6);
ReefAngel.Relay.On(Box1_Port1);
ReefAngel.Relay.On(Box1_Port3);
ReefAngel.Relay.On(Box1_Port4);
ReefAngel.PHMin = 537;
ReefAngel.PHMax = 860;
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
InternalMemory.OverheatTemp_write(820);
}
void loop()
{
ReefAngel.SingleATO(true,Box1_Port2,180,2);
ReefAngel.StandardFan(Box1_Port6,775,785);
ReefAngel.StandardHeater(Box1_Port1,770,775);
ReefAngel.DosingPumpRepeat(Box1_Port7,0,144,2);
ReefAngel.DosingPumpRepeat(Port8,1,144,2);
if (hour() >= 10 && hour() < 20)
{
ReefAngel.StandardLights(Port1,11,1,19,0);
ReefAngel.StandardLights(Port3,11,0,19,0);
ReefAngel.StandardLights(Port4,10,0,19,59);
ReefAngel.StandardLights(Box1_Port5,14,0,15,0);
ReefAngel.StandardLights(Box1_Port8,13,0,16,0);
ReefAngel.StandardLights(Port5,8,0,11,0);
ReefAngel.PWM.SetDaylight(PWMSlope(11,0,19,0,0,20,120,0));
ReefAngel.PWM.SetActinic(PWMSlope(10,0,19,59,0,20,180,0));
}
else
{
ReefAngel.StandardLights(Port2,21,1,5,0);
ReefAngel.StandardLights(Port3,20,0,6,0);
ReefAngel.StandardLights(Port4,21,0,5,0);
ReefAngel.StandardLights(Box1_Port5,1,0,2,0);
ReefAngel.StandardLights(Box1_Port8,1,0,4,0);
ReefAngel.StandardLights(Port5,19,0,22,0);
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(20,0,6,0,0,20,180,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(21,0,5,0,0,20,120,0));
}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1200 || ReefAngel.Params.Temp[T3_PROBE] >= 1200) {ReefAngel.Relay.On(Port7);}
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) {ReefAngel.Relay.Off(Port7);}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1300 || ReefAngel.Params.Temp[T3_PROBE] >= 1300) {ReefAngel.Relay.Off(Port1);}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1300 || ReefAngel.Params.Temp[T3_PROBE] >= 1300) {ReefAngel.Relay.Off(Port2);}
ReefAngel.ShowInterface();
ReefAngel.Portal("d0lph1n","xxxxx");
}
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;
return oldValue;
}

===
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <Time.h>
#include <OneWire.h>
#include <RA_NokiaLCD.h>
#include <avr/pgmspace.h>
#include <InternalEEPROM.h>
#include <Wire.h>
#include <Memory.h>

RA_NokiaLCD e;

void setup()
{
e.Init();
e.Clear(COLOR_WHITE,0,0,132,132);
e.BacklightOn();
InternalMemory.FeedingTimer_write(900);
InternalMemory.LCDTimer_write(600);
InternalMemory.HeaterTempOn_write(765);
InternalMemory.HeaterTempOff_write(770);
InternalMemory.ChillerTempOn_write(785);
InternalMemory.ChillerTempOff_write(775);
InternalMemory.OverheatTemp_write(800);
InternalMemory.IMCheck_write(0xCF06A31E);
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+20, MENU_START_ROW*3, "Memory Updated");
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+25, MENU_START_ROW*6, "You can now");
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+25, MENU_START_ROW*7, "upload your");
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+33, MENU_START_ROW*8, "INO code");
}

void loop()
{
}
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Custom code, please help

Post by lnevo »

You can take out the PWMSlopeOvernight now and just use PWMSlope which now supports overnight or normal mode :)
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

lnevo wrote:You can take out the PWMSlopeOvernight now and just use PWMSlope which now supports overnight or normal mode :)
Thanks for your suggestion. Where can I find more info about Overnight vs normal mode or can you help me re-write the code please?
Last edited by d0lph1n on Mon May 13, 2013 1:49 pm, edited 1 time in total.
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Custom code, please help

Post by lnevo »

If the start time is greater than the end time, it will automatically work now.

If the start time is less than the end time it reverse to the old default behavior. Nothing for you to change except have the start and end time be what you want :)
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Please let me know if the code below is correct:

/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
void setup()
{
ReefAngel.Init();
ReefAngel.FeedingModePorts = Port6Bit;
ReefAngel.FeedingModePortsE[0] = Port4Bit | Port5Bit | Port8Bit;
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port6Bit | Port8Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit | Port8Bit | Port4Bit | Port5Bit;
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit;
ReefAngel.OverheatShutoffPortsE[0] = Port1Bit;
ReefAngel.Relay.On(Port6);
ReefAngel.Relay.On(Box1_Port1);
ReefAngel.Relay.On(Box1_Port3);
ReefAngel.Relay.On(Box1_Port4);
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
InternalMemory.OverheatTemp_write(795);
}
void loop()
{
ReefAngel.SingleATO(true,Box1_Port8,180,2);
ReefAngel.StandardFan(Box1_Port6,775,785);
ReefAngel.StandardHeater(Box1_Port1,765,770);
ReefAngel.DosingPumpRepeat(Box1_Port7,0,144,2);
ReefAngel.DosingPumpRepeat(Port8,1,144,2);
if (hour() >= 10 && hour() < 20)
{
ReefAngel.StandardLights(Port1,11,1,19,0);
ReefAngel.StandardLights(Port3,11,0,19,0);
ReefAngel.StandardLights(Port4,10,0,19,59);
ReefAngel.StandardLights(Port5,8,0,11,0);
ReefAngel.PWM.SetDaylight(PWMSlope(11,0,19,0,0,20,120,0));
ReefAngel.PWM.SetActinic(PWMSlope(10,0,19,59,0,20,180,0));
}
else
{
ReefAngel.StandardLights(Port2,21,1,5,0);
ReefAngel.StandardLights(Port3,20,0,6,0);
ReefAngel.StandardLights(Port4,21,0,5,0);
ReefAngel.StandardLights(Port5,19,0,22,0);
ReefAngel.PWM.SetDaylight(PWMSlope(20,0,6,0,0,20,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(21,0,5,0,0,20,120,0));
}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1200 || ReefAngel.Params.Temp[T3_PROBE] >= 1200) {ReefAngel.Relay.On(Port7);}
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) {ReefAngel.Relay.Off(Port7);}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1300 || ReefAngel.Params.Temp[T3_PROBE] >= 1300) {ReefAngel.Relay.Off(Port1);}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1300 || ReefAngel.Params.Temp[T3_PROBE] >= 1300) {ReefAngel.Relay.Off(Port2);}
ReefAngel.ShowInterface();
ReefAngel.Portal("d0lph1n","xxxxx");
}
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

Looks good :)
Roberto.
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

I upgraded the RA 6.1 board to Plus 2.1 and I was able to upload the custom program but the LCD is blank (sometimes I see a white horizontal line but it works fine with the old board) and during upload of the memory program the compiler displays the following error:

"The following features were automatically added:
Watchdog Timer
Version Menu
===
The following features were detected:
Simple Menu
C:\Users\Alex\Documents\Arduino\libraries\RA_NokiaLCD\RA_NokiaLCD.cpp: In member function 'void RA_NokiaLCD::SendCMD(byte)':
C:\Users\Alex\Documents\Arduino\libraries\RA_NokiaLCD\RA_NokiaLCD.cpp:709: error: 'ReefAngel' was not declared in this scope"
===

It's using the latest RA libraries 1.1.0
Here is the internal memory:

#include <ReefAngel_Features.h>
#include <Globals.h>
#include <Time.h>
#include <OneWire.h>
#include <RA_NokiaLCD.h>
#include <avr/pgmspace.h>
#include <InternalEEPROM.h>
#include <Wire.h>
#include <Memory.h>

RA_NokiaLCD e;

void setup()
{
e.Init();
e.Clear(COLOR_WHITE,0,0,132,132);
e.BacklightOn();
InternalMemory.FeedingTimer_write(900);
InternalMemory.LCDTimer_write(600);
InternalMemory.HeaterTempOn_write(765);
InternalMemory.HeaterTempOff_write(770);
InternalMemory.ChillerTempOn_write(785);
InternalMemory.ChillerTempOff_write(775);
InternalMemory.OverheatTemp_write(800);
InternalMemory.IMCheck_write(0xCF06A31E);
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+20, MENU_START_ROW*3, "Memory Updated");
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+25, MENU_START_ROW*6, "You can now");
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+25, MENU_START_ROW*7, "upload your");
e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+33, MENU_START_ROW*8, "INO code");
}

void loop()
{
}
===

Thank you
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

That is an old internal memory file.
Use this instead:

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>

void setup()
{
  InternalMemory.LCDID_write(255);
  InternalMemory.FeedingTimer_write(900);
  InternalMemory.LCDTimer_write(600);
  InternalMemory.HeaterTempOn_write(765);
  InternalMemory.HeaterTempOff_write(770);
  InternalMemory.ChillerTempOn_write(785);
  InternalMemory.ChillerTempOff_write(775);
  InternalMemory.OverheatTemp_write(800);
  InternalMemory.IMCheck_write(0xCF06A31E);
  ReefAngel.Init();
  ReefAngel.LCD.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+20, MENU_START_ROW*3, "Memory Updated");
  ReefAngel.LCD.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+25, MENU_START_ROW*6, "You can now");
  ReefAngel.LCD.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+25, MENU_START_ROW*7, "upload your");
  ReefAngel.LCD.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL+33, MENU_START_ROW*8, "INO code") ;
}

void loop()
{
  wdt_reset();
}

It will also configure the board for your old screen.
Roberto.
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Thank you Roberto. It works great. I appreciate it
Image
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

For the past weeks i switched from dosing Ca & Alk to dosing Kalk + vinegar solution. Now that the Ph probe is working properly with the new RA plus board i'd like the ato sensor(s) to control the kalk + vinegar dosing pump instead of water if the ph is lower than lets say 8.1

This the current config:
ReefAngel.SingleATO(true,Box1_Port2,180,2);
ReefAngel.DosingPumpRepeat(Port8,1,120,4);

If the ph is smaller than 8.1 then ReefAngel.SingleATO(true,Port8,180,1) else ReefAngel.SingleATO(true,Box1_Port2,180,2);

Is this doable? What are the risks?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

Not sure what you are trying to do... :(
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Custom code, please help

Post by lnevo »

He wants to ato the vinegar+kalk when ph is less than 8.1 and ato ro/di otherwise
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

Ahh... I don't think it would work though.
I think the port would never shut off if it was on and ph raised above 8.1
Try like this:

Code: Select all

if (ReefAngel.Params.PH <= 810)
{
  ReefAngel.SingleATO(true,Port8,180,1);
  ReefAngel.Relay.Off(Box1_Port2);
}
else
{
  ReefAngel.SingleATO(true,Box1_Port2,180,2);
  ReefAngel.Relay.Off(Port8);
}
Roberto.
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Right, Inevo. Perfect. Roberto. Thanks. I'll give it a try asap.

Maybe I'm over complicating things. Maybe I should stay with the classic dosing method.
Image
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

It works but it needs more tweaking.

If pH <=818 & ATO ON then the ATO controls the Kalk pump but if during this process ph>818 and the ATO still on, it stops pumping kalk and it doesn' start pumping fresh water without manually resetting the ATO sensor On/OFF

This is the existing code:
if (ReefAngel.Params.PH <= 818)
{
ReefAngel.SingleATO(true,Box1_Port7,70,0);
ReefAngel.Relay.Off(Box1_Port8);
}
else
{
ReefAngel.SingleATO(true,Box1_Port8,120,0);
ReefAngel.Relay.Off(Box1_Port7);
}

I think we have to introduce another IF that checks the ATO status.

We have the following variables:
Ph <= 818
Single ATO status = On/Off
ATO pump port = Box1_Port8
Kalk pump port = Box1_Port7

If ph <= 818
then
check ATO Status
{If ATO ON then
ReefAngel.SingleATO(true,Box1_Port7,70,1); # ATO pumps kalk
ReefAngel.Relay.Off(Box1_Port8);
else
ReefAngel.Relay.On(Box1_Port7); #Kalk pump ON
ReefAngel.Relay.Off(Box1_Port8);
}
else
{
ReefAngel.SingleATO(true,Box1_Port8,120,1); # ATO pumps fresh water
ReefAngel.Relay.Off(Box1_Port7);
It needs a check ATO Status refresh at this point.
}

What do you think?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

I think it is your restriction on the single ato function.
ReefAngel.SingleATO(true,Box1_Port8,120,1);
The last 1 means it will have to wait another hour to pump again.
Try zero instead.
Roberto.
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Anyway, lets disregard this idea for now. It doesn't make too much sense in practice.

What's the safest way to dose kalk via Box1_Port7 if the ph drops below 818 but I also need a time out and a waiting period similar to the ATO function?

I built this code for now, is it ok? It will dose kalk for 20 seconds every 10 min until pH goes above 818, I hope. For my 8-9 gal of water, a 20 sec dose of kalk + vinegar+water (2g+15ml+1l) will increase the pH by 0.01-0.02

if (ReefAngel.Params.PH <= 818){ReefAngel.DosingPumpRepeat(Box1_Port7,0,10,20);}
if (ReefAngel.Params.PH >= 820){ReefAngel.Relay.Off(Box1_Port7);}
if (ReefAngel.Params.PH < 800){ReefAngel.Relay.Off(Box1_Port7);} #if it runs out of kalk or if the pH probe is damaged
Image
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

For the past 24h the dosing worked great.
Attachments
image.jpg
image.jpg (49.35 KiB) Viewed 3889 times
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Custom code, please help

Post by lnevo »

Nice! Just keep your eyes on the probe and double check it once in a while so you don't end up doing something bad :) but way to control that swing!
d0lph1n
Posts: 122
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Look what happend when it ran out of kalk + vinegar.
I left home for a couple of days and i forgot to refill the kalk+v container. When I realized why the pH was dropping I turned on an air pump to push more air into the skimmer. It helped for a while...but it was not enough.
Attachments
image.jpg
image.jpg (50.45 KiB) Viewed 3860 times
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Custom code, please help

Post by lnevo »

Thats not too bad...should see what my ph dropped to on thanksgiving with everyone over my house!
Post Reply