All RANet relay boxes and dimming modules will need this update.
Symptom: your RANet relay box blinks white/blue very fast and causes the relay box to go into fallback.
If you would like to see the symptom, upload this 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 <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>
void setup()
{
ReefAngel.Init(); //Initialize controller
ReefAngel.Use2014Screen(); // Let's use 2014 Screen
ReefAngel.AddRANet(); // RANet Add-On Module
ReefAngel.Relay.On(Box1_Port2);
ReefAngel.Relay.On(Box1_Port4);
}
void loop()
{
ReefAngel.ShowInterface();
}
1. Open the relay box/dimming module enclosure
2. Locate the RANet module inside. 3. Remove it from the expansion module
4. Detach the Xbee radio. Be careful not to damage the pins of the radio. Be very gentle.
5. Connect the USB-TTL cable to the RANet module 6. Download the attached code and open the code on Arduino or copy and paste it from the bottom of the post
8. Change the board to "Reef Angel Controller w/ optiboot"
9. Upload the code
10. Make sure the code uploads and Arduino says "Done uploading" without errors
11. Disconnect the USB-TTL cable
12. Attach the Xbee radio
13. Place the RANet module back into the expansion module
14. Close the enclosure
15. Change the board back to "Reef Angel Plus"
16. Upload the code above to confirm that the firmware fixed the issue
This is the latest firmware code:
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 68
#define DISCONNECT_TIMEOUT 10000
#define LastFallback0 100 // Memory location for fallback storage
#define RANet_Down 0
#define RANet_OK 1
#define LIGHTNING 1 // Trigger value for lightning strike
#define TRIGGER 62 // Position in payload of trigger byte
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();
char lastc=0;
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 && lastc==13) // 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<12;a=a+2) // Step through the 12 bytes of dimming data
{
byte newdata=(RANetData[18+a]); //LSB
byte newdata1=(RANetData[18+a+1]); //MSB
Wire.beginTransmission(0x40);
Wire.write(0x8+(4*(a/2))); // Channels 0 through 5
Wire.write(newdata); // Write LSB
Wire.write(newdata1); // Write MSB
Wire.endTransmission();
}
UpdateWhiteChannel();
RANet_Status=RANet_OK;
}
}
buffer_index=255; // reset buffer index
}
lastc=c;
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);
}
}
if (RANetData[TRIGGER]==LIGHTNING) Lightning(); // Look for lightning trigger
RANetData[TRIGGER]=0; // Clear trigger byte.
}
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);
}
void Lightning()
{
int a=random(1,5); // Pick a number of consecutive flashes from 1 to 4.
for (int i=0; i<a; i++)
{
// Flash on
int newdata=4095;
Wire.beginTransmission(0x40); // Address of the dimming expansion module
Wire.write(0x8+(4*1)); // 0x8 is channel 0, 0x12 is channel 1, etc. I'm using channel 1.
Wire.write(newdata&0xff); // Send the data 8 bits at a time. This sends the LSB
Wire.write(newdata>>8); // This sends the MSB
Wire.endTransmission();
int randy=random(20,80); // Random number for a delay
if (randy>71) randy=((randy-70)/2)*100; // Small chance of a longer delay
delay(randy); // Wait from 20 to 69 ms, or 100-400 ms
// Flash off
Wire.beginTransmission(0x40); // Same as above
Wire.write(0x8+(4*1));
Wire.write(RANetData[20]); // Return to previous value
Wire.write(RANetData[21]);
Wire.endTransmission();
delay(random(30,50)); // Wait from 30 to 49 ms
}
}