First time coder - Please help :)

Do you have a question on how to do something.
Ask in here.
Post Reply
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

First time coder - Please help :)

Post by Poiromaniax »

Hey guys,

so its my first week with RA, and so far im loving it.
Im just struggling to get to grips with the programming stuff (I am technical, but suck at programming - I just space out, lol)

I need some help and understanding here:

1) Where do i specify that i am using moonlights? I tried to copy and paste some code (from here http://forum.reefangel.com/viewtopic.php?f=12&t=1160) and it gave me an error along the lines of "Moonphase is not defined"
2) How do i change vortech mode from the webserver/portal?

3) Please look over my code and tell me if it looks wrong to you :) (I copied it from here: http://forum.reefangel.com/viewtopic.ph ... eature+hog and modified a few lines, dunno if it will work)

I pretty much need to control my Vortech mode (from iphone or wifi or portal, matters not) be able to use feed and waterchange modes (works everywhere except for from the headunit itself) and set moonlights.

Heaters etc should be pretty straightforward?

My code:

Code: Select all

#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <avr/pgmspace.h>
#include <ReefAngel_Colors.h>
#include <ReefAngel_CustomColors.h>
#include <ReefAngel_Salinity.h>
#include <ReefAngel_RF.h>
#include <ReefAngel.h>  


//*********************************************************************************************************************************
//Global Variables
byte vtechmode;
byte DayAge;
byte ThisPhase;
int JulianDate(int,int,int);
double MoonAge(int,int,int);
byte MoonState();
boolean bFeeding=false;
byte SeasonsVar[]={
  0,0,0,0,0,0,0,0};
//End Global Variables
//*********************************************************************************************************************************

//*********************************************************************************************************************************
//Define Relay Ports
#define MH                  1
#define MH                  2
#define Heater 250          3
#define Heater 300          4
#define Tunze               5
#define Vortech             6
#define Skimmer             7
#define Return              8
//*********************************************************************************************************************************

//*********************************************************************************************************************************
//Custom Main, Graph & Menu
void DrawCustomMain()
{
  Wire.requestFrom(8,8);
  for (int a=0;a<8;a++)
  {
    if (Wire.available()) SeasonsVar[a]=Wire.receive();
  }

  byte x = 6;
  byte y = 2;
  byte t;
  char text[7];

  ReefAngel.LCD.DrawDate(6, 2);
  ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
  pingSerial();

  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 6, 90, "--------------------");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 6, 126, "--------------------");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 2, 93, "|");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 2, 103, "|");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 2, 113, "|");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 2, 123, "|");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 126, 93, "|");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 126, 103, "|");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 126, 113, "|");
  ReefAngel.LCD.DrawText(COLOR_TOMATO,255, 126, 123, "|");


  ReefAngel.LCD.DrawText(0,255,18,12,"Vortech MP40W");
  ReefAngel.LCD.Clear(255, 1, 19, 128, 29);
  if (vtechmode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,35,21,"Constant");
  else if(vtechmode == 1) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,42,21,"Lagoon");
  else if (vtechmode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,25,21,"Reef Crest");
  else if (vtechmode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,22,21,"Short Pulse");
  else if (vtechmode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,25,21,"Long Pulse");
  else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,45,21,"Night");

  ReefAngel.LCD.DrawText(0,255,10,30,"Display");
  ConvertNumToString(text, ReefAngel.Params.Temp3, 10);
  ReefAngel.LCD.DrawLargeText(COLOR_INDIANRED, 255, 10, 40, text, Num8x8);
  pingSerial();

  ReefAngel.LCD.DrawText(0,255,100,30,"pH");
  ConvertNumToString(text, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.DrawLargeText(COLOR_PLUM, 255, 85, 40, text, Num8x8);
  pingSerial();

  ReefAngel.LCD.DrawText(0,255,43,48,"Salinity");
  ConvertNumToString(text, ReefAngel.Params.Salinity, 100);
  ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN, 255, 49, 58, text, Num8x8);
  pingSerial();

  pingSerial();
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 77, TempRelay);

 (ReefAngel.PWM.GetActinicValue() > 0)
  {
    ReefAngel.LCD.DrawText(0,255,8,97,"Moon");
    DayAge = MoonAge(day(), month(), year());
    MoonState(DayAge);
    char* ThisPhaseLabel[]={
      "New","Waxing Crescent","First Quarter","Waxing Gibbous","Full","Waning Gibbous","Last Quarter","Waning Crescent"            };
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,ThisPhaseLabel[ThisPhase]);
  }
void DrawCustomGraph()
{
}

//End Custom
//*********************************************************************************************************************************

void setup()
{
  ReefAngel.Init(); 
  ReefAngel.PHMin=502;
  ReefAngel.PHMax=827;

  ReefAngel.FeedingModePorts = B10100000;
  ReefAngel.WaterChangePorts = B10101000;
  ReefAngel.OverheatShutoffPorts = B01000000;
  ReefAngel.LightsOnPorts = B00000000;

  // Ports that are always on
  ReefAngel.Relay.On(PowerCenter);
  ReefAngel.Relay.On(Return);
  ReefAngel.Relay.On(Reactors);
  ReefAngel.Relay.On(LEDPSU);
  ReefAngel.Relay.On(Refugium);
  ReefAngel.Relay.On(Salinitypsu);
}

void loop()
{

  //Heater on&off
  ReefAngel.StandardHeater(Heater,780,792);

  //Delay Skimmer
  ReefAngel.Relay.DelayedOn(Skimmer, 5);
  if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
 
      }
  if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[4].IsTriggered())
  {
    ReefAngel.RF.UseMemory=true;
    vtechmode = InternalMemory.RFMode_read();
  }
  if (hour() <= 6 && hour() >= 22)
  {
      ReefAngel.PWM.SetActinic(MoonPhase());
        }
  else 
    {
      ReefAngel.PWM.SetActinic(0);
    }

  ReefAngel.ShowInterface();
}

int JulianDate(int d, int m, int y)
{ 
  int mm, yy;
  int k1, k2, k3;
  int j;

  yy = y - (int)((12 - m) / 10);
  mm = m + 9;
  if (mm >= 12)
  {
    mm = mm - 12;
  }
  k1 = (int)(365.25 * (yy + 4712));
  k2 = (int)(30.6001 * mm + 0.5);
  k3 = (int)((int)((yy / 100) + 49) * 0.75) - 38;
  // 'j' for dates in Julian calendar:
  j = k1 + k2 + d + 59;
  if (j > 2299160)
  {
    // For Gregorian calendar:
    j = j - k3; // 'j' is the Julian date at 12h UT (Universal Time)
  }
  return j;
}

double MoonAge(int d, int m, int y)
{ 
  int j = JulianDate(d, m, y);
  //Calculate the approximate phase of the moon
  int ip = (j + 4.867) / 29.53059;
  ip = ip - abs(ip); 
  //After several trials I've seen to add the following lines, 
  //which gave the result was not bad 
  if(ip < 0.5)
    int ag = ip * 29.53059 + 29.53059 / 2;
  else
    int ag = ip * 29.53059 - 29.53059 / 2;
  // Moon's age in days
  byte ag = abs(ag) + 1;
  return ag;
}

byte MoonState(byte D)
{
  switch(D){
  case 1: 
    0, 29;
    ThisPhase = 0;
  case 2: 
    1, 2, 3, 4, 5, 6;
    ThisPhase = 1;
  case 3: 
    7;
    ThisPhase = 2;
  case 4: 
    8, 9, 10, 11, 12, 13;
    ThisPhase = 3;
  case 5: 
    14;
    ThisPhase = 4;
  case 6: 
    15, 16, 17, 18, 19, 20, 21;
    ThisPhase = 5;
  case 7: 
    22;
    ThisPhase = 6;
  case 8: 
    23, 24, 25, 26, 27, 28;
    ThisPhase = 7;
  default: 
    return 0;
  }
}
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: First time coder - Please help :)

Post by binder »

What version of the libraries to you have installed? Your code looks like it is referring to the 0.8.5.X libraries. This is not the most recent version. The current version is 0.9.6. Some of the functionality you are trying to use was not included until the 0.9.X version, so that can explain why you were getting problems.

For the vortech control, check out this thread: http://forum.reefangel.com/viewtopic.ph ... it=vortech

Now, on to your code. You cannot do this:

Code: Select all

  // Ports that are always on
  ReefAngel.Relay.On(PowerCenter);
  ReefAngel.Relay.On(Return);
  ReefAngel.Relay.On(Reactors);
  ReefAngel.Relay.On(LEDPSU);
  ReefAngel.Relay.On(Refugium);
  ReefAngel.Relay.On(Salinitypsu);
because the "ports" are not defined based on your code. So those will give you errors compiling. If you want to use the names, then you will have to use these names that you specified already:

Code: Select all

//Define Relay Ports
#define MH                  1
#define MH                  2
#define Heater 250          3
#define Heater 300          4
#define Tunze               5
#define Vortech             6
#define Skimmer             7
#define Return              8
Otherwise, you will want to use Port1, Port2, ... Port8 instead.

Hmmm....there are several things that are not right with your code. What I would suggest to get you started and more familiar is to start using RAGen. That way you can get a grasp on the basics of the code first. Once you get a grasp on the basics then you can move onward to the more complex stuff. I suggest you get your base system running first, then we can add in the custom main screen. Just about everything you are wanting to do (aside from the custom main screen, rf control and the moonlights) can be done inside RAGen with ease.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

First time coder - Please help :)

Post by Poiromaniax »

Thanks binder,

I am using dev libraries 0.9.6.
I started using RAGen for my basic code, it does seem to work (except when I Push feed mode on the controller itself, it doesn't put the vortech into feed?)

The above code isn't the one that is actually running on my RA, rather it's just some bits and pieces from threads on the forum. Probably better to build on my working code?

Lastly, I am pretty lost with the whole custom screens, do I still have to edit the customcolors file? Or was that only for an old version?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: First time coder - Please help :)

Post by rimai »

Do you also have the PWM expansion module?
There are some bits of code related to PWM module.
For your vortech, did you go through syncing the vortechs to RA following the instructions on the manual?
Roberto.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

Hey Roberto,

I dont have the pwm module. But i think im gonna make a basic code with RAGen and try add custom code from there after defining all my features, problem is i have no clue how to code the moonlights.

I went through the RF module setup, got my vortech syncing and everything, it just doesnt work from the controller itself - only through the portal and app?
Image
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

Ok,

I have done some fiddling - and now this is my code - Feeding mode is working through the controller too now :D

Code: Select all

// Autogenerated file by RAGen (v1.2.2.171), (05/08/2012 21:44)
// RA_050812_2144.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define DisplayImages
#define DateTimeSetup
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define SIMPLE_MENU
#define CUSTOM_MAIN
#define RFEXPANSION
*/


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

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


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

void DrawCustomMain()
{
  // the graph is drawn/updated when we exit the main menu &
  // when the parameters are saved
  ReefAngel.LCD.DrawDate(6, 122);
  pingSerial();
#if defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params);
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,15,93,"RF Mode:");
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,70,93,ReefAngel.RF.Mode);
  pingSerial();
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 103, TempRelay);
}

void DrawCustomGraph()
{
  ReefAngel.LCD.DrawGraph(5, 5);
}


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.SetTemperatureUnit(1);  // set to Celsius Temperature

    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port6Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port5Bit | Port6Bit | Port7Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;

    // Ports that are always on
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
    ReefAngel.Relay.On(Port7);
    ReefAngel.Relay.On(Port8);
    ////// Place additional initialization code below here
    

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

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.MHLights(Port1);
    ReefAngel.MHLights(Port2);
    ReefAngel.StandardHeater(Port3);
    ReefAngel.StandardHeater(Port4);
    ////// Place your custom code below here
    

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

    // This should always be the last line
    ReefAngel.ShowInterface();
}
and my internal memory:

Code: Select all

// Autogenerated file by RAGen (v1.2.2.171), (05/08/2012 20:21)
// Memory_050812_2021.ino
//
// This file sets the default values to 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.MHOnHour_write(12);
    InternalMemory.MHOnMinute_write(0);
    InternalMemory.MHOffHour_write(22);
    InternalMemory.MHOffMinute_write(0);
    InternalMemory.StdLightsOnHour_write(8);
    InternalMemory.StdLightsOnMinute_write(0);
    InternalMemory.StdLightsOffHour_write(15);
    InternalMemory.StdLightsOffMinute_write(0);
    InternalMemory.WM1Timer_write(200);
    InternalMemory.WM2Timer_write(354);
    InternalMemory.DP1Timer_write(10);
    InternalMemory.DP2Timer_write(10);
    InternalMemory.FeedingTimer_write(900);
    InternalMemory.LCDTimer_write(600);
    InternalMemory.OverheatTemp_write(655);
    InternalMemory.LEDPWMDaylight_write(50);
    InternalMemory.LEDPWMActinic_write(90);
    InternalMemory.HeaterTempOn_write(250);
    InternalMemory.HeaterTempOff_write(260);
    InternalMemory.ChillerTempOn_write(272);
    InternalMemory.ChillerTempOff_write(258);
    InternalMemory.ATOTimeout_write(60);
    InternalMemory.PHMax_write(840);
    InternalMemory.PHMin_write(550);
    InternalMemory.MHDelay_write(5);
    InternalMemory.DP1OnHour_write(20);
    InternalMemory.DP1OnMinute_write(0);
    InternalMemory.DP2OnHour_write(22);
    InternalMemory.DP2OnMinute_write(30);
    InternalMemory.ATOHourInterval_write(0);
    InternalMemory.ATOHighHourInterval_write(0);
    InternalMemory.ATOHighTimeout_write(60);
    InternalMemory.DP1RepeatInterval_write(0);
    InternalMemory.DP2RepeatInterval_write(0);
    InternalMemory.SalMax_write(2550);
    InternalMemory.PWMSlopeStartD_write(15);
    InternalMemory.PWMSlopeEndD_write(100);
    InternalMemory.PWMSlopeDurationD_write(60);
    InternalMemory.PWMSlopeStartA_write(15);
    InternalMemory.PWMSlopeEndA_write(100);
    InternalMemory.PWMSlopeDurationA_write(60);
    InternalMemory.RFMode_write(0);
    InternalMemory.RFSpeed_write(100);
    InternalMemory.RFDuration_write(10);
    InternalMemory.PWMSlopeStart0_write(15);
    InternalMemory.PWMSlopeEnd0_write(100);
    InternalMemory.PWMSlopeDuration0_write(60);
    InternalMemory.PWMSlopeStart1_write(15);
    InternalMemory.PWMSlopeEnd1_write(100);
    InternalMemory.PWMSlopeDuration1_write(60);
    InternalMemory.PWMSlopeStart2_write(15);
    InternalMemory.PWMSlopeEnd2_write(100);
    InternalMemory.PWMSlopeDuration2_write(60);
    InternalMemory.PWMSlopeStart3_write(15);
    InternalMemory.PWMSlopeEnd3_write(100);
    InternalMemory.PWMSlopeDuration3_write(60);
    InternalMemory.PWMSlopeStart4_write(15);
    InternalMemory.PWMSlopeEnd4_write(100);
    InternalMemory.PWMSlopeDuration4_write(60);
    InternalMemory.PWMSlopeStart5_write(15);
    InternalMemory.PWMSlopeEnd5_write(100);
    InternalMemory.PWMSlopeDuration5_write(60);
    InternalMemory.IMCheck_write(0x5241494D);
}

void loop()
{
    // display success screen
    e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*2, "Internal Memory Set");
    e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*4, "Now load your");
    e.DrawText(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*5, "   RA code file");
    delay(5000);
}
One thing that doesnt happen is my main screen doesnt show which mode my vortech is in? just says "RF Mode: 0"

I copied the code from the CustomMainScreen_RFExpansion so I dunno if theres something missing that im not seeing?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: First time coder - Please help :)

Post by rimai »

Cool.
0 means it is on constant mode.
These are the modes:
#define Constant 0
#define Random1 1 // Lagoonal
#define Random2 2 // Reef Crest
#define ShortWave 3
#define LongWave 4
#define Smart_NTM 5 // Nutrient Transport Mode
#define Smart_TSM 6 // Tidal Swell Mode
You can change the mode on your code by using:

Code: Select all

      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,60,6);
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: First time coder - Please help :)

Post by rimai »

For the moonlights, simply add:

Code: Select all

    ReefAngel.PWM.SetActinic(MoonPhase());
    ReefAngel.PWM.SetDaylight(MoonPhase());
Roberto.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

First time coder - Please help :)

Post by Poiromaniax »

Awesome, forgive me for being stupid, but what are the numbers after vortech mode? (60,6) is that speed an duration?

I want mine on 100% reef crest unless feeding and would also like to display vortehc mode in text on my main screen, or a second screen. As long as i can change mode from the app or portal or wifi interface i am ok with that

If I want to set the moonlights according to current moon phase?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: First time coder - Please help :)

Post by rimai »

Someone else had the modes in text somewhere here in the forums.
http://forum.reefangel.com/viewtopic.php?f=11&t=535
If you want to change the modes remotely, you don't need anything in your code then.
In your code, replace this:

Code: Select all

  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,70,93,ReefAngel.RF.Mode);
With this:

Code: Select all

  byte vtechmode = InternalMemory.RFMode_read();
  if (vtechmode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,DefaultBGColor,70,93,"Constant");
  else if(vtechmode == 1) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,70,93,"Lagoon");
  else if (vtechmode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,70,93,"Reef Crest");
  else if (vtechmode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,DefaultBGColor,70,93,"Short Pulse");
  else if (vtechmode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,DefaultBGColor,70,93,"Long Pulse");
  else if (vtechmode == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,70,93,"Nutrient Trnsp.");
  else if (vtechmode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,70,93,"Tidal Swell");
  else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,DefaultBGColor,70,93,"Night");
Also, the RF module will light up with the same color patterns as the Vortech driver.
Reef Crest is a yellow tone color.

The code I posted above for the moonlights is going to set them to the current moon phase :)
Roberto.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

Thanks Roberto,

I am getting a "sketch too big error" when adding the moonlight code?

and a "Class_NokiaLCD has no member named "DrawLargeText" when adding the vortech code?

*EDIT* Im no longer getting DrawLargeText error after adding "Font8x8" and "Font8x16"

HOWEVER, now i am just stuck with "Sketch too big error"!?!?! its driving me slightly nuts
Image
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

This is the code i am getting "Sketch too big error" - only thing i have changed since ragen compiled is added:

Code: Select all

 ReefAngel.PWM.SetActinic(MoonPhase());
    ReefAngel.PWM.SetDaylight(MoonPhase());
I am confused here

Code: Select all

// Autogenerated file by RAGen (v1.2.2.171), (05/09/2012 18:47)
// RA_050912_1847.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define DateTimeSetup
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define SIMPLE_MENU
#define CUSTOM_MAIN
#define RFEXPANSION
#define FONT_8x8
#define FONT_8x16
*/


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

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


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

void DrawCustomMain()
{
    // the graph is drawn/updated when we exit the main menu &
    // when the parameters are saved
    ReefAngel.LCD.DrawDate(6, 112);
    pingSerial();
#if defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params,
    ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params);
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
    pingSerial();
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

void DrawCustomGraph()
{
    ReefAngel.LCD.DrawGraph(5, 5);
}


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.SetTemperatureUnit(1);  // set to Celsius Temperature

    // Ports that are always on
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
    ReefAngel.Relay.On(Port7);
    ReefAngel.Relay.On(Port8);
    ////// Place additional initialization code below here
    

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

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.MHLights(Port1);
    ReefAngel.MHLights(Port2);
    ReefAngel.StandardHeater(Port3);
    ReefAngel.StandardHeater(Port4);
    ReefAngel.PWM.SetActinic(MoonPhase());
    ReefAngel.PWM.SetDaylight(MoonPhase());
    ////// Place your custom code below here
    

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

    // This should always be the last line
    ReefAngel.ShowInterface();
}
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: First time coder - Please help :)

Post by binder »

First thing, remove the DateTimeSetup. That's a big feature hog there. You've got wifi so you can change the date/time remotely.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

Thanks binder,

Got the moonlights uploaded - will remove the datetime and see if i can get the vortech menu too :)
Image
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

Ok,

I can upload the vortech menu too, but now obviously the spacing is all off. Currently it shows the mode underneath the relay ports. (i.e i see the relay ports and they are directly ontop of "Vortech mode" so i only see the last 3 letters of the current vortech mode)

I am unable to find where to change vortech mode - mine is currently set on constant and i wanna change to Reef Crest, but cant see where i would do that? This is the main feature that i need!

If someone can help modify my code so that i can see everything properly on my main screen, that will be great :D

I dont need the graph, cause i can see that through the portal/interface. Just vortech mode, current moon state (e.g waxing, gibbous), ph, temp (only Temp 1) and of course relays :) not too much to ask :P

I have this code for moon phases, but cant just paste it in as it wont fit nicely

Code: Select all

ReefAngel.LCD.DrawText(0,255,8,97,"Moon");
  DayAge = MoonAge(day(), month(), year());
  MoonState(DayAge);
  if (ThisPhase == 0) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"New");
  else if (ThisPhase == 1) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"Waxing Crescent");
  else if (ThisPhase == 2) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"First Quarter");
  else if (ThisPhase == 3) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"Waxing Gibbous");
  else if (ThisPhase == 4) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"Full");
  else if (ThisPhase == 5) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"Waning Gibbous");
  else if (ThisPhase == 6) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"Last Quarter");
  else if (ThisPhase == 7) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,97,"Waning Crescent");
and here is my current code:

Code: Select all

// Autogenerated file by RAGen (v1.2.2.171), (05/09/2012 19:57)
// RA_050912_1957.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define SIMPLE_MENU
#define CUSTOM_MAIN
#define RFEXPANSION
#define FONT_8x8
*/


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

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


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

void DrawCustomMain()
{
    // the graph is drawn/updated when we exit the main menu &
    // when the parameters are saved
    ReefAngel.LCD.DrawDate(6, 112);
    pingSerial();
#if defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params,
    ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params);
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
    pingSerial();
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,15,93,"RF Mode:");
    byte vtechmode = InternalMemory.RFMode_read();
  if (vtechmode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,DefaultBGColor,70,93,"Constant");
  else if(vtechmode == 1) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,70,93,"Lagoon");
  else if (vtechmode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,70,93,"Reef Crest");
  else if (vtechmode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,DefaultBGColor,70,93,"Short Pulse");
  else if (vtechmode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,DefaultBGColor,70,93,"Long Pulse");
  else if (vtechmode == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,70,93,"Nutrient Trnsp.");
  else if (vtechmode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,70,93,"Tidal Swell");
  else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,DefaultBGColor,70,93,"Night");
    pingSerial();
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

void DrawCustomGraph()
{
    ReefAngel.LCD.DrawGraph(5, 5);
}


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.SetTemperatureUnit(1);  // set to Celsius Temperature

    // Ports that are always on
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
    ReefAngel.Relay.On(Port7);
    ReefAngel.Relay.On(Port8);
    ////// Place additional initialization code below here
    

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

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.MHLights(Port1);
    ReefAngel.MHLights(Port2);
    ReefAngel.StandardHeater(Port3);
    ReefAngel.StandardHeater(Port4);
    ReefAngel.PWM.SetActinic(MoonPhase());
    ReefAngel.PWM.SetDaylight(MoonPhase());
    ////// Place your custom code below here
    

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

    // This should always be the last line
    ReefAngel.ShowInterface();
}
Thanks kindly :)
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: First time coder - Please help :)

Post by binder »

Real quick. To change the vortech mode, you have 4 options.
1. Use the Android App. Under Memory menu, choose RF Mode under the location.
2. Use the iPhone App. Custom memory location of 855.
3. Use the java status app. Memory location of 855.
4. Manually with the URL (the same way the apps do it). http://YOURIP:2000/mb855,VALUE
Like it was mentioned earlier: http://forum.reefangel.com/viewtopic.ph ... it=vortech

The value should be set to 2 for reefcrest. So store 2 in memory location 855.
The manual command for it is this: http://YOURIP:2000/mb855,2

That should take care of that for you.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

First time coder - Please help :)

Post by Poiromaniax »

binder wrote:Real quick. To change the vortech mode, you have 4 options.
1. Use the Android App. Under Memory menu, choose RF Mode under the location.
2. Use the iPhone App. Custom memory location of 855.
3. Use the java status app. Memory location of 855.
4. Manually with the URL (the same way the apps do it). http://YOURIP:2000/mb855,VALUE
Like it was mentioned earlier: http://forum.reefangel.com/viewtopic.ph ... it=vortech

The value should be set to 2 for reefcrest. So store 2 in memory location 855.
The manual command for it is this: http://YOURIP:2000/mb855,2

That should take care of that for you.
Thanks again! For now I have set it with RAGen. I tried to change it via the iPhone app, but it did not reflect the changes on my controller? Maybe it's a bug, I tried to change it to each mode in turn and it still didn't want to.

In future I will use the manual command or java app :)
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: First time coder - Please help :)

Post by binder »

Here's a quick n dirty way to get most of the information you want on the screen. It's got everything but the moonphase.

Code: Select all

// vortech mode, moon state, ph, temp, relays

#define RFRow 40
#define RFCol 50
void DrawCustomMain()
{
    // the graph is drawn/updated when we exit the main menu &
    // when the parameters are saved
    ReefAngel.LCD.DrawDate(6, 112);
    pingSerial();

    ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T1_PROBE], T1TempColor, 6, MENU_START_ROW);
    ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, PHColor, 6, MENU_START_ROW*2);

  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,6,RFRow,"RF Mode:");
    byte vtechmode = InternalMemory.RFMode_read();
  if (vtechmode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,DefaultBGColor,RFCol,RFRow,"Constant   ");
  else if(vtechmode == 1) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,RFCol,9RFRow,"Lagoon     ");
  else if (vtechmode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,RFCol,RFRow,"Reef Crest ");
  else if (vtechmode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,DefaultBGColor,RFCol,RFRow,"Short Pulse");
  else if (vtechmode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,DefaultBGColor,RFCol,RFRow,"Long Pulse ");
  else if (vtechmode == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,RFCol,RFRow,"Nut. Trnsp.");
  else if (vtechmode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,RFCol,RFRow,"Tidal Swell");
  else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,DefaultBGColor,RFCol,RFRow,"Night      ");
    pingSerial();
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

void DrawCustomGraph()
{
}

I haven't tested it either. It also does not display Temp or T1 or PH. It's mostly a simple base to work from. To alter where the RF mode is placed, you just need to adjust the RFCol and RFRow values.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

First time coder - Please help :)

Post by Poiromaniax »

Thanks again man, you're a legend

I'll try fiddle with it and see if I have luck adding in ph and temp :)
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: First time coder - Please help :)

Post by binder »

Poiromaniax wrote:Thanks again man, you're a legend

I'll try fiddle with it and see if I have luck adding in ph and temp :)
Let me rephrase this. It displays the T1 temp and PH BUT it does not display the labels for the values. So you will have to add the labels in yourself.
Make sure you read through this guide: http://forum.reefangel.com/viewtopic.php?f=14&t=109
It's got a lot of good information about creating your own custom main screen.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

Hey binder,

Ive just tried the code and am getting an error
"no matching function to call for RA_NokiaLCD::DrawSingleMonitor (int&, int, int, int)'

any ideas?

I thought that maybe it was because i didnt have the numbers enabled, but that wasnt it
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: First time coder - Please help :)

Post by binder »

I will take a look tonight when I get home.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

First time coder - Please help :)

Post by Poiromaniax »

binder wrote:I will take a look tonight when I get home.

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

Re: First time coder - Please help :)

Post by rimai »

Try this:

Code: Select all

// vortech mode, moon state, ph, temp, relays

#define RFRow 40
#define RFCol 50
void DrawCustomMain()
{
    // the graph is drawn/updated when we exit the main menu &
    // when the parameters are saved
    ReefAngel.LCD.DrawDate(6, 112);
    pingSerial();

    ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T1_PROBE], T1TempColor, 6, MENU_START_ROW,10);
    ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, PHColor, 6, MENU_START_ROW*2,100);

  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,6,RFRow,"RF Mode:");
    byte vtechmode = InternalMemory.RFMode_read();
  if (vtechmode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,DefaultBGColor,RFCol,RFRow,"Constant   ");
  else if(vtechmode == 1) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,RFCol,RFRow,"Lagoon     ");
  else if (vtechmode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,DefaultBGColor,RFCol,RFRow,"Reef Crest ");
  else if (vtechmode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,DefaultBGColor,RFCol,RFRow,"Short Pulse");
  else if (vtechmode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,DefaultBGColor,RFCol,RFRow,"Long Pulse ");
  else if (vtechmode == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,RFCol,RFRow,"Nut. Trnsp.");
  else if (vtechmode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,DefaultBGColor,RFCol,RFRow,"Tidal Swell");
  else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,DefaultBGColor,RFCol,RFRow,"Night      ");
    pingSerial();
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

void DrawCustomGraph()
{
}
Roberto.
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

First time coder - Please help :)

Post by Poiromaniax »

Thanks, I will try in the next few days :)
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: First time coder - Please help :)

Post by binder »

The code Roberto posted is right on. I accidentally left off a parameter at the end. Good catch. 8-)
Poiromaniax
Posts: 180
Joined: Thu Apr 05, 2012 6:20 am
Location: JHB, South Africa

Re: First time coder - Please help :)

Post by Poiromaniax »

Thanks guys :)

Code is working now :)

I have also made my own custom main :D just gotta figure out how to add the moon state on the screen
Image
Post Reply