For review, I'm trying to hook the lowATO port to a 5V wall wart to detect a power failure. The main lines are connected to a battery back-up. The plan is to shut-off everything but a powerhead while the power is out and to return back to normal when main power returns.
When I tried a couple versions of this code, I always get an intermittent response to the power from the 5V wall wart being unplugged and or it cycles on and off. Also, something is not right on the masking as the port will cycle with the status change, but the others that are on stay on.
Any ideas? Do I need a resistor to pull up/down the signal?
Here is my abbreviated code....
Code: Select all
/* Main ReefAngelPlus controller with communication for sound,
auxillary monitor, I/O expansion, and extra relaybox, send master time,
flow, buzzer, overflow and reservoir alarms on the I/O
The following features are enabled for this File:
#define DisplayImages
#define SetupExtras
#define DateTimeSetup
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define RelayExp
#define WDT
#define CUSTOM_MENU
#define CUSTOM_MENU_ENTRIES 9
#define CUSTOM_MAIN
#define COLORS_PDE
#define FONT_8x8
#define NUMBERS_8x8
#define CUSTOM_VARIABLES
*/
#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 <ReefAngel.h>
#include <IO.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <avr/pgmspace.h>
//Power outage settings
byte BatteryPower1; //first outlet box
byte BatteryPower2; //second outlet box
static boolean fSave = true; //status of highATOPin
//Custom Main Display
void DrawCustomGraph()
{
}
void DrawCustomMain()
{
if ( ! digitalRead(lowATOPin) )
{
ReefAngel.LCD.Clear(255,1,92,102,102);
ReefAngel.LCD.DrawText(COLOR_GREEN, DefaultBGColor,1,92,"Main Power ON");
}
else
{
ReefAngel.LCD.Clear(255,1,92,102,102);
ReefAngel.LCD.DrawText(COLOR_RED, DefaultBGColor,1,92,"BACKUP Power ON");
}
if (ReefAngel.LowATO.IsActive())
{
lowATOPin == 0;
FillCircle(100,96,5,COLOR_RED);
ReefAngel.LCD.DrawText(COLOR_WHITE,COLOR_RED,98,92,"P");
}
else
{
lowATOPin == 1;
FillCircle(100,96,5,COLOR_GREEN);
ReefAngel.LCD.DrawText(COLOR_WHITE,COLOR_GREEN,98,92,"P");
}
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 110, TempRelay);
// draw 1st expansion relay
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox(12, 120, TempRelay);
}
//************************************************************************************
void setup()
{
//...(other stuff)
//Status of the outlets if power is triggered (only 1 powerhead stays on, all other outlets off)
BatteryPower1 = Port3Bit;
BatteryPower2 = 0;
digitalWrite(lowATOPin,LOW);
}
//************************************************************************************
void loop()
{
// Specific functions
//1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
ReefAngel.StandardHeater(Port1,788,792);
ReefAngel.StandardHeater(Port2,770,792);
ReefAngel.MHLights(Port3,10,0,20,0,5);
ReefAngel.StandardLights(Port4,9,0,21,0);
ReefAngel.StandardFan(Port8,792,820);
ReefAngel.DosingPumpRepeat(Box1_Port7,0,60,4); // Dose for 4 seconds every 60 minutes with 0 minutes offset
ReefAngel.DosingPumpRepeat(Box1_Port8,5,60,4); // Dose for 4 seconds every 60 minutes with 5 minutes offset
//Logic for a poweroutage and return to normal
if (digitalRead(lowATOPin))
{
// only execute once during power outage
if ( fSave )
{
// Force on the ports you want, turn them on if they are
// not already on
ReefAngel.Relay.RelayMaskOn = BatteryPower1;
ReefAngel.Relay.RelayMaskOnE[0] = BatteryPower2;
ReefAngel.Relay.RelayMaskOff = ~BatteryPower1;
ReefAngel.Relay.RelayMaskOffE[0] = ~BatteryPower2;
// ReefAngel.Relay.Write();
fSave = false;
}
}
else
{
// only execute once after power returns
if ( ! fSave )
{
// return everything back to where it should be in normal operation
ReefAngel.Relay.RelayMaskOn = 0;
ReefAngel.Relay.RelayMaskOnE[0] = 0;
ReefAngel.Relay.RelayMaskOff = 0xff;
ReefAngel.Relay.RelayMaskOffE[0] = 0xff;
// ReefAngel.Relay.Write();
fSave = true;
}
}
//...other stuff
ReefAngel.Portal("jsclownfish");
ReefAngel.ShowInterface();
}