Reef Angel Library Tutorial Code - Start from here

144 views
Skip to first unread message

Roberto Imai

unread,
Jun 18, 2010, 9:46:00 PM6/18/10
to reef...@googlegroups.com
Hello Everyone,
 
Due to much interest on a tutorial type of code/document, I have created the attached code to allow everyone to have a starting point on programming their units with their specific requirements.
The code has a simple menu system and also has most of the standard functions to date, so you can copy and paste and create your own code.
I have placed some comments throughout the code to try to explain each block, but if you don't understand or think it needs a little more details, please let me know.
I hope this will give everyone a very good and solid starting point to customize your Reef Angel Controller.
Please let me know if this was useful or if it needs any other extra information in there or if something did not work.
Happy coding :)
 
Sincerely,
Roberto Imai
 
ReefAngelTutorial.pde
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

BillyB

unread,
Jun 19, 2010, 12:24:29 PM6/19/10
to Reef Angel Controller
Awesome Roberto!!! I was going to ask for something like this, but
figured I asked too much already. You are the man.... Now get back to
getting our wireless working!!! :)
>  ReefAngelTutorial.pde
> 16KViewDownload

BillyB

unread,
Jun 19, 2010, 1:41:22 PM6/19/10
to Reef Angel Controller
I just went through the tutorial code, and it helped me immensely!!
But a few things have me stumped.

1. In the area it checks if feeding mode is done, Timer(0), why does
it only turn sump pump on, and not the wavemakers also? Is this part
of the gui function or the timer library?

2. Where you turn lights off and on (except the PWM for leds), you use
a ReefAngel.Relay.RelayMaskOn=B11111111 for example. Can you explain
what the different values are and where we can see this part of the
code? I am interested in this because I would like to set 2 times that
the lights ( or at least the MH's) turn on and off each day, so I
would need to create another function for this I assume. Maybe a
ReefAngel.MHLightsMorn and a ReefAngel.MHLightsEve?

And this is just a typo, but I noticed the comments for the feeding
timer of turning the sump on says off (ReefAngel.Relay.On(Sump); //
Turn Sump off).

Thanks.

Roberto Imai

unread,
Jun 19, 2010, 7:09:47 PM6/19/10
to reef...@googlegroups.com
1. The wavemakers are on a different timer. They use Timer[1] and Timer[2] and only work when SelectedMenu=255, which is when you are at the default screen. So, whenever it comes the time for them to come on, they will.
2. The value of RelayMaskOn is used to do an OR compare with RelayData. I use the value in binary format, hence the B in the beginning of the number. It is a binary representation of the relays that need to be overridden to always on. The default value is B00000000, which means no relay is overridden. If you set B00000110, you are overriding the relay 2 and 3 to always on and according to the relay definition on the beginning of the code, those relays are: Actinic and MHLight.
Was that clear or confusing?
Roberto

BillyB

unread,
Jun 20, 2010, 12:06:34 PM6/20/10
to Reef Angel Controller
1. Makes sense. I was unaware that the screen would stay at the
feeding screen during the timer for feeding.

2. Still a little confused. I understand the bits to relay part and I
understand the first 2 uses in the code for lights override off and
on. But the last 2 uses still dont make sense to me.

--------------------------------------------------------------------------
If the controller is on "Clear Overheat", the value of SelectedMenu
will be 5. This is based according to the menu created above
So, we check to see if the value is 5 and if it is, it'll clear the
Overheat

----------------------------------------------------------------------------------------------------------------------------------------------------------
*/
if (ReefAngel.SelectedMenu==5) //Clear Overheat Selected
{
ReefAngel.LED.Off();
ReefAngel.Relay.RelayMaskOn=B11111111; //Override MHlight Auto;
ReefAngel.ReturnMenuFunction(); // Return from menu function;
------------------------------------------------------------------

Here it seems you are turning everything on. Not sure why.

And here:

-----------------------------------------------------------------------

If Temp2 sensor reachs 150.0F, it will consider an overheat and will
turn the lights off

----------------------------------------------------------------------------------------------------------------------------------------------------------
*/
if (ReefAngel.Params.Temp2>=1500) // It Temp2 >= 150.0F
{
ReefAngel.LED.On();
ReefAngel.Relay.RelayMaskOn=B11111011; //Override MHlight Off;
}

------------------------------------------

Seems like if temp is over 150, everything will end up being ON except
MH?


Roberto Imai

unread,
Jun 20, 2010, 1:06:20 PM6/20/10
to reef...@googlegroups.com
Hi Jamie,

I think what you missing is this piece of information:
The are 3 byte variables for relay calculation. They are RelayData, RelayMaskOn and RelayMaskOff.
The value sent to the relay box is a calculation of these 3 values:
byte TempRelay=RelayData;
TempRelay&=RelayMaskOff;
TempRelay|=RelayMaskOn;
For more information on bitwise comparisons: http://arduino.cc/en/Reference/BitwiseAnd
I'm going to use binary values on all values, just to make it easy to understand, but you can look at this to understand more about how to convert them: http://arduino.cc/en/Reference/IntegerConstants
Relay 1 is the least significant bit.

RelayData: byte value that represents which relays should be on or off.
Examples:
ReefAngel.Relay.RelayData=B00101011;
In this line, you are telling the controller to turn on relays 1,2,4,6 and turn off relays 3,5,7,8
ReefAngel.Relay.RelayData=B11100000;
In this line, you are telling the controller to turn on relays 6,7,8 and turn off relays 1,2,3,4,5

RelayMaskOn: byte value that represents which relays should be overridden to always on. This mask is going to be compared to RelayData with OR comparison.
Examples:
ReefAngel.Relay.RelayMaskOn=B00000000;
In this line, you are telling the controller to not override any relay to always on. They are all going to be in auto.
ReefAngel.Relay.RelayMaskOn=B00001000;
In this line, you are telling the controller to override relay 4 to always on.
ReefAngel.Relay.RelayMaskOn=B01100001;
In this line, you are telling the controller to override relays 1,6,7 to always on.

RelayMaskOff: byte value that represents which relays should be overridden to always off. This mask is going to be compared to RelayData with AND comparison.
Examples:
ReefAngel.Relay.RelayMaskOff=B11111111;
In this line, you are telling the controller to not override any relay to always off. They are all going to be in auto.
ReefAngel.Relay.RelayMaskOff=B11110111;
In this line, you are telling the controller to override relay 4 to always off.
ReefAngel.Relay.RelayMaskOff=B10011110;
In this line, you are telling the controller to override relays 1,6,7 to always off.

After reading this email, I noticed that the mask for turning the MH off is wrong. I'll double check the code when I get home.
It should be:
ReefAngel.Relay.RelayMaskOff=B11111111; //Override MHlight Auto;
ReefAngel.Relay.RelayMaskOff=B11111011; //Override MHlight Off;

Sincerely,
Roberto.

BillyB

unread,
Jun 20, 2010, 2:48:36 PM6/20/10
to Reef Angel Controller
Cool, makes total sense now. I must have a good grasp because after
looking at the ReefAngel.cpp code, I was going to ask you if you meant
RelayMaskOff on those, but then cut it out of my previous response :).
And thanks for the better clarification above, really helped also.
This seems alot like subnet masking, which I have branded in my brain
from studying for my CCNA. Figured after 10+ years in IT and my
company going away soon, gotta beef up my resume!!!

BillyB

unread,
Jun 20, 2010, 2:52:42 PM6/20/10
to Reef Angel Controller
Btw, did you have experience in C++ or PLC programming before tackling
this project? You have done a great job!

Reply all
Reply to author
Forward
0 new messages