Universal Relay with RA*

New members questions
Post Reply
aensor
Posts: 7
Joined: Wed Dec 20, 2017 3:53 am

Universal Relay with RA*

Post by aensor »

Hi,
I've a new ReefAngel Star controller and an having a bit of difficulty with getting it to control my universal relay. I'm supplying power to the relay (and it shows power), and have the controller set with a few ports to "always on", but none of the ports on the relay are supplying power (even though the code deployed via the web wizard shows the ports as on). My laptop does pick up the relay as a USB device (but unknown device without appropriate driver), even though the miniUSB connection on the relay seems a little loose, so the USB-miniUSB cable seems fine.
Is there a particular position for the three dip switches on the relay (or a doc that describes how they should be set) or only one of the two USB ports on the controller that must be specifically used?
I did notice that I needed ferrite cores around the controller and the relay USB cables to prevent getting locked in a bus error each day (but I'm running both cables alongside each other through a small hole so that's not a big surprise).
Thanks for any advice.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Universal Relay with RA*

Post by rimai »

The relay box is supposed to be connected to the RA* and not to your computer.
Leave the dip switches all on the up position. That is ID #1 and I'm assuming your code uses Box1_PortX, right?
Roberto.
aensor
Posts: 7
Joined: Wed Dec 20, 2017 3:53 am

Re: Universal Relay with RA*

Post by aensor »

Yes, indeed the RA* is connected to the relay via a USB-miniUSB cable (and there's a separate microUSB from the controller to its own power supply). I only connected the relay cable to a laptop temporarily to ensure the cable and relay miniUSB connector were not faulty. The web wizard produces code including this snippet:
// Ports that are always on
ReefAngel.Relay.On( Box1_Port5 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
ReefAngel.Relay.On( Box1_Port8 );
The GUI "Exp. Relay Box 1" shows those four ports in green. The relay is being supplied 240V and the power light on the relay shows power is on, but there's no power being supplied by any of the eight relay ports even when I put all three dipswitches in "on" (or instead all not in "on") - by "up" do you mean on or off?
The only thing I may have done differently was use a 2 meter USB-miniUSB cable (but I've tried another too) and connected ferrite cores to stop a frequent bus error.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Universal Relay with RA*

Post by rimai »

Upload this code to RA*:

Code: Select all

/**
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr, 
void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1, true);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,HEX);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}

#define sbi(port,bitnum)		port |= _BV(bitnum)
#define cbi(port,bitnum)		port &= ~(_BV(bitnum))

#define i2cMux  0x70

#define i2cMuxEnable  43

byte start_address = 1;
byte end_address = 128;

byte muxpresent=0;
// standard Arduino setup()
void setup()
{
  Wire.begin();
  pinMode(7,OUTPUT);
  Serial.begin(57600);
  DDRH|=(1<<2); // Port PH2 output (Exp Bus Power)
  cbi(PORTH,2); // Turn on exp bus power
  pinMode(i2cMuxEnable,OUTPUT);
  digitalWrite(i2cMuxEnable,LOW);
  delay(1000);
  digitalWrite(i2cMuxEnable,HIGH);
  delay(100);
  Wire.beginTransmission(i2cMux);
  Wire.write(0xf);
  muxpresent=Wire.endTransmission();
  delay(100);
  
  if(muxpresent!=0)
  {
    Serial.println(muxpresent);
    Serial.println("I2C Mux not found");
  }
  else
  {
    Wire.beginTransmission(i2cMux);
    Wire.requestFrom(i2cMux, 1);
    delay(100);
    if (Wire.available())
    {
      byte channels=Wire.read();
      Serial.println(channels);
      if (channels==0xf)
        Serial.println("All channels active");
      else
        Serial.println("Error setting channels");
    }
    else
    {
      Serial.println("No response from I2C Mux");
    }
    Wire.endTransmission();
    
    Serial.println("I2CScanner ready!");
  
    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,DEC);
    Serial.print(" to ");
    Serial.print(end_address,DEC);
    Serial.println("...");
  
    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );
  
    Serial.println("\ndone");
  }
}

// standard Arduino loop()
void loop() 
{
  // Nothing to do here, so we'll just blink the built-in LED
  digitalWrite(7,HIGH);
  delay(300);
  digitalWrite(7,LOW);
  delay(300);
}
You will need a serial monitor such as putty, tera term or Arduino IDE.
Open the serial monitor at 57600 baud.
Send the log.
Roberto.
aensor
Posts: 7
Joined: Wed Dec 20, 2017 3:53 am

Re: Universal Relay with RA*

Post by aensor »

Done, but I just get the message:

Code: Select all

2
I2C Mux not found
I also get the same log when I also have the salinity expansion connected, even though I know that does work (as I see its readings in the controller GUI whenever its connected).
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Universal Relay with RA*

Post by rimai »

Sorry.
Wrong code :(

Code: Select all

/**
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr, 
void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1, true);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,HEX);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}

#define sbi(port,bitnum)		port |= _BV(bitnum)
#define cbi(port,bitnum)		port &= ~(_BV(bitnum))


byte start_address = 1;
byte end_address = 128;

// standard Arduino setup()
void setup()
{
  Wire.begin();
  pinMode(7,OUTPUT);
  Serial.begin(57600);
  DDRH|=(1<<2); // Port PH2 output (Exp Bus Power)
  cbi(PORTH,2); // Turn on exp bus power
  pinMode(39,OUTPUT);
  pinMode(40,OUTPUT);
  pinMode(41,OUTPUT);
  digitalWrite(39,HIGH);
  digitalWrite(40,HIGH); 
  digitalWrite(41,HIGH); 
  Serial.println("\nI2CScanner ready!");

  Serial.print("starting scanning of I2C bus from ");
  Serial.print(start_address,DEC);
  Serial.print(" to ");
  Serial.print(end_address,DEC);
  Serial.println("...");

  // start the scan, will call "scanFunc()" on result from each address
  scanI2CBus( start_address, end_address, scanFunc );

  Serial.println("\ndone");
}

// standard Arduino loop()
void loop() 
{
  // Nothing to do here, so we'll just blink the built-in LED
  digitalWrite(7,HIGH);
  delay(300);
  digitalWrite(7,LOW);
  delay(300);
}

Roberto.
aensor
Posts: 7
Joined: Wed Dec 20, 2017 3:53 am

Re: Universal Relay with RA*

Post by aensor »

Sorry for the delayed response, work does get in the way sometimes...

I believe things are getting sorted, the three dip switches are all set to "on", I've replaced the miniUSB cable again (as it seems it was faulty and later totally failed), and put the ferrite cores back on. Now my relay has power and I can toggle the power on/off using the controller GUI, so the controller now does communicate with the relay.

With the relay and the salinity expansion connected the code now gives the following output:

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       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 found!         addr: 39         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       addr: 4A       addr: 4B
addr: 4C       addr: 4D found!  addr: 4E        addr: 4F        addr: 50
addr: 51       addr: 52       addr: 53       addr: 54        addr: 55
addr: 56       addr: 57       addr: 58       addr: 59        addr: 5A
addr: 5B       addr: 5C       addr: 5D       addr: 5E        addr: 5F
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
done
Post Reply