Modified Version Of lnevo's Code

New members questions
Post Reply
InPandaWeTrust
Posts: 11
Joined: Tue Oct 08, 2013 3:12 pm

Modified Version Of lnevo's Code

Post by InPandaWeTrust »

Hi Everybody, sort of new to RA. Have known about it for a while but havent had my tank set up for a few years and only recently got back into marines so now I'm fiddling about. Saving up cash for the RA unit at the moment, but have got an arduino mega 2560 on hand from other projects so I'm going to mess around on it, learning the code etc, while I wait on the RA unit.

As the title says, I'm going to be using a modified version of Inevo's awesome code.
Some stuff I would like to control:
200W of DIY LEDs, 5 channels with PWM control
Two Jebao WP-25s (going to control using the cable)
DC-5500 diablo return pump (using the cable as well)
3 dosing pumps (relays) - want to use Inevo's logging on these
Auto Top up (relay) (will manually fill the RO chamber when necessary)
a DIY chiller (relay triggered by temp probe)
heater
Fans for aerating the tank room. (relays)
pH sensor
Salinity maybe
I will be using a Wifi attachment as well so the alerts and the portal are on the cards.

I wonder if any of the mods would not mind moving my questions from Inevo's thread to here so that I do not clutter his thread?
InPandaWeTrust
Posts: 11
Joined: Tue Oct 08, 2013 3:12 pm

Re: Modified Version Of Inevo's Code

Post by InPandaWeTrust »

The first bit I'd like to get working is the lighting. So from the total code, I've pulled everything but the lighting related stuff.
First off, which of the includes would I need to get this part to run?

Code: Select all

// Define Custom Memory Locations
#define Mem_B_MoonSlope       100
#define Mem_B_Vacation        101
#define Mem_I_Latitude        108
#define Mem_I_Longitude       110
#define Mem_B_AcclRiseOffset  112
#define Mem_B_AcclSetOffset   113
#define Mem_B_AcclDay         114

#define Mem_B_PrintDebug      198
#define Mem_B_ResetMemory     199

void init_memory() {
  // Initialize Custom Memory Locations
  InternalMemory.write(Mem_B_MoonSlope,60);
  InternalMemory.write_int(Mem_I_Latitude,19.611544);
  InternalMemory.write_int(Mem_I_Longitude,-155.436402);
  InternalMemory.write(Mem_B_AcclRiseOffset,4);
  InternalMemory.write(Mem_B_AcclSetOffset,2);
  InternalMemory.write(Mem_B_AcclDay,0);
  InternalMemory.write(Mem_B_ResetMemory,false);
}

// define globals here
#define NUMBERS_8x16

// Define Portal Variables
#define Var_AcclDay      3

// Define Relay Ports by Name
#define WhiteLEDs          3
#define BlueLEDs           4
#define Refugium           7

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

// Custom classes
SunLocation sun;

////// Place global variable code above here

// Setup on controller startup/reset
void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
 
  ////// Place additional initialization code below here    
  if (InternalMemory.read(Mem_B_ResetMemory)) 
    init_memory();
  ////// Place additional initialization code above here
}

void loop()
{
  ReefAngel.MoonLights(Refugium);
  ReefAngel.ActinicLights(BlueLEDs);
  ReefAngel.StandardLights(WhiteLEDs); 
  
    ////// Place your custom code below here
  SetSun();               // Setup Sun rise/set lighting
  SetMoon();              // Setup Moon rise/set lighting
/*  // This part I'm not going to worry about for now if I'm not using the portal correct?
  // This should always be the last line
  ReefAngel.Portal("InPandaWeTrust");
  ReefAngel.ShowInterface();
*/
}

void SetSun() {
  // Start acclimation routine
  int acclRiseOffset=InternalMemory.read(Mem_B_AcclRiseOffset)*60;
  int acclSetOffset=InternalMemory.read(Mem_B_AcclSetOffset)*60;
  byte acclDay=InternalMemory.read(Mem_B_AcclDay);
  ReefAngel.CustomVar[Var_AcclDay]=acclDay;

  // See if we are acclimating corals and decrease the countdown each day
  static boolean acclCounterReady=false;
  if (now()%SECS_PER_DAY!=0) acclCounterReady=true;
  if (now()%SECS_PER_DAY==0 && acclCounterReady && acclDay>0) {
    acclDay--;
    acclCounterReady=false;
    InternalMemory.write(Mem_B_AcclDay,acclDay);
  } 
  // End acclimation

  sun.Init(InternalMemory.read_int(Mem_I_Latitude), InternalMemory.read_int(Mem_I_Longitude));
  sun.SetOffset(2,(acclDay*acclRiseOffset),2,(-acclDay*acclSetOffset)); // rise_hour, rise_seconds, set_hour, set_seconds
  sun.CheckAndUpdate(); // Calculate today's Sunrise / Sunset
}

void SetMoon() {
// rfi
  byte offset=InternalMemory.read(Mem_B_MoonSlope);
  
  byte startD=InternalMemory.read(Mem_B_PWMSlopeStartD);
  byte endD=InternalMemory.read(Mem_B_PWMSlopeEndD);
  byte timeD=InternalMemory.read(Mem_B_PWMSlopeDurationD);

  byte startA=InternalMemory.read(Mem_B_PWMSlopeStartA);
  byte endA=InternalMemory.read(Mem_B_PWMSlopeEndA);
  byte timeA=InternalMemory.read(Mem_B_PWMSlopeDurationA);

  static byte mp=MoonPhase();
  
  if (mp!=MoonPhase()) {
    InternalMemory.write(Mem_B_PWMSlopeEndD,mp);
    InternalMemory.write(Mem_B_PWMSlopeEndA,mp);
    mp=MoonPhase();
  }
  
  moon_init(InternalMemory.read_int(Mem_I_Latitude), InternalMemory.read_int(Mem_I_Longitude));
  
  ReefAngel.PWM.SetDaylight(PWMSlope(Moon.riseH,Moon.riseM,Moon.setH,Moon.setM, startD,endD,timeD,0));
  ReefAngel.PWM.SetActinic(PWMSlope(Moon.riseH,Moon.riseM,Moon.setH,Moon.setM, startA,endA,timeA,0));
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Modified Version Of Inevo's Code

Post by lnevo »

The includes should be copied verbatim. Make sure you have the same includes copied over.

As far as copying my code, I highly recommned starting with a wizard generated code... it's a lot easier bringing in pieces of my code than trying to adapt it in place...

Also need more information like what are you trying to do with the lighting. I have a few different lights as do you...

Most of my code is broken into functions for each specific task.. ie. SetSun(); SetMoon(); But you've defined your Moonlights and Standard / Actinic Lights already.

Also you've commented out the portal function which gives you the wifi functionality which you will need since all my code works with the memory based variables.

And finally none of this will work if you don't run ReefAngel.ShowInterface(); That's the command that actually does everything after it's been set in the previous functions. Without it your INO will not do anything.
InPandaWeTrust
Posts: 11
Joined: Tue Oct 08, 2013 3:12 pm

Re: Modified Version Of Inevo's Code

Post by InPandaWeTrust »

As far as the moonlights etc, I just copied that straight from your code. I haven't actually edited anything on this version save for commenting out that one part and the GPS co-ordinates.

Will perhaps try with a wizard generated code if I dont come right here.
What I want to do with the lighting :
Basically just have it do sunrise/set as per my location(will offset it by a few hours to make it start later in the day though) and the idea of acclimatising is great too so I'd like that to work. I have 5 channels of LEDs, 2 blue, 2 white and 1 UV. I would like to be able to control the different channels separately at some point, perhaps dim one side of the tank more than the other in acclimatising or something. Maybe set the PWM % of each channel/colour

I dont have a wifi module yet, only got an ethernet module which I'm not sure how to work with in terms of the RA code.

Ok so far, I must uncomment the things you mentioned. Easy enough. If I put all the includes into the INO and try verify it says stuff like this for example :
''libraries\ReefAngel/ReefAngel.h:238: error: 'RFClass' does not name a type''

Does that mean I should go into ReefAngel.h and take out the portions not relating to my current lighting portion?
InPandaWeTrust
Posts: 11
Joined: Tue Oct 08, 2013 3:12 pm

Re: Modified Version Of Inevo's Code

Post by InPandaWeTrust »

Maybe I will hard code some of the variables in to start. Avoid the memory locations
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Modified Version Of Inevo's Code

Post by lnevo »

Something is wrong with your installation.... I recommend uninstall / reinstall. Make sure to remove the Documents\Arduino folder.

We need to get the basics down first. Also I don't recommend using my code at all if you don't have a wifi module or it's not setup yet. The reason being all my settings are made to not be hard coded and to use memory which you cannot manipulate without network connectivity.

You can still use the SunLocation class though, but let's get you started and things compiling properly first....

You should not have to edit any of the library files...
InPandaWeTrust
Posts: 11
Joined: Tue Oct 08, 2013 3:12 pm

Re: Modified Version Of lnevo's Code

Post by InPandaWeTrust »

Finally have some time to tackle this and I've found the main error that was ruining everything. My sketch folder is in my documents (default via arduino) so I changed that to the install folder in Program files so that all the code and my sketches are in the same place. Suddenly no compiling errors.

As far as going with the basics for now, I'm interested in the pin allocations for Port 1, 2, 3 etc. What are the board pin numbers on things like the actinic/daylight channel? Its all fine and dandy for when the code is running on a RA unit, but for now what pins will be used on my arduino board? I have no idea where its going to send the signal to test if the code is working properly. Was going to start the code on the basic wave patterns, to get something going in the mean time.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Modified Version Of lnevo's Code

Post by lnevo »

Hehe had a feeling it was you...

Make sure you change the username in the Portal function...got a bunch of random alerts last night from a strange IP :)

Need to modify the post with a bogus username so that doesn't happen again :)
InPandaWeTrust
Posts: 11
Joined: Tue Oct 08, 2013 3:12 pm

Re: Modified Version Of lnevo's Code

Post by InPandaWeTrust »

That wasn't me :) I know about changing the username in the portal function and I haven't even uploaded your code yet ;) I'm still trying to go section by section and take out all the stuff that will work for me. I made a cable for my jebao pumps (with a low pass filter) and have written a small piece of code based on the fading example to fade between right and left.

Need to figure out the pin situation before I can try using your code otherwise i wont know which pin the signals are going to
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Modified Version Of lnevo's Code

Post by rimai »

lnevo wrote:Hehe had a feeling it was you...

Make sure you change the username in the Portal function...got a bunch of random alerts last night from a strange IP :)

Need to modify the post with a bogus username so that doesn't happen again :)
Use the portal key.
That's what it is for.
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Modified Version Of lnevo's Code

Post by lnevo »

Yea..need to do that too...but would still need to modify before posting.
Post Reply