Multiple Relays - Special Coding Needed?

Do you have a question on how to do something.
Ask in here.
Post Reply
Dadof2boys
Posts: 11
Joined: Sat Oct 10, 2015 7:46 am

Multiple Relays - Special Coding Needed?

Post by Dadof2boys »

I've just added a new universal relay to my system, in addition to the power control expansion I already have in my system. The new universal relay is setup as Box1 (dip switches are set) and I changed the power control expansion to Box2 (dip switches are now set to ID 2).

To activate Box2 in the code, do I need to do something special? I thought I would just be able to code for Box2_PortX and be done but for some reason the system won't activate any of Box2 ports. If I switch the dip switches on the universal relay to ID 2 and the power control expansion to ID 1 the opposite happens -- the PCE now works and the universal relay does not.

Is there something that needs to be added to the code?

Here is the code that I have right now with the Universal Relay as ID 1 and PCE as ID 2:

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>

/*
Ports assignment:

Port1 - Sump Heater
Port2 - Main Sump Pump
Port3 - Canopy Fan - Right
Port4 - Moon Lighting - Right
Port5 - Moon Lighting - Left
Port6 - Day Lights - Right
Port7 - Day Lights - Left
Port8 - Sun Lights - Left

Expansion Box 1 - Standard Expansion
Port1 - Stand Light
Port2 - Skimmer in Sump
Port3 - Canopy Fan - Left
Port4 - Circulation Pump - Tank Center
Port5 - Circulation Pump - Tank Right
Port6 - Circulation Pump - Tank Left
Port7 - 

Port8 -

Expansion Box 2 - 12v Expansion
Port1 - ATO Pump
Port2 - Cal. Pump
Port3 - Mag. Pump

*/

void setup()
{
    // This must be the first line
    InternalMemory.LCDID_write(0);
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
    ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
    ReefAngel.AddMultiChannelWaterLevelExpansion();  // Multi-Channel Water Level Expanion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = 0;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port2Bit;
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port4Bit | Port5Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.LightsOnPortsE[0] = 0;
    ReefAngel.LightsOffPorts = Port4Bit | Port5Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.OverheatShutoffPortsE[0] = 0;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 829 );


    // Ports that are always on
    ReefAngel.Relay.On( Port2 ); // Main Pump
    ReefAngel.Relay.On( Box2_Port1 ); // Circulation Pump - Tank Center
    ReefAngel.Relay.On( Box2_Port2 ); // Skimmer
    ReefAngel.Relay.On( Box2_Port1 ); // Sump Lighting

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

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

void loop()
{
    ReefAngel.StandardHeater( Port1,751,801 );
    ReefAngel.StandardFan( Port3,809,812 ); // Canopy Fan - Right
    ReefAngel.StandardFan( Box2_Port3,809,812 ); // Canopy Fan - Left
    ReefAngel.StandardLights( Port4,20,0,7,30 );
    ReefAngel.StandardLights( Port5,20,0,7,30 );
    ReefAngel.StandardLights( Port6,7,45,20,0 );
    ReefAngel.StandardLights( Port7,7,50,19,30 );
    ReefAngel.StandardLights( Port8,8,0,20,0 );
    ////// Place your custom code below here
    
        
    if (ReefAngel.WaterLevel.GetLevel(1)<=90 && ReefAngel.WaterLevel.GetLevel(2)>10)ReefAngel.Relay.On(Box1_Port1);
    if (ReefAngel.WaterLevel.GetLevel(1)>95)ReefAngel.Relay.Off(Box1_Port1);     

    ReefAngel.WavemakerRandom(Box2_Port5,60,300); // Turn Box2_Port5 on/off random cycles that lasts from 60 to 300 secs
    if (ReefAngel.Water
    ReefAngel.Relay.Set(Box2_Port6,!ReefAngel.Relay.Status(Box2_Port5)); // Turn Box2_Port6 on/off on opposite cycle as Box 1 - Port 5

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

  }

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

Re: Multiple Relays - Special Coding Needed?

Post by rimai »

One of the IDs is wrong.
Leave the power expansion on ID1 and send a photo of how you set the ID on the new box.
Roberto.
Dadof2boys
Posts: 11
Joined: Sat Oct 10, 2015 7:46 am

Re: Multiple Relays - Special Coding Needed?

Post by Dadof2boys »

I'll take it in the morning and send a photo of both to be on the safe side. Can't thank you enough for all of your help this week! I'll reset the PCE to 1 and change the universal relay to 2.
Dadof2boys
Posts: 11
Joined: Sat Oct 10, 2015 7:46 am

Re: Multiple Relays - Special Coding Needed?

Post by Dadof2boys »

Made the ID changes this morning... Now the universal relay (now on ID 2) is responding without issue. The PCE (now on ID 1) is no longer responding. Here's the picture of the PCE set to ID 1 - all the dip switches are slid to the off position and the head unit has been rebooted to be on the safe side.
Attachments
PCE - ID 1
PCE - ID 1
PCE_ID1.png (241.12 KiB) Viewed 5211 times
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Multiple Relays - Special Coding Needed?

Post by rimai »

Let's do a quick search for the modules.
Run I2Cscanner and send the results:
viewtopic.php?p=18831#p18831
After running i2cscanner code, you will need to load your code again to put things back to normal.
Roberto.
Dadof2boys
Posts: 11
Joined: Sat Oct 10, 2015 7:46 am

Re: Multiple Relays - Special Coding Needed?

Post by Dadof2boys »

Here's the results from i2cscanner:

Code: Select all

I2CScanner ready!
starting scanning of I2C bus from 1 to 128...
addr: 1       	addr: 2       	addr: 3       	addr: 4       
addr: 5       	addr: 6       	addr: 7       	addr: 8       
addr: 9       	addr: A       	addr: B       	addr: C       
addr: D       	addr: E       	addr: F       	addr: 10       
addr: 11       	addr: 12       	addr: 13       	addr: 14       
addr: 15       	addr: 16       	addr: 17       	addr: 18       
addr: 19       	addr: 1A       	addr: 1B       	addr: 1C       
addr: 1D       	addr: 1E       	addr: 1F       	addr: 20 found!
addr: 21       	addr: 22       	addr: 23       	addr: 24       
addr: 25       	addr: 26       	addr: 27       	addr: 28       
addr: 29       	addr: 2A       	addr: 2B       	addr: 2C       
addr: 2D       	addr: 2E       	addr: 2F       	addr: 30       
addr: 31       	addr: 32       	addr: 33       	addr: 34       
addr: 35       	addr: 36       	addr: 37       	addr: 38       
addr: 39 found!	addr: 3A       	addr: 3B       	addr: 3C       
addr: 3D       	addr: 3E       	addr: 3F       	addr: 40       
addr: 41       	addr: 42       	addr: 43       	addr: 44       
addr: 45       	addr: 46       	addr: 47       	addr: 48       
addr: 49 found!	addr: 4A       	addr: 4B       	addr: 4C       
addr: 4D found!	addr: 4E       	addr: 4F       	addr: 50 found!
addr: 51       	addr: 52       	addr: 53       	addr: 54 found!
addr: 55       	addr: 56       	addr: 57       	addr: 58       
addr: 59       	addr: 5A       	addr: 5B       	addr: 5C       
addr: 5D       	addr: 5E       	addr: 5F       	addr: 60       
addr: 61       	addr: 62       	addr: 63       	addr: 64       
addr: 65       	addr: 66       	addr: 67       	addr: 68 found!
addr: 69       	addr: 6A       	addr: 6B       	addr: 6C       
addr: 6D       	addr: 6E       	addr: 6F       	addr: 70       
addr: 71       	addr: 72       	addr: 73       	addr: 74       
addr: 75       	addr: 76       	addr: 77       	addr: 78       
addr: 79       	addr: 7A       	addr: 7B       	addr: 7C       
addr: 7D       	addr: 7E       	addr: 7F       	addr: 80 found!

done
Dadof2boys
Posts: 11
Joined: Sat Oct 10, 2015 7:46 am

Re: Multiple Relays - Special Coding Needed?

Post by Dadof2boys »

I see that address 38 is not showing up and since that is for ID 1, I know it's not seeing it. I moved the USB for the PCE to another port on the expansion module and reran i2cscanner and now that ID is showing up. Looks like I have 4 bad ports on the expansion module and that will need to be replaced sometime soon. But... in any case, I'm back in business.
Post Reply