PH Expansion

Do you have a question on how to do something.
Ask in here.
Post Reply
stevengreen2
Posts: 29
Joined: Thu Sep 27, 2012 11:02 pm
Location: Redding

PH Expansion

Post by stevengreen2 »

Is there something wrong with my code. I changed it today for my PH expansion to handle my calcium reactor and I can't get it to work right off of my PH Expansion.

Here is my code:

Code: Select all

#define WDT
#define NUMBERS_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 <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 <ReefAngel.h>
#include <avr/pgmspace.h>

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


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


void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  ReefAngel.AddStandardMenu();  // Add Standard Menu
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port5Bit;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = 0;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = 0;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port1Bit | Port3Bit;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;
  // Set the Overheat temperature setting
  InternalMemory.OverheatTemp_write( 830 );


  // Ports that are always on

   ReefAngel.Relay.On( Port5 );
  ////// Place additional initialization code below here


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

void loop()
{
  ReefAngel.StandardHeater( Port1,780,790 );
  ReefAngel.SingleATO( true,Port3,300,0 );
  ReefAngel.StandardLights( Port4,9,0,22,0 ); //LED Fans
  ReefAngel.StandardLights( Port6,9,0,22,0 ); //UV LED
  ReefAngel.StandardLights( Port7,11,0,20,0 ); //DR-Cyan LED
  ReefAngel.StandardLights( Port8,22,0,9,30 ); //SUMP LIGHT
  ReefAngel.PWM.SetDaylight( PWMSlope(10,0,21,0,10,100,30,10) ); //BLUE LED
  ReefAngel.PWM.SetChannel( 0, PWMSlope(9,0,22,0,10,100,60,10) ); //RB LED
  ReefAngel.PWM.SetChannel( 1, PWMSlope(10,30,21,0,10,55,120,10) ); //CW LED
  ReefAngel.PWM.SetChannel( 2, PWMSlope(10,30,21,0,10,75,120,10) ); //CW LED
  ////// Place your custom code below here

if ( ReefAngel.Params.PHExp < 665 ) ReefAngel.Relay.Off(Box1_Port2); //CO2 Switch
if ( ReefAngel.Params.PHExp >= 680 ) ReefAngel.Relay.On(Box1_Port2); //CO2 Switch

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

  // This should always be the last line
  ReefAngel.AddWifi();
  ReefAngel.ShowInterface();
}

void DrawCustomMain()
{
  byte x = 6;
  byte y = 2;
  byte t;
  char text[10];

  // Parameters
  ReefAngel.LCD.DrawDate(6, 2);
  ReefAngel.LCD.Clear(COLOR_SLATEGREY, 1, 11, 132, 11);
  pingSerial();

  ReefAngel.LCD.DrawLargeText(COLOR_BLUE,255,12,16,"Steve's Reef", Font8x16);
  pingSerial();

  ReefAngel.LCD.DrawText(COLOR_BLUE,255, 6, 101, "--------------------");
  ReefAngel.LCD.DrawText(COLOR_BLUE,255, 6, 126, "--------------------");
  ReefAngel.LCD.DrawText(COLOR_BLUE,255,10,30,"TANK");
  ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(COLOR_SLATEGREY, 255, 15, 40, text, Num8x16);
  pingSerial();

  ReefAngel.LCD.DrawText(COLOR_BLUE,255,85,30,"CR pH");
  ConvertNumToString(text, ReefAngel.Params.PHExp, 100);
  ReefAngel.LCD.DrawLargeText(COLOR_SLATEGREY, 255, 85, 40, text, Num8x16);
  pingSerial();

  // Main Relay Box
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 87, TempRelay);
  pingSerial();

  ReefAngel.LCD.DrawText(COLOR_BLUE,255,12,58,"Room");
  ConvertNumToString(text, ReefAngel.Params.Temp[T3_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(COLOR_SLATEGREY, 255, 15, 68, text, Num8x16);

  ReefAngel.LCD.DrawText(COLOR_BLUE,255,81,58,"Tank pH");
  ConvertNumToString(text, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.DrawLargeText(COLOR_SLATEGREY, 255, 85, 70, text, Num8x16);

  ReefAngel.LCD.DrawText(0,255,15,109, "RB");  
  ReefAngel.LCD.DrawText(COLOR_SLATEGREY,255,14,119, ReefAngel.PWM.GetChannelValue(0));

  ReefAngel.LCD.DrawText(0,255,105,109, "CW");  
  ReefAngel.LCD.DrawText(COLOR_SLATEGREY,255,106,119, ReefAngel.PWM.GetChannelValue(1));

  ReefAngel.LCD.DrawText(0,255,55,109, "BLUE");  
  ReefAngel.LCD.DrawText(COLOR_SLATEGREY,255,60,119, ReefAngel.PWM.GetDaylightValue());
}
void DrawCustomGraph()
{
}
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights7' /

// Main Relay Box 

// Date and Time


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

Re: PH Expansion

Post by rimai »

It looks good.
What is it doing?
Roberto.
stevengreen2
Posts: 29
Joined: Thu Sep 27, 2012 11:02 pm
Location: Redding

Re: PH Expansion

Post by stevengreen2 »

Well the PH is 7.22 right now and port 2 is not on.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PH Expansion

Post by rimai »

The code looks good.
Can you test the relay expansion to see if you can control it and it communicates with the head unit?
Roberto.
stevengreen2
Posts: 29
Joined: Thu Sep 27, 2012 11:02 pm
Location: Redding

Re: PH Expansion

Post by stevengreen2 »

Yeah, I can turn off/on port 2 with my phone just fine. I used to have port 2 configured for C02 with the regular PH from the controller.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PH Expansion

Post by rimai »

So let's check the pH expansion.
Are you sure it is working?
The 7.22 value you mentioned, is it the one displayed as CR pH?
Roberto.
stevengreen2
Posts: 29
Joined: Thu Sep 27, 2012 11:02 pm
Location: Redding

Re: PH Expansion

Post by stevengreen2 »

Yeah, the PH expansion is going to my Calcium Reactor and it is showing 7.72 now
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PH Expansion

Post by rimai »

Humm... not sure what the issue is :oops:
Everything looks correct.
Roberto.
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: PH Expansion

Post by binder »

I have a couple comments.

1. This line at the end shouldn't be there. I'm not exactly sure what it is doing either:

Code: Select all

// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights7' /

// Main Relay Box 
This line is just hanging out outside of all the normal functioning code. It should probably be removed.

2. Next, I see no reference to an expansion relay box HOWEVER your custom CO2 code is using the 1st expansion box and port 2 on it and not on the main relay.

Code: Select all

if ( ReefAngel.Params.PHExp < 665 ) ReefAngel.Relay.Off(Box1_Port2); //CO2 Switch
if ( ReefAngel.Params.PHExp >= 680 ) ReefAngel.Relay.On(Box1_Port2); //CO2 Switch
I think this should be changed to this to work:

Code: Select all

if ( ReefAngel.Params.PHExp < 665 ) ReefAngel.Relay.Off(Port2); //CO2 Switch
if ( ReefAngel.Params.PHExp >= 680 ) ReefAngel.Relay.On(Port2); //CO2 Switch
Otherwise it is trying to toggle a relay that doesn't exist.
stevengreen2
Posts: 29
Joined: Thu Sep 27, 2012 11:02 pm
Location: Redding

Re: PH Expansion

Post by stevengreen2 »

Thanks so much guys, that did it. That code was just left from copying somebody's elses code from the forum. I'm so glad that no matter what issue I have with this reef angel it can be fixed fast.
Post Reply