Page 1 of 1

Override relays

Posted: Mon Jan 14, 2013 10:07 am
by jsclownfish
Hi all,

I am working on this touchscreen http://forum.reefangel.com/viewtopic.ph ... 2&start=30 and I was planning to try to use a button to have off/on override of the relay switches like you can do from the web/portal/phoneapps. I was thinking I would need a series of if/then statements in my main and a set of variables early in the code to override the relay status. However, I'm thinking there must be something in the libraries that lets you override the relay status since none of us code for it, but we can all do it from the accessory apps. :?

Is there an easy way to do this?

Thanks,
Jon

Override relays

Posted: Mon Jan 14, 2013 10:28 am
by lnevo
The off/on masks should be perfect for that.

Re: Override relays

Posted: Mon Jan 14, 2013 10:51 am
by rimai
Nothing in the libraries yet.
I think the easiest is to just use the masks as lnevo mentioned

Re: Override relays

Posted: Mon Jan 14, 2013 11:34 am
by jsclownfish
Thanks. That should work. I did this to send the temp relay data to the second monitor (my original RA), but I didn't really understand the conversion sending the TempRelay byte to the 2nd monitor and it reading it as a bit mask. Since I'm trying to go the other way trying to send the mask to the controller, I'll have to learn a bit more about the bitmasks to figure out what byte to send to the main for each condition.

-Jon

Re: Override relays

Posted: Fri Jan 18, 2013 1:46 pm
by jsclownfish
I'm still struggling to understand :? how to send the correct byte of info as a mask command over I2C to turn off a specific port without effecting the others. It was easy with the RA secondary screen unit because I had the TempRelay functions on both sides to convert the byte sent. I actually have a couple projects in the works where I'd like to send a request to turn off or on a single port. The ezLCD touchscreen seems to read from the master RA just fine, but I want to enable the touchscreen buttons to turn off and on relay ports if possible with the mask. For example if I toggle a button to turn off port #1, but leave the others alone, how do I send that info to the main to make the correct mask? Thanks for your help...

-Jon

Re: Override relays

Posted: Fri Jan 18, 2013 2:20 pm
by jsclownfish
Would something like this work? ('borrowed' from the wifi library) I'd put this in the master and send the relay position and status if changed on the ezLCD button.

Code: Select all

void loop()

//other stuff

GetRelay();
if (lcdtype==0)  // Turn port off
   {
     if ( lcdrelay < 9 )
	{
	bitClear(ReefAngel.Relay.RelayMaskOn,lcdrelay-1);
	bitClear(ReefAngel.Relay.RelayMaskOff,lcdrelay-1);
	}
    else if (lcdtype==1)  // Turn port on
	{
	if ( lcdrelay < 9 )
	  {
	   bitSet(ReefAngel.Relay.RelayMaskOn,lcdrelay-1);
	   bitSet(ReefAngel.Relay.RelayMaskOff,lcdrelay-1);
	  }
        }
   } 
   
//end of loop

void GetRelay()  //relay status sent from ezLCD
{
  Wire.requestFrom(7,9);
  if(Wire.available())
  {
    for (int a=0;a<2;a++)
      LCDIn[a]=Wire.read();
  }
  lcdrelay=LCDIn[1];
  lcdtype=LCDIn[2];
}

Re: Override relays

Posted: Fri Jan 18, 2013 4:12 pm
by rimai
I think it works, but your brackets are not correct...
lcdtype==1 would never happen.
Also, to simplify things, forget about lcdrelay<9 check...
Just make sure to send less than 9
You also need a way to return back to auto.

Code: Select all

if (lcdtype==0)  // Turn port off
{
    bitClear(ReefAngel.Relay.RelayMaskOn,lcdrelay-1);
    bitClear(ReefAngel.Relay.RelayMaskOff,lcdrelay-1);
}
else if (lcdtype==1)  // Turn port on
{
    bitSet(ReefAngel.Relay.RelayMaskOn,lcdrelay-1);
    bitSet(ReefAngel.Relay.RelayMaskOff,lcdrelay-1);
} 
else if (lcdtype==2)  // Turn port Auto
{
    bitClear(ReefAngel.Relay.RelayMaskOn,lcdrelay-1);
    bitSet(ReefAngel.Relay.RelayMaskOff,lcdrelay-1);
} 


Re: Override relays

Posted: Sun Jan 20, 2013 12:12 pm
by jsclownfish
Thanks! Works perfectly. I am able to use the Touchscreen to toggle the relays. I just need to figure out how to get it to display multiple screens for both showing data from the main and controlling relay from the Touchscreen. The arLCD works at 38400 baud and is really awkward requiring delays in places to allow the screen to refresh.

-Jon