Author Topic: Sprinkler Mote - IOShield  (Read 13841 times)

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Sprinkler Mote - IOShield
« on: August 29, 2016, 12:10:03 PM »
Felix,

I purchased the IOShield for my sprinkler controller, 16 zone version of Felix's, and everything is soldered, programmed, and wired.  Works great!  Now on to my issue;

Like Felix's, there is an extra triac which controls MV terminals on the bottom terminal strip.  This I believe stands for "Main Valve".  I use this in my system, being on well water, to control a relay that turns on a Rid-O-Rust system pump.  This MV was programmed in the controller to come on whenever zones 1-8 came on which pumps a solution into the line to help prevent rust stains.  Zones 1-8 are zones that are close to the driveway, sidewalk, and the brick of the house.

Reading thru the IOShield sketch there appears to be some code that only allows 1 zone on at a time.  Although I like that feature, I'm looking for suggestions (code) on the best way to allow zone 17, rid-o-rust relay, to come on with certain zones at the same time.  Hope this makes sense.

Any help would greatly be appreciated,
GM


« Last Edit: September 09, 2016, 01:49:54 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sprinkler Mote
« Reply #1 on: August 29, 2016, 12:16:15 PM »
See these functions, notice how the functions simply shift out the zone # you give them, basically they are internal functions to the sketch but nothing stops you from sending out multiple zones at the same time. The AllOn illustrates how this is done - apply the latch, shift out all 1s, then release the latch to apply those changes. The registersWriteBit writes a single bit, ensuring all other bits are 0 (ie only 1 zone is active). This could be modified to allow a combination of 1s to be set.

Code: [Select]
void registersAllOn() {
  digitalWrite(LATCHPIN, LOW);
  for(byte i=0;i<REGISTERCOUNT;i++)
    shiftOut(DATAPIN, CLOCKPIN, MSBFIRST, 0xFF); 
  digitalWrite(LATCHPIN, HIGH);
}

//writes a single bit to a daisy chain of up to 32 shift registers (max 16 IOShields) chained via LATCHPIN, CLOCKPIN, DATAPIN
void registersWriteBit(byte whichPin) {
    byte bitPosition = whichPin % 8;
    int zeroFills = (REGISTERCOUNT - 1) - (whichPin/8);

    if (zeroFills<0) { //whichPin was "out of bounds"
      DEBUGln("requested bit out of bounds (ie learger than available register bits to set)");
      registersClear();
      return;
    }

    digitalWrite(LATCHPIN, LOW);   
    for (byte i=0;i<zeroFills;i++)
      shiftOut(DATAPIN, CLOCKPIN, MSBFIRST, 0x0);
   
    byte byteToWrite = 0;
    bitSet(byteToWrite, bitPosition);
    shiftOut(DATAPIN, CLOCKPIN, MSBFIRST, byteToWrite);
   
    for (byte i=0;i<REGISTERCOUNT-zeroFills-1;i++)
      shiftOut(DATAPIN, CLOCKPIN, MSBFIRST, 0x0);
    digitalWrite(LATCHPIN, HIGH);
}

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #2 on: August 29, 2016, 12:23:30 PM »
Felix,

Thanks for the quick response.  New to this code stuff so I will read your response over a few times to try and make sense of it.

Appreciate your help,
GM

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sprinkler Mote
« Reply #3 on: August 29, 2016, 12:38:36 PM »
Ok let me know if you need more help, I am quite tied up but will try to advise as time permits.
Anyhow i guess it all comes down to how you want to control that extra MV output, with any other station(s) or separately (independently).
If it's always the same output and it's always just one, then you could alter the existing function that sets 1 zone, and add a boolean parameter (MVon) that is AND-ed to the resulting byte which gets shifted out to the IOShield. (we're assuming here you will use up to the 16 available OUTPUTs of the IOShield). Otherwise this could be a 17th output which you could set on any Moteino pin, or perhaps chain another IOShield to obtain 32 total outputs, etc.

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #4 on: August 29, 2016, 02:26:14 PM »
Felix,

I appreciate your time so whenever you have the time.

I read your first response and I think I understand the AllOn, 0xff writes 8 zero's?

Still confused with the registerWriteBit though.

Ok, so I'm using 14 of the 16 available zones.  I can use zone 15 or 16 for the MV if you think that would be easier.

The MV triac is labeled  Q17 on the sprinkler circuit board.  Yours would be Q13.  So let's say we use zone 15 for the MV; I would need z15 to come on whenever zones 1 thru 8 were on.

I would like to be able to edit which zones triggered z15.

Thanks,
GM

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #5 on: August 29, 2016, 06:42:52 PM »
Ok, so I'm using 14 of the 16 available zones.  I can use zone 15 or 16 for the MV if you think that would be easier.

The MV triac is labeled  Q17 on the sprinkler circuit board.  Yours would be Q13.  So let's say we use zone 15 for the MV; I would need z15 to come on whenever zones 1 thru 8 were on.

Just to add some clarity to what I was thinking in the statement above.

I'm only using 14 of the 16 available zones in the sprinkler controller.  So I would have the 2 extra outputs on the IOShield that can be used.  So if it would be easier, code wise, to take output 15 of the IOShield and wire it to Q17 (MV triac) of the sprinkler controller.  Whatever way you think is best would be appreciated.

Thanks,
GM

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sprinkler Mote
« Reply #6 on: August 30, 2016, 09:31:10 AM »
0xFF is hexadecimal and is == 1s in binay.
0x00 is all 0s, 0xAA is 1010101...
I would keep it simple at the sketch side. Just add a parameter to the zone setting function: (..., boolean z15ON).
Before shifting out the 2 bytes to the registers, AND the last bit of the second byte (corresponds to z15) with this boolean parameter.

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #7 on: August 30, 2016, 10:30:35 AM »
I would keep it simple at the sketch side. Just add a parameter to the zone setting function: (..., boolean z15ON).
Before shifting out the 2 bytes to the registers, AND the last bit of the second byte (corresponds to z15) with this boolean parameter.

Felix,

Thanks for your time.

I have lots more reading to do before any of this makes sense.  Sorry for the ignorance

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #8 on: September 06, 2016, 08:55:11 AM »
So if I was to go with your suggestion, would z15ON turn on every time it see's z1-z8 turn on?  Meaning if I was to turn on z1 manually, would z15ON turn on..  or if z1 was in a schedule, would z15ON turn on?

Still trying to figure this out

Thanks

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sprinkler Mote
« Reply #9 on: September 06, 2016, 09:55:17 AM »
So if I was to go with your suggestion, would z15ON turn on every time it see's z1-z8 turn on?  Meaning if I was to turn on z1 manually, would z15ON turn on..  or if z1 was in a schedule, would z15ON turn on?
It would do that if you tell it to in some way, ie call the suggested function with (..., true) parameters.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sprinkler Mote
« Reply #10 on: September 06, 2016, 10:32:56 AM »
BTW there's a function which you could also use to write anything to the shift registers:

Code: [Select]
void registerWriteBytes(const void* buffer, byte byteCount)

But this requires some bit shifting and using a byte buffer and usually pointers scare people really bad.
Why don't you just use another Moteino digital pin to set your Z15 conditionally based on what zone is turned ON at one time?

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #11 on: September 06, 2016, 04:24:44 PM »

Why don't you just use another Moteino digital pin to set your Z15 conditionally based on what zone is turned ON at one time?

This sounds easier for the newbie.  How would you activate that pin when zones 1 thru 8 were activated?

Thanks Felix

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #12 on: September 06, 2016, 04:35:24 PM »
Also, would the pin on the moteino need to be set "low" to turn on the triac.  (Same controller as you)

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sprinkler Mote
« Reply #13 on: September 06, 2016, 04:51:18 PM »
One way is to check in void zoneON(byte which).
Something like...

Code: [Select]
if (which >0 && which < N) { digitalWrite(moteinoPin, HIGH); } else { digitalWrite(pin, LOW); } 

It's going to be set HIGH in code, like the outputs of the IOShield. How you wire it makes it biased such that the TRIACs will be activated.

sparky

  • Sr. Member
  • ****
  • Posts: 296
  • Country: us
Re: Sprinkler Mote
« Reply #14 on: September 06, 2016, 05:50:42 PM »
So that would be entered under the following section somewhere?

//writes a single bit to a daisy chain of up to 32 shift registers (max 16 IOShields) chained via LATCHPIN, CLOCKPIN, DATAPIN