Mike's RSM 500 Code

Share you PDE file with our community
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

OK, when I unplug the RF module the red light turns off. And I can control ports.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

Try this update.
You need to open the enclosure and connect the USB-TTL cable with the black wire on the GND pin.
Then, you need to edit the file update.bat to use whatever com port you are using.
Double-click the update.bat file to start updating.
Attachments
update.zip
(427.13 KiB) Downloaded 505 times
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Which is the ground pin?
Image
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

Sorry, I forgot to say to remove the RF module too.
RF.png
RF.png (18.62 KiB) Viewed 8638 times
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

libusb0.dll is missing error when I run the bat file (avrdude.exe)

EDIT:Got the fix...Had to copy that file to c:\Windows\syswow64
RF firmware should be updated now. Going to plug it back in and see what happens.
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Same issue....after a bit red light comes on and relays don't toggle on/off. When I unplug RF module the relays toggle (even when I manually toggle when red light is blinking).

Is my RF module a dud?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

Ok, are you sure you got it updated?
Did it go through the % from 0 to 100?
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

OK, I didn't see any percentage...the command window closed when it was finished. I just re-ran the update by running it manually so the window didn't auto exit.

EDIT: My RA just had two power outage scenarios (code that was working fine), when power was fine (relay exp never lost power). Could the root cause be the new Expansion Hub?

Code: Select all

avrdude -Cavrdude.conf -v -patmega328p
-carduino -P\\.\COM6 -b115200 -D -Uflash:w:RF_Update_WDT_modified.hex:i

avrdude: Version 6.0, compiled on Apr  6 2012 at 19:29:19
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "avrdude.conf"

         Using Port                    : \\.\COM6
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
Rebooting Reef Angel Controller
avrdude: stk500_getsync(): not in sync: resp=0x64

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

Re: Mike's RSM 500 Code

Post by rimai »

No, it didn't upload.
It needs to upload just like in RA.
It will flash the red led for a few seconds and there will be a % bar.
Did you remove the Ecotech RF module?
It won't work with the RF module plugged into the board.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

I don't think I understand...here is what I did.

I unplugged the RF Exp Module and removed the board from the plastic case. Hooked up the USB TTL to the RF board (pic I posted above) black wire to ground pin. Connect USB end to computer and run the command.

Sent from my Nexus 7 using Tapatalk 4
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

You must also remove the Ecotech RF module before you can upload or it will thing the serial data is supposed to be sent to the vortech drivers.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

It's been awhile since I have needed to update code, but the power outage function wasn't working.

Not sure why but the power outage was below "// This should always be the last line" When I moved it up I couldn't compile. What did I do wrong here?

Thanks!

Getting the following compile error at: void CheckPower() {

Code: Select all

updated_code.cpp: In function 'void loop()':
updated_code:165: error: a function-definition is not allowed here before '{' token
updated_code:257: error: expected `}' at end of input

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 <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>

// Define Named Relay Ports
#define Flow1           1
#define Flow2           2
#define Flow3           3
#define Return          4
#define Skimmer         5
#define VortechL        6
#define VortechR        7
#define HeaterDisp      8

#define CenterT5        Box1_Port1
#define FrontT5         Box1_Port2
#define BackT5          Box1_Port3
#define MoonLED         Box1_Port4
#define Unused          Box1_Port5
#define Reactor         Box1_Port6
#define Fan             Box1_Port7
#define HeaterSump      Box1_Port8

////// Place global variable code below here
// Custom Main
byte x,y;
char text[10];

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

////// Setup Begin
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    
    // Controlled Modes Toggled Ports
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit; //Fan,HeaterSump
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit; // Flow1-3,Return,Skimmer,HeaterDisp
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; //Front+BackT5,Reactor,Fan,HeaterSump
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5
    
    // Water Temperature Settings & Overheat
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 820 );
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterDisp
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port8Bit; //Front+BackT5,HeaterSump

    // Ports that are always on
    ReefAngel.Relay.On( Flow1 );
    ReefAngel.Relay.On( Flow2 );
    ReefAngel.Relay.On( Flow3 );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    ReefAngel.Relay.On( Reactor );
    // Ports that are always off
    ReefAngel.Relay.Off(Unused);

    ////// Place additional initialization code below here
    
    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval(5);
    
    ////// Place additional initialization code above here
}
////// Setup End

////// Loop Begin
void loop()
{
    // Ports that are Delayed
    ReefAngel.Relay.DelayedOn( Skimmer,2 );
    // Temperature Control
    ReefAngel.StandardHeater( HeaterSump,770,773 );
    ReefAngel.StandardHeater( HeaterDisp,767,770 );
    ReefAngel.StandardFan( Fan,810,814 );
    // T5 Light Schedule
    ReefAngel.StandardLights( CenterT5,9,0,20,0 );
        if (hour()==14 && minute()>=0 && minute()<=59) ReefAngel.Relay.Off(CenterT5);
    ReefAngel.StandardLights( FrontT5,10,0,18,0 );
	if (hour()==15 && minute()>=0 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    ReefAngel.StandardLights( BackT5,11,0,19,0 );
        if (hour()==16 && minute()>=0 && minute()<=29) ReefAngel.Relay.Off(BackT5);

////// Place your custom code below here
    
    // RSM MoonLED Schedule
    if (hour()>=6 && hour()<=8) ReefAngel.StandardLights( MoonLED,6,0,8,59 ); //Morning
    else if(hour()>=20 && hour()<=23) ReefAngel.StandardLights( MoonLED,20,0,23,45 ); //Evening
    else if(hour()>=23 || hour()<=4) if (MoonPhase()>=90) ReefAngel.StandardLights( MoonLED,23,46,4,0 ); //Full Moon
    
    // Moonphase LED Schedule
    if (hour()>=20 || hour()<4)
    {
      ReefAngel.PWM.SetActinic(MoonPhase());
      ReefAngel.PWM.SetDaylight(MoonPhase());
    }
    else
    {
      ReefAngel.PWM.SetActinic(0);
      ReefAngel.PWM.SetDaylight(0);
    }
    //T5 Light Off Variable
    //if (hour()==12 && minute()>=30 && minute()<=44) ReefAngel.Relay.Off(CenterT5);
    //if (hour()==12 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==16 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5); 
    //if (hour()==13 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    //if (hour()==16 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    
    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if (ReefAngel.DisplayedMenu!=FEEDING_MODE || ReefAngel.DisplayedMenu!=WATERCHANGE_MODE)
    {
      if (hour()>=16 && hour()<=19)
      {
        ReefAngel.RF.UseMemory=false;
        ReefAngel.RF.SetMode(LongWave,50,30);
      }
        else if (hour()>=20 || hour()<7)
        {
          ReefAngel.RF.UseMemory=false;
          ReefAngel.RF.SetMode(Lagoon,25,0);
        }
        else
        {
          ReefAngel.RF.UseMemory=true;
        }
     }

    // When Return pump is off so is Skimmer
    if (!ReefAngel.Relay.Status(Return)) {
      ReefAngel.Relay.Override(Skimmer,0); 
    }

void CheckPower() {
  static boolean PowerOutage=false;
  static boolean DelayedPowerOutage=false;
    
    // Power Outage - Leave Single Flow Pump Powered
    if (!ReefAngel.Relay.IsRelayPresent(EXP1_RELAY)) PowerOutage=true; //Expansion Relay 1 has lost power
    if (!PowerOutage)
    { 
      ReefAngel.Timer[1].Start();
    } 
    if (ReefAngel.Timer[1].IsTriggered())
    { 
      DelayedPowerOutage=true;
    }
    if (DelayedPowerOutage)
    {
    ReefAngel.Relay.Off (Flow1);
    ReefAngel.Relay.Off (Flow2);
    ReefAngel.Relay.Off (Flow3);
    ReefAngel.Relay.Off (Return);
    ReefAngel.Relay.Off (Skimmer);
    ReefAngel.Relay.Off (HeaterDisp);
    //set vortechs to low power
    }
    
    // Power Restored
    if (PowerOutage && ReefAngel.Relay.IsRelayPresent(EXP1_RELAY))
    {
      PowerOutage=false;
      DelayedPowerOutage=false;
      LastStart=now();
    }
}
////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "*****","*****" );
    ReefAngel.ShowInterface();
}
////// Loop End

////// Custom Main Begin
void DrawCustomMain()
{
// Display Date & Time
    ReefAngel.LCD.DrawDate(5, 2);
    ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
    pingSerial();

// Display Water Temp Value
    ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
    ReefAngel.LCD.DrawHugeNumbers(COLOR_CRIMSON, 255, 5, 14, text);
    pingSerial();
// Display pH Text
    ReefAngel.LCD.DrawText(COLOR_INDIGO,255,80,14,"pH");
// Display pH Value
    ConvertNumToString(text, ReefAngel.Params.PH, 100);
    ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 95, 14, text, Num8x16);
    pingSerial();
// Display Room Temp Text
    ReefAngel.LCD.DrawText(COLOR_ROYALBLUE,255,80,24,"Rm");
// Display Room Temp Value
    ConvertNumToString(text, ReefAngel.Params.Temp[T3_PROBE], 10);
    ReefAngel.LCD.DrawLargeText(COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16);
    pingSerial();
// Vortech Info

//Moon Phase
    ReefAngel.LCD.Clear(DefaultBGColor,5,88,95,95);
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,5,88,MoonPhaseLabel());
//Dimmable Moon LEDs
    ReefAngel.LCD.DrawText(COLOR_NAVY,255,5,98, "MoonLEDs:");
    ReefAngel.LCD.Clear(DefaultBGColor,59,98,75,106);
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,59,98, ReefAngel.PWM.GetActinicValue());
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,75,98, "%");
  // Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();
// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();
}
////// Custom Main End

////// Custom Graph Begin
void DrawCustomGraph()
{}
///// Custom Graph End
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

you cannot define a function within another function. your checkpower function is being defined inside the loop function code.
move it out and that should help.


Sent from my Nexus 7
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

I went ahead and updated your code and moved everything around how it should be. I test compiled and everything compiles just fine. I did not upload the code to a controller though.

The formatting is updated too. You will also need to put your portal information back in since you removed it before.
Hope this helps.

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 <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>

// Define Named Relay Ports
#define Flow1           1
#define Flow2           2
#define Flow3           3
#define Return          4
#define Skimmer         5
#define VortechL        6
#define VortechR        7
#define HeaterDisp      8

#define CenterT5        Box1_Port1
#define FrontT5         Box1_Port2
#define BackT5          Box1_Port3
#define MoonLED         Box1_Port4
#define Unused          Box1_Port5
#define Reactor         Box1_Port6
#define Fan             Box1_Port7
#define HeaterSump      Box1_Port8

////// Place global variable code below here
// Custom Main
byte x, y;
char text[10];

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

////// Setup Begin
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller

    // Controlled Modes Toggled Ports
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit; //Fan,HeaterSump
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit; // Flow1-3,Return,Skimmer,HeaterDisp
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; //Front+BackT5,Reactor,Fan,HeaterSump
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5

    // Water Temperature Settings & Overheat
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 820 );
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterDisp
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port8Bit; //Front+BackT5,HeaterSump

    // Ports that are always on
    ReefAngel.Relay.On( Flow1 );
    ReefAngel.Relay.On( Flow2 );
    ReefAngel.Relay.On( Flow3 );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    ReefAngel.Relay.On( Reactor );
    // Ports that are always off
    ReefAngel.Relay.Off( Unused );

    ////// Place additional initialization code below here

    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval( 5 );

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

////// Loop Begin
void loop()
{
    // Ports that are Delayed
    ReefAngel.Relay.DelayedOn( Skimmer, 2 );
    // Temperature Control
    ReefAngel.StandardHeater( HeaterSump, 770, 773 );
    ReefAngel.StandardHeater( HeaterDisp, 767, 770 );
    ReefAngel.StandardFan( Fan, 810, 814 );
    // T5 Light Schedule
    ReefAngel.StandardLights( CenterT5, 9, 0, 20, 0 );

    if ( hour() == 14 && minute() >= 0 && minute() <= 59 ) {
        ReefAngel.Relay.Off( CenterT5 );
    }

    ReefAngel.StandardLights( FrontT5, 10, 0, 18, 0 );

    if ( hour() == 15 && minute() >= 0 && minute() <= 29 ) {
        ReefAngel.Relay.Off( FrontT5 );
    }

    ReefAngel.StandardLights( BackT5, 11, 0, 19, 0 );

    if ( hour() == 16 && minute() >= 0 && minute() <= 29 ) {
        ReefAngel.Relay.Off( BackT5 );
    }

////// Place your custom code below here

    // RSM MoonLED Schedule
    if ( hour() >= 6 && hour() <= 8 ) {
        ReefAngel.StandardLights( MoonLED, 6, 0, 8, 59 );    //Morning
    } else if( hour() >= 20 && hour() <= 23 ) {
        ReefAngel.StandardLights( MoonLED, 20, 0, 23, 45 );    //Evening
    } else if( hour() >= 23 || hour() <= 4 ) if ( MoonPhase() >= 90 ) {
            ReefAngel.StandardLights( MoonLED, 23, 46, 4, 0 );    //Full Moon
        }

    // Moonphase LED Schedule
    if ( hour() >= 20 || hour() < 4 ) {
        ReefAngel.PWM.SetActinic( MoonPhase() );
        ReefAngel.PWM.SetDaylight( MoonPhase() );
    } else {
        ReefAngel.PWM.SetActinic( 0 );
        ReefAngel.PWM.SetDaylight( 0 );
    }

    //T5 Light Off Variable
    //if (hour()==12 && minute()>=30 && minute()<=44) ReefAngel.Relay.Off(CenterT5);
    //if (hour()==12 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==16 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==13 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    //if (hour()==16 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);

    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
        if ( hour() >= 16 && hour() <= 19 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( LongWave, 50, 30 );
        } else if ( hour() >= 20 || hour() < 7 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( Lagoon, 25, 0 );
        } else {
            ReefAngel.RF.UseMemory = true;
        }
    }

    // When Return pump is off so is Skimmer
    if ( !ReefAngel.Relay.Status( Return ) ) {
        ReefAngel.Relay.Override( Skimmer, 0 );
    }
    
    // Check the power here, the function is defined below
    CheckPower();

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

    // This should always be the last line
    ReefAngel.Portal( "*****", "*****" );
    ReefAngel.ShowInterface();
}
////// Loop End

////// Custom Function
void CheckPower()
{
    static boolean PowerOutage = false;
    static boolean DelayedPowerOutage = false;

    // Power Outage - Leave Single Flow Pump Powered
    if ( !ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = true;    //Expansion Relay 1 has lost power
    }

    if ( !PowerOutage ) {
        ReefAngel.Timer[1].Start();
    }

    if ( ReefAngel.Timer[1].IsTriggered() ) {
        DelayedPowerOutage = true;
    }

    if ( DelayedPowerOutage ) {
        ReefAngel.Relay.Off ( Flow1 );
        ReefAngel.Relay.Off ( Flow2 );
        ReefAngel.Relay.Off ( Flow3 );
        ReefAngel.Relay.Off ( Return );
        ReefAngel.Relay.Off ( Skimmer );
        ReefAngel.Relay.Off ( HeaterDisp );
        //set vortechs to low power
    }

    // Power Restored
    if ( PowerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = false;
        DelayedPowerOutage = false;
        LastStart = now();
    }
}
////// Custom Function End

////// Custom Main Begin
void DrawCustomMain()
{
// Display Date & Time
    ReefAngel.LCD.DrawDate( 5, 2 );
    ReefAngel.LCD.Clear( COLOR_BLACK, 1, 11, 132, 11 );
    pingSerial();

// Display Water Temp Value
    ConvertNumToString( text, ReefAngel.Params.Temp[T1_PROBE], 10 );
    ReefAngel.LCD.DrawHugeNumbers( COLOR_CRIMSON, 255, 5, 14, text );
    pingSerial();
// Display pH Text
    ReefAngel.LCD.DrawText( COLOR_INDIGO, 255, 80, 14, "pH" );
// Display pH Value
    ConvertNumToString( text, ReefAngel.Params.PH, 100 );
    ReefAngel.LCD.DrawLargeText( COLOR_INDIGO, 255, 95, 14, text, Num8x16 );
    pingSerial();
// Display Room Temp Text
    ReefAngel.LCD.DrawText( COLOR_ROYALBLUE, 255, 80, 24, "Rm" );
// Display Room Temp Value
    ConvertNumToString( text, ReefAngel.Params.Temp[T3_PROBE], 10 );
    ReefAngel.LCD.DrawLargeText( COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16 );
    pingSerial();
// Vortech Info

//Moon Phase
    ReefAngel.LCD.Clear( DefaultBGColor, 5, 88, 95, 95 );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 5, 88, MoonPhaseLabel() );
//Dimmable Moon LEDs
    ReefAngel.LCD.DrawText( COLOR_NAVY, 255, 5, 98, "MoonLEDs:" );
    ReefAngel.LCD.Clear( DefaultBGColor, 59, 98, 75, 106 );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 59, 98, ReefAngel.PWM.GetActinicValue() );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 75, 98, "%" );
    // Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();
// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();
}
////// Custom Main End

////// Custom Graph Begin
void DrawCustomGraph()
{}
///// Custom Graph End

modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Thanks a lot!

I uploaded the updated code and the power outage is working now.

Strange thing is that the overheat function isn't working now...I did a full power off and it temp is 82.0 and the overheat light isn't coming on and the ports aren't shutting off....any ideas?
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

hmmm...more checking is needed. nothing is standing out to me at quick glance.


Sent from my iPad mini
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

So I recalibrated my pH probe for the first time since I set it up (Nov 2012). Before the calibration I had a pH or 8.34 and now after its at 7.75.

Could the pH be off by that much after about 2.5 years?
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Forgot to mention that I moved the pH probe from the back of the display tank to the sump, could that be the difference? I'll move it back tonight and report back.

Any ideas on the overheat function not working?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

If you get T1 above 82F, nothing happens?
Not even the status LED?
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Correct, last week t1 was at 82 and ports did not shut off and the red light did not come on. I could try and get t1 above 82.

Sent from my HTC One_M8 using Tapatalk
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

It has to go more than 82F and stay there for at least 3 seconds to be considered overheat.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Ok it's working, sorry for the false alarm. Just never had it sit right at 82 for awhile.

I moved the ph probe gettin the sump to the DT and the ph reading hasn't changed much.

Sent from my HTC One_M8 using Tapatalk
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

pH was reading under 7 for the past two nights...doing the calibration again. Now its around 7.5, but its still way lower than it was at 8.5. Do I need a new probe?
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

So I recently ditched my T5 lights for the RSM S Series LEDs. I also did some wiring cleanup, added a skimmate container using High ATO, and just got an Avast Swabbie retrofit.

During the last few days I have been playing around with the Swabbie code. Not using timing in the memory I could get the port to switch on at 4am, but that was the only time (it wasn't running every 4 hours).

So I tried adding lnevo's code for the Swabbie. Compiles fine, but the relay does not run.

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 <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <PAR.h>
#include <ReefAngel.h>

// Define Custom Memory Locations
#define Mem_B_SwabbieRepeat   100
#define Mem_B_SwabbieTime     101

void init_memory() {
  // Initialize Custom Memory Locations
  InternalMemory.write(Mem_B_SwabbieRepeat,6); 
  InternalMemory.write(Mem_B_SwabbieTime,1);
  }

// Define Named Relay Ports
#define FlowPumps       1
#define Lights          2
#define Return          3
#define VortechL        4
#define VortechR        5
#define Skimmer         6
#define FanSump         7
#define HeaterSump      8

#define Reactor         Box1_Port1
#define Swabbie         Box1_Port2
#define Unused          Box1_Port3
#define Unused          Box1_Port4
#define Unused          Box1_Port5
#define WCMix           Box1_Port6
#define WCFlow          Box1_Port7
#define WCHeater        Box1_Port8

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


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

////// Setup Begin (on controller startup/reset)
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen
    // Define labels for LCD screen
    ReefAngel.CustomLabels[0]="Flow Pumps";
    ReefAngel.CustomLabels[1]="Lights";
    ReefAngel.CustomLabels[2]="Return";
    ReefAngel.CustomLabels[3]="Vortech L";
    ReefAngel.CustomLabels[4]="Vortech R";
    ReefAngel.CustomLabels[5]="Skimmer";
    ReefAngel.CustomLabels[6]="Fan";
    ReefAngel.CustomLabels[7]="Heater";

    ReefAngel.CustomLabels[Box1_Port1Label] = "Reactor";
    ReefAngel.CustomLabels[Box1_Port2Label] = "Swabbie";
    ReefAngel.CustomLabels[Box1_Port3Label] = "";
    ReefAngel.CustomLabels[Box1_Port4Label] = "";
    ReefAngel.CustomLabels[Box1_Port5Label] = "";
    ReefAngel.CustomLabels[Box1_Port6Label] = "WCMix";
    ReefAngel.CustomLabels[Box1_Port7Label] = "WCFlow";
    ReefAngel.CustomLabels[Box1_Port8Label] = "WCHeater";
    
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit | Port5Bit; //Unused ports for testing RF module and random feedmode
    
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; // Flowpumps,Return,VortechL,Skimmer,Fan,HeaterSump
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit ; //Reactor,Swabbie    
    
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port6Bit; //Lights
    ReefAngel.LightsOnPortsE[0] = 0;
    
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterSump
    ReefAngel.OverheatShutoffPortsE[0] = 0;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Ports that default on
    ReefAngel.Relay.On( FlowPumps );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    
    // Ports that default off
    ReefAngel.Relay.Off( Unused );
    ReefAngel.Relay.Off( Swabbie );
    ReefAngel.Relay.Off( WCMix );
    ReefAngel.Relay.Off( WCFlow );
    ReefAngel.Relay.Off( WCHeater );

    ////// Place additional initialization code below here

    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval( 5 );    

    ////// Place additional initialization code above here
}
////// Setup End
////// Loop Begin
void loop()
{
    ReefAngel.Relay.On(Reactor); 
    ReefAngel.StandardHeater( HeaterSump );
    ReefAngel.StandardFan( FanSump );
    ReefAngel.StandardLights( Lights );  
    
////// Place your custom code below here

    //HighATO=on, delay start Skimmer | HighATO=off, Skimmer shuts off
    if (ReefAngel.HighATO.IsActive())
      ReefAngel.Relay.DelayedOn( Skimmer );
    else
      ReefAngel.Relay.Off( Skimmer );

    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
        if ( hour() >= 16 && hour() <= 20 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( LongWave, 70, 30 );
        } else if ( hour() >= 20 || hour() < 7 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( ReefCrest, 40, 0 );
        } else {
            ReefAngel.RF.UseMemory = true;
        }
    }
    
//    ReefAngel.StandardHeater( HeaterWC, 775, 778 );

    
    // Turn off Skimmer & FanSump & Reactor if Return Pump is off
    if ( !ReefAngel.Relay.Status( Return ) ) {
        ReefAngel.Relay.Override( Skimmer, 0 );
        ReefAngel.Relay.Override( FanSump, 0 );
        ReefAngel.Relay.Override( Reactor, 0 );
    }
    
    // Check the power here, the function is defined below
    CheckPower();
    
////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "****", "****" );
    ReefAngel.ShowInterface();
}

////// Custom Function
void RunSwabbie() {
  int repeat=InternalMemory.read(Mem_B_SwabbieRepeat)*60;
  int runtime=InternalMemory.read(Mem_B_SwabbieTime)*60;
  static time_t t;
 
  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Swabbie)) {
    ReefAngel.Relay.Auto(Swabbie);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Swabbie);
  } else {
    ReefAngel.DosingPumpRepeat(Swabbie,0,repeat,runtime);   
  } 
}

void CheckPower()
{
    static boolean PowerOutage = false;
    static boolean DelayedPowerOutage = false;

    // Power Outage - Leave Only Vortech Pumps active
    if ( !ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = true;    //Expansion Relay 1 has lost power
    }

    if ( !PowerOutage ) {
        ReefAngel.Timer[1].Start();
    }

    if ( ReefAngel.Timer[1].IsTriggered() ) {
        DelayedPowerOutage = true;
    }

    if ( DelayedPowerOutage ) {
        ReefAngel.Relay.Off ( FlowPumps );
        ReefAngel.Relay.Off ( Return );
        ReefAngel.Relay.Off ( Skimmer );
        ReefAngel.Relay.Off ( Lights );
        ReefAngel.Relay.Off ( FanSump);
        ReefAngel.Relay.Off ( HeaterSump);
        //set vortechs to long wave? something that ripples surface
    }

    // Power Restored
    if ( PowerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = false;
        DelayedPowerOutage = false;
        LastStart = now();
    }
}
////// Custom Function End
When I read the custom memory location of 100 & 101, both result in 255. So I am assuming the memory locations aren't being written. Also when I manually changed the memory from 255 to 6 or 1 the relay has not turned on every six or one hours.

I am guessing maybe it has to do with this line which I do not have. I am not sure how to update it to write the memory for the Swabbie.

Code: Select all

InternalMemory.write(Mem_B_ResetMemory,false);
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

Ignore the init_memory function, it doesnt always work right. but please manually set both memory locations. One needs the runtime and the other gets the repeat value. Runtime should be 1 for one minute and repeat should be 6 for one hour.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

You mean 6 for six hours, right?

So remove init_memory lines and set manually...do I need to update the controller in order to see the swabbie port activate?

I set 100 to 6, and 101 to 1...
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

You will not see it in the portal if thats what your looking for.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

The memory values or the relay switching on? I do see the relay switch at 4am.

Sent from my A0001 using Tapatalk
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

You won't reliably see the port in the portal for relay activity.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

You also need to call RunSwabbie(); in your loop. I don see it there which means its never getting called.
Post Reply