RANet relay expansion not working

Expansion modules and attachments
Post Reply
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: RANet relay expansion not working

Post by bencollinz »

how did you get relay box to work? Mine is just flashing white at me...

my code

Code: Select all

    #include <SoftwareSerial.h>
    #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 <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 Heater      1
    #define Return      2
    #define HeaterTk2   3
    #define Skimmer     4
    #define Vortech1    5
    #define Vortech2    6
    #define ATO         7 
    #define Sump Light  8
    */
    ////// Place global variable code below here
byte vtechmode, vtSpeed, vtDuration;
    ////// Place global variable code above here


    void setup()
    {
        // This must be the first line
        ReefAngel.Init();  //Initialize controller
        // Ports toggled in Feeding Mode
        ReefAngel.FeedingModePorts = Port2Bit;
        // ReefAngel.FeedingModePortsE[0] = 0;
        // Ports toggled in Water Change Mode
        // ReefAngel.WaterChangePorts = Port7Bit | Port4Bit | Port5Bit | Port6Bit;
        // ReefAngel.WaterChangePortsE[0] = 0;
        // Ports toggled when Lights On / Off menu entry selected
        // ReefAngel.LightsOnPorts = 0;
        // ReefAngel.LightsOnPortsE[0] = 0;
        // Ports turned off when Overheat temperature exceeded
        ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit;
        // 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( 830 );


        // Ports that are always on
        ReefAngel.Relay.On( Port2 );
        ReefAngel.Relay.On( Port3 );
        ReefAngel.Relay.On( Port4 );
        ReefAngel.Relay.On( Port5 );
        ReefAngel.Relay.On( Port6 );
        ReefAngel.Relay.On( Box1_Port1 );
        ReefAngel.Relay.On( Box1_Port2 );
        ReefAngel.Relay.On( Box1_Port3 );
        ReefAngel.Relay.On( Box1_Port4 );
        ReefAngel.Relay.On( Box1_Port5 );
        ReefAngel.Relay.On( Box1_Port6 );
        ReefAngel.Relay.On( Box1_Port7 );
        ReefAngel.Relay.On( Box1_Port8 );
      

        ////// Place additional initialization code below here
       
        // Hardcode calibrations
        ReefAngel.PHMin=576; // PH7.0
        ReefAngel.PHMax=842; // PH10.0
        ReefAngel.SalMax=3300; // 35ppt
        ////// Place additional initialization code above here
    }

    void loop()
    {
    vtechmode=InternalMemory.RFMode_read();
    vtSpeed=InternalMemory.RFSpeed_read();
    vtDuration=InternalMemory.RFDuration_read();

    static unsigned long feeding;
    ReefAngel.StandardHeater( Port1,778,782 );
        ReefAngel.WaterLevelATO( Port7,180,71,74 );
        ReefAngel.StandardLights( Port8,15,0,2,0 );
        ReefAngel.PWM.SetChannel( 0,PWMSlope(19,00,21,00,15,51,20,0) );  //MOON
        ReefAngel.PWM.SetChannel( 1,PWMSlope(12,30,20,00,15,50,30,0) );  //RB
        ReefAngel.PWM.SetChannel( 2,PWMSlope(12,20,20,00,15,95,30,0) ); //WHITE
        ReefAngel.PWM.SetChannel( 3,PWMSlope(12,15,20,00,15,70,30,0) );  //BLUE&CYAN
        ReefAngel.PWM.SetChannel( 4,PWMSlope(12,00,20,30,15,70,30,0) ); //UV
        
        if ( ReefAngel.HighATO.IsActive())
        {
          ReefAngel.Relay.On(Port2);
        }
        else
        {
          ReefAngel.Relay.Off(Port2);
        }
        
if (hour() >=13 && hour() < 20)
      {
        // if (ReefAngel.RF.Mode==Night) ReefAngel.RF.SetMode(Feeding_Stop,0,0);
        ReefAngel.RF.UseMemory=true;
        // ReefAngel.RF.SetMode(ReefCrest,60,20);
            if (ReefAngel.DisplayedMenu==FEEDING_MODE)
            {
             feeding=now();
             }
             if (now()-feeding<5400) {
            // if (now()-feeding > 1 && now()-feeding < 5400) { // 1 second after feeding mode until 60 minutes after feeding mode.
  ReefAngel.RF.UseMemory=false;
    ReefAngel.RF.SetMode(Smart_NTM,75,10);
    }
           }
      else
      {
        ReefAngel.RF.UseMemory=false;
        ReefAngel.RF.SetMode(Constant,10,0);
       }
         if (vtechmode!=InternalMemory.RFMode_read())
          InternalMemory.RFMode_write(vtechmode);
         if (vtSpeed!=InternalMemory.RFSpeed_read())
          InternalMemory.RFSpeed_write(vtSpeed);
         if (vtDuration!=InternalMemory.RFDuration_read())
          InternalMemory.RFDuration_write(vtDuration);

        // This should always be the last line
        ReefAngel.Portal( "bencollinz" );
        ReefAngel.ShowInterface();
    }
   
     void DrawCustomMain()
    {
      char text[7];
        // Date and Time
        ReefAngel.LCD.DrawDate( 6, 2 );
        ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
        pingSerial();

    ReefAngel.LCD.DrawText(0,255,18,12,"EcoSmart Vortech");
  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_GOLD,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 == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,8,21,"Nutrient Trnsp.");
  else if (vtechmode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,23,21,"Tidal Swell");
  else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,45,21,"Night");

  ReefAngel.LCD.DrawText(0,255,4,30,"RF Speed:");
  ReefAngel.LCD.Clear(255,59,29,128,39);
  ReefAngel.LCD.DrawText(COLOR_BLUE, DefaultBGColor,71,31,vtSpeed);
  ReefAngel.LCD.DrawText(COLOR_BLUE, DefaultBGColor,90,31,"/");
  ReefAngel.LCD.DrawText(COLOR_BLUE, DefaultBGColor,100,31,vtDuration);
  
  ReefAngel.LCD.DrawText(0,255,10,40,"Salt");
  ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(COLOR_INDIANRED, 255, 10, 50, text, Num8x8);
  pingSerial();

 /* ReefAngel.LCD.DrawText(0,255,50,40,"Fresh");
  ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(COLOR_INDIANRED, 255, 50, 50, text, Num8x8);
  pingSerial();
*/
  ReefAngel.LCD.DrawText(0,255,100,40,"pH");
  ConvertNumToString(text, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.DrawLargeText(COLOR_PLUM, 255, 85, 50, text, Num8x8);
  pingSerial();

  ReefAngel.LCD.DrawText(0,255,13,58,"Salinity");
  ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
  ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN, 255, 13, 68, text, Num8x8);
  pingSerial();

  // water level
    ReefAngel.LCD.DrawText(0,255,68,58,"WL");
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE,255, 68, 68, ReefAngel.WaterLevel.GetLevel() );
    pingSerial();

       // Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox( 12, 108, TempRelay );
        pingSerial();
         // Relay Expansion
        TempRelay = ReefAngel.Relay.RelayDataE[0];
        TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
       TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
       ReefAngel.LCD.DrawOutletBox( 12, 120, TempRelay );
        pingSerial();
     
    }
    
    void DrawCustomGraph()
    {
    }
    /* void Heater2(byte HeaterRelay, int LowTemp, int HighTemp)
    {
    if (ReefAngel.Params.Temp[T2_PROBE] == 0) return; // Don't turn the heater on if the temp is reading 0
    if (ReefAngel.Params.Temp[T2_PROBE] <= LowTemp && ReefAngel.Params.Temp[T2_PROBE] > 0) ReefAngel.Relay.On(HeaterRelay); // If sensor 2 temperature <= LowTemp - turn on heater
    if (ReefAngel.Params.Temp[T2_PROBE] >= HighTemp) ReefAngel.Relay.Off(HeaterRelay); // If sensor 2 temperature >= HighTemp - turn off heater
    }
    void Heater1(byte HeaterRelay, int LowTemp, int HighTemp)
    {
    if (ReefAngel.Params.Temp[T1_PROBE] == 0) return; // Don't turn the heater on if the temp is reading 0
    if (ReefAngel.Params.Temp[T1_PROBE] <= LowTemp && ReefAngel.Params.Temp[T1_PROBE] > 0) ReefAngel.Relay.On(HeaterRelay); // If sensor 2 temperature <= LowTemp - turn on heater
    if (ReefAngel.Params.Temp[T1_PROBE] >= HighTemp) ReefAngel.Relay.Off(HeaterRelay); // If sensor 2 temperature >= HighTemp - turn off heater
    }
    */
Image
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: RANet relay expansion not working

Post by cosmith71 »

Put this is in setup()

Code: Select all

ReefAngel.AddRANet();
--Colin
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: RANet relay expansion not working

Post by bencollinz »

cosmith71 wrote:Put this is in setup()

Code: Select all

ReefAngel.AddRANet();
--Colin
Thank you! Found it shortly after I asked, go figure.
Image
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: RANet relay expansion not working

Post by bencollinz »

grafxalien wrote:another question about the expansion. I just go back in town after getting it setup. Last night I noticed that every 10-20 min my refugium light would turn off for a second then right back on. This light is hooked up to the wireless relay expansion. I think the expansion is losing connection to RANET, turning it off then back on. The box is only ~3 feet away from the controller. Is there any way to check/fix this problem?
I'm having this issue as well. My main lights keep flashing.
Image
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: RANet relay expansion not working

Post by cosmith71 »

Did you try this?
rimai wrote:Open the enclosure box
Remove all screws to free up the board inside.
You should be able to pry the board from the outlets.
Pay attention to the Logo LED lead wires. Make sure to disconnect when separating the pcb from the outlets/box.
With the pcb in your hand, you will see the RANet Receiver
Detach and look underneath. One of the 6pin headers has a GND marking. That's the black wire of the programming cable you use to program RA.
Connect the programming cable to the RANet Receiver.
Go to Arduino and make sure to change the board to ReefAngel w/ optiboot
Load the code below to the RANet Receiver.

Code: Select all

#include <Wire.h>
#include <avr/eeprom.h>

#define BLUE_LED    9
#define WHITE_LED   10

#define BLUE_INTENSITY   255
#define WHITE_INTENSITY  255

#define RANET_MAX_SIZE  64
#define DISCONNECT_TIMEOUT  10000

#define LastFallback0  100 // Memory location for fallback storage

#define RANet_Down    0
#define RANet_OK      1

byte buffer_index;
byte buffer[128];
char buf[3];
byte bufint, bufsize;
byte RANetData[RANET_MAX_SIZE];
byte RANetCRC;
byte BlueChannel=0;
byte WhiteChannel=0;
byte RANet_Status=RANet_Down;
boolean cable_present=false;

unsigned long lastmillis=millis();
unsigned long lastcablecheck=millis();

void setup()
{
  pinMode(BLUE_LED,OUTPUT);
  pinMode(WHITE_LED,OUTPUT);
  Serial.begin(57600);
  Wire.onReceive(NULL);
  Wire.onRequest(NULL);
  Wire.begin();
  for (int a=0;a<RANET_MAX_SIZE; a++) // Clear array
    RANetData[a]=0; 
  Wire.beginTransmission(0x68);
  Wire.write(0);
  int a=Wire.endTransmission();
  cable_present=(a==0);
  // setup PCA9685 for data receive
  // we need this to make sure it will work if connected ofter controller is booted, so we need to send it all the time.
  Wire.beginTransmission(0x40);
  Wire.write(0);
  Wire.write(0xa1);
  Wire.endTransmission();
}

void loop()
{
  if (cable_present)
  {
    BlueChannel=100;
    WhiteChannel=0;
    analogWrite(WHITE_LED,WHITE_INTENSITY*WhiteChannel/100);
    analogWrite(BLUE_LED,BLUE_INTENSITY*BlueChannel/100);
  }
  else  
  {
    BlueChannel=0;
    WhiteChannel=0;
    while(Serial.available())
    {
      UpdateWhiteChannel();
      char c = Serial.read(); // Read each incoming byte
      buffer[buffer_index]=c; // store in the buffer array
      if (c==10) // if line feed we analyze the payload
      {
        if (buffer_index>25) // only need to analyse if buffer_index is greater than 25, otherwise the payload is broken or corrupt
          if (buffer_index==buffer[1]) // check if payload matches the length the controller sent
          {
            UpdateWhiteChannel();
            RANetCRC=0;
            for (int a=0; a<(buffer_index-2); a++) // calculate CRC
              RANetCRC+=buffer[a];
            UpdateWhiteChannel();
            if (RANetCRC==buffer[buffer_index-2]) // if CRC matches
            {
              UpdateWhiteChannel();
              for (int a=0; a<(buffer_index-2); a++) // Copy buffer to RANetData
                RANetData[a]=buffer[a];
              UpdateWhiteChannel();
              lastmillis=millis();
  //            Serial.print(millis());
  //            Serial.print("\t");
  //            Serial.println(RANetData[2]);
              for (int a=0;a<8;a++)
              {
                if (eeprom_read_byte((unsigned char *) LastFallback0+a)!=RANetData[10+a])
                {
                  eeprom_write_byte((unsigned char *) LastFallback0+a, RANetData[10+a]);
                }
                Wire.beginTransmission(0x38+a);
                Wire.write(~RANetData[2+a]);
                Wire.endTransmission();
              }
              for (int a=0;a<6;a++)
              {
                int newdata=(int)(RANetData[18+a]*40.95);
                Wire.beginTransmission(0x40);
                Wire.write(0x8+(4*a));
                Wire.write(newdata&0xff);
                Wire.write(newdata>>8);
                Wire.endTransmission();
              }
              UpdateWhiteChannel();
              RANet_Status=RANet_OK;
            }
          }
        buffer_index=255; // reset buffer index
      }
      UpdateWhiteChannel();
      if (buffer_index++>=128) buffer_index=0; // increment index of buffer array. reset index if >=128
    }
    if (millis()-lastmillis>DISCONNECT_TIMEOUT)
    {
      lastmillis=millis();
  //    Serial.println("Disconnected");
  //    Serial.print(millis());
  //    Serial.print("\t");
  //    Serial.println(RANetData[10]);
      for (int a=0;a<8;a++)
      {
        Wire.beginTransmission(0x38+a);
        Wire.write(~eeprom_read_byte((unsigned char *) LastFallback0+a));
        Wire.endTransmission();
      }
      RANet_Status=RANet_Down;
    }
    if (RANet_Status==RANet_Down)
    {
        BlueChannel=0;
        WhiteChannel=millis()%2000<1000?0:100;
        analogWrite(WHITE_LED,WHITE_INTENSITY*WhiteChannel/100);
        analogWrite(BLUE_LED,BLUE_INTENSITY*BlueChannel/100);
    }
  }
}

void UpdateWhiteChannel()
{
  WhiteChannel=sin(radians((millis()%7200)/40))*255;
  BlueChannel=255-(sin(radians((millis()%7200)/40))*255);
  analogWrite(WHITE_LED,WhiteChannel);
  analogWrite(BLUE_LED,BlueChannel);
}
Let me know if you have any questions.
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: RANet relay expansion not working

Post by bencollinz »

cosmith71 wrote:Did you try this?
rimai wrote:Open the enclosure box
Remove all screws to free up the board inside.
You should be able to pry the board from the outlets.
Pay attention to the Logo LED lead wires. Make sure to disconnect when separating the pcb from the outlets/box.
With the pcb in your hand, you will see the RANet Receiver
Detach and look underneath. One of the 6pin headers has a GND marking. That's the black wire of the programming cable you use to program RA.
Connect the programming cable to the RANet Receiver.
Go to Arduino and make sure to change the board to ReefAngel w/ optiboot
Load the code below to the RANet Receiver.
I just did this. We'll see if it helps.
Here are some pictures for others in the future:
"You should be able to pry the board from the outlets."
I was a little disappointed to see that ALL of these black boxes were not pushed onto the board all the way
1.jpg
1.jpg (296.9 KiB) Viewed 6746 times
there fixed it
2.jpg
2.jpg (313.12 KiB) Viewed 6746 times
"Pay attention to the Logo LED lead wires. Make sure to disconnect when separating the pcb from the outlets/box."
3.jpg
3.jpg (301.78 KiB) Viewed 6746 times
continued below...
Image
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: RANet relay expansion not working

Post by bencollinz »

rimai wrote:Open the enclosure box
Remove all screws to free up the board inside.
You should be able to pry the board from the outlets.
Pay attention to the Logo LED lead wires. Make sure to disconnect when separating the pcb from the outlets/box.
With the pcb in your hand, you will see the RANet Receiver
Detach and look underneath. One of the 6pin headers has a GND marking. That's the black wire of the programming cable you use to program RA.
Connect the programming cable to the RANet Receiver.
Go to Arduino and make sure to change the board to ReefAngel w/ optiboot
Load the code below to the RANet Receiver.
"With the pcb in your hand, you will see the RANet Receiver"
4.jpg
4.jpg (320.69 KiB) Viewed 6746 times
"Detach and look underneath. One of the 6pin headers has a GND marking. That's the black wire of the programming cable you use to program RA."
5.jpg
5.jpg (257.53 KiB) Viewed 6746 times
"Connect the programming cable to the RANet Receiver."
6.jpg
6.jpg (325.61 KiB) Viewed 6746 times
Image
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: RANet relay expansion not working

Post by bencollinz »

This still occurs. Just not as frequently.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: RANet relay expansion not working

Post by rimai »

Did you confirm that the box requires 10 seconds now to assume connection loss?
Roberto.
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: RANet relay expansion not working

Post by bencollinz »

rimai wrote:Did you confirm that the box requires 10 seconds now to assume connection loss?
yes. 10 seconds.
Image
Post Reply