Page 1 of 1

WP40 on the ATO PWM & Custom code

Posted: Wed Jun 19, 2013 11:52 am
by oscarinw
Hello all,

I just wanted to share my experience in hooking up a Jebao WP40 to my RA via the ATO PWM port. Hopefully this will save someone some time in the future.

So I wanted to upgrade my tank flow and started getting curious about the WP40. From different forums and reviews, I gathered that it was worth the try and placed the order for this pump online.
After that, I had to figure out the way to connect it and make it work with the RA.

Here's the step by step of that:

1. Get the cable from RA. When you place the order, make sure to indicate that your cable is meant to be used with the ATO PWM because that port uses a different volt range than the light dimming PWMs on the relay box.

2. The cable is attached to the outer-most ATO pin. That's the dimmable one. Pump goes in the water :)

3. When I first hooked up my pump, it worked at (what looked like to be) full force. My fish looked like stray kites in the sky!

4. Upload your new code for controlling this pump.
For this, I had a lot of help from user 'lnevo'. He was amazing with me and explained everything thoroughly.
I used the 'template' of the ReefCrest Function and just made one change.

4.1 The way it's written, ReefCrest uses a random speed between an average speed and a deviation percentage. So if your avg. speed is 50 and your deviation is 10%, it will choose a random value between 40% and 60%. It will then run the pump in cycles that last 5 seconds at that power and after the 5 seconds, will choose a new random power value.
The original ReefCrest mode is defined as:

Code: Select all

byte ReefCrestMode(byte WaveSpeed, byte WaveOffset, boolean PulseSync)
{
  static unsigned long lastwavemillis=millis();
  static int newspeed=WaveSpeed;
  if ((millis()-lastwavemillis) > 5000)
  {
    if (random(100)<50) newspeed--; else newspeed++;
    newspeed=constrain(newspeed,WaveSpeed-WaveOffset,WaveSpeed+WaveOffset);
    newspeed=constrain(newspeed,0,100);
    lastwavemillis=millis();
  }  
  if (PulseSync)
    return newspeed;
  else
    return WaveSpeed-(newspeed-WaveSpeed);
}
The only part I wasn't too fond of on this mode was the fact that the duration of the cycle was always 5 seconds. So we modified it to make it a random value between 5 and 15 seconds.
It looked then like this:

Code: Select all

byte ReefCrestMode(byte WaveSpeed, byte WaveOffset, boolean PulseSync)
{
  static unsigned long lastwavemillis=millis();
  static int delay;
  static int newspeed=WaveSpeed;
  if ((millis()-lastwavemillis) > delay)
  {
    delay=random(5000,15000);
    if (random(100)<50) newspeed--; else newspeed++;
    newspeed=constrain(newspeed,WaveSpeed-WaveOffset,WaveSpeed+WaveOffset);
    newspeed=constrain(newspeed,0,100);
    lastwavemillis=millis();
  }  
  if (PulseSync)
    return newspeed;
  else
    return WaveSpeed-(newspeed-WaveSpeed);
}
With that, I just went ahead and changed the name of the mode so it doesn't conflict with your previously existing definitions in the library. How to change the name of the mode? All you do is change ReefCrestMode for WhatYouWant or any other preferred name. Looks like this now:

Code: Select all

byte WhatYouWant(byte WaveSpeed, byte WaveOffset, boolean PulseSync)
{
  static unsigned long lastwavemillis=millis();
  static int delay;
  static int newspeed=WaveSpeed;
  if ((millis()-lastwavemillis) > delay)
  {
    delay=random(5000,15000);
    if (random(100)<50) newspeed--; else newspeed++;
    newspeed=constrain(newspeed,WaveSpeed-WaveOffset,WaveSpeed+WaveOffset);
    newspeed=constrain(newspeed,0,100);
    lastwavemillis=millis();
  }  
  if (PulseSync)
    return newspeed;
  else
    return WaveSpeed-(newspeed-WaveSpeed);
}
4.2 Pasting this function in your code:
Just as explained by lnevo: "Just put it at the bottom on a new line or if you want you can put it in the global variable section. Either way it cant be inside any set of {}"
So I went ahead and pasted it directly above your "void loop ()" line

5 Invoking your function
Thanks to 'rimai', I was able to come-up with the line to invoke the WhatYouWant or old ReefCrest function.
Since you are hooking it up to your ATO PWM, it needs to be multiplied by a factor of 2.55.
It looked like this:

Code: Select all

pinMode(lowATOPin,OUTPUT);
analogWrite(lowATOPin,WhatYouWant(60,20,true)*2.55);
6. Including a parabola function to give stronger flow during the day and weaker at night:
With the help of 'lnevo' again, we were able to come up with this new function. It makes the pump start at 3am at an avg speed of 30 with a variance of 12% and 'peak' its power at 3pm with a power of 75% and a variance of 25%
The final code to be pasted on the "Custom Code' section:

Code: Select all

pinMode(lowATOPin,OUTPUT);   
analogWrite(lowATOPin, 2.55*WhatYouWant( PWMParabola(3,0,2,59,30,75,0), PWMParabola(3,0,2,59,12,25,0),true) );
Notice that the 2.55 factor was changed places but it shouldn't alter your results.

I really like this mode as it is truly random in duration, power and is variable throughout the 24 hours of the day.

I hope this helps someone in the future and you don't have to tie the forum gurus more than they already are.

Happy Reefing!

Re: WP40 on the ATO PWM & Custom code

Posted: Thu Jun 20, 2013 7:38 pm
by daniella3d
What would be the line for having it plugged through the daylight channel instead of the ATO?

Re: WP40 on the ATO PWM & Custom code

Posted: Thu Jun 20, 2013 8:26 pm
by lnevo
ReefAngel.PWM.SetDaylight( WhatYouWant( PWMParabola(3,0,2,59,30,75,0), PWMParabola(3,0,2,59,12,25,0),true) );

If your using 1.0.9 and the new DCP5/ump from the Wizard, you can do this:

if (ReefAngel.DCPump.Mode==Custom) {
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Speed=WhatYouWant( PWMParabola(3,0,2,59,ReefAngel.DCPump.Speed*.4,ReefAngel.DCPump.Speed,0), PWMParabola(3,0,2,59,ReefAngel.DCPump.Duration*.5,ReefAngel.DCPump.Duration,0),true);
} else {
ReefAngel.DCPump.UseMemory=true;
}

and then you can choose Custom from the portal.

Re: WP40 on the ATO PWM & Custom code

Posted: Thu Jun 20, 2013 8:28 pm
by lnevo
Oscar, I added ATO PWM support to the DCPump library, so you can use the wizard and you'll just have to add ReefAngel.DCPump.LowATOChannel=Sync; to activate it :)

If you use the code above you can choose custom from the portal or switch through all the modes.

http://forum.reefangel.com/viewtopic.php?p=28572#p28572

Re: WP40 on the ATO PWM & Custom code

Posted: Fri Jun 21, 2013 6:38 am
by cosmith71
What's the mod on the cable to run at 5V?

Re: WP40 on the ATO PWM & Custom code

Posted: Fri Jun 21, 2013 8:24 am
by rimai

Re: WP40 on the ATO PWM & Custom code

Posted: Fri Jun 21, 2013 9:29 pm
by oscarinw
lnevo wrote:Oscar, I added ATO PWM support to the DCPump library, so you can use the wizard and you'll just have to add ReefAngel.DCPump.LowATOChannel=Sync; to activate it :)

If you use the code above you can choose custom from the portal or switch through all the modes.

http://forum.reefangel.com/viewtopic.php?p=28572#p28572
Sweetness...
I haven't upgraded to the new set of libraries but I'm looking forward to seeing that.
Thanks again Lee!

Re: WP40 on the ATO PWM & Custom code

Posted: Tue Jun 25, 2013 10:37 am
by cosmith71
Hey Roberto,

I have a WP-25 on a 29G Biocube. Whenever the RA resets or I upload something the pump goes full blast and destroys my tank. Is there any way to avoid this? Any mod to the cable that can limit the top speed? I tried replacing the 10K resistor thinking it would halve the speed, but it doesn't run at all that way.

Thanks,

--Colin

Re: WP40 on the ATO PWM & Custom code

Posted: Tue Jun 25, 2013 10:43 am
by rimai
The only way to avoid this is to use a dimming expansion module, which keeps the same speed even when the head unit is being programmed.
By default, the channels go to 100% when it is being programmed and it's the way the chip is designed to be.

Re: WP40 on the ATO PWM & Custom code

Posted: Tue Jun 25, 2013 11:30 am
by cosmith71
Well, I don't know what happened, but it's working, although unexpectedly.

With the 10K resistor back in, the speed is contrained to half. The pump shuts down while programming now (unexpected, but fine).

This is using the Low ATO port, BTW.

--Colin

Re: WP40 on the ATO PWM & Custom code

Posted: Fri Aug 30, 2013 8:39 am
by kimacom
this is awesome thread,
that helps me a lot to understand and use it.
thanks much guys

Re: WP40 on the ATO PWM & Custom code

Posted: Mon Sep 23, 2013 3:41 pm
by ganjero
is there a way to check if this is working? if the speed is ramping up and down? will the portal ato low level change colors when running this?

Also,
How would I change this code for a pump connected to the ATO port?

Code: Select all

static time_t StartFeeding=0;
              if (ReefAngel.DisplayedMenu==FEEDING_MODE)
                StartFeeding=now(); // if we entered feeding mode, register what time it was.
              if (now()-StartFeeding > 1800 && now()-StartFeeding < 5400) // if feeding started between 1800 and 5400 seconds
                ReefAngel.PWM.SetActinic(100);
              else   
                ReefAngel.PWM.SetActinic(45);
Thanks

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 5:20 am
by ganjero
any input on the above?

Thanks

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 7:57 am
by rimai
The code you posted is for feeding mode.
Not sure what you are asking.
The way to test is load into the controller and check your pump.

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 8:14 am
by Amos Poh
( PWMParabola(3,0,2,59,30,75,0), PWMParabola(3,0,2,59,12,25,0),true) );

Hi can anyone explain what the number means so i can alter to my preference?
Thanks :)

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 9:03 am
by ganjero
rimai wrote:The code you posted is for feeding mode.
Not sure what you are asking.
The way to test is load into the controller and check your pump.
Roberto,

Sorry if I was not clear. This code controls a pump that run a 45% all the time, and at 100% for one hour starting 30min after triggering feed mode.

My question is how do I modify this code to do this for a pump controlled through the ATO port instead of the Actinic port as shown in the code.

Code: Select all

static time_t StartFeeding=0;
              if (ReefAngel.DisplayedMenu==FEEDING_MODE)
                StartFeeding=now(); // if we entered feeding mode, register what time it was.
              if (now()-StartFeeding > 1800 && now()-StartFeeding < 5400) // if feeding started between 1800 and 5400 seconds
                ReefAngel.PWM.SetActinic(100);
              else   
                ReefAngel.PWM.SetActinic(45);
Thank you,

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 9:54 am
by rimai
It's in the OP.
Use something like this to set the ATO port to what you want:

Code: Select all

pinMode(lowATOPin,OUTPUT);
analogWrite(lowATOPin,45*2.55);
The example above sets it to 45%

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 10:10 am
by rimai
Amos Poh wrote:( PWMParabola(3,0,2,59,30,75,0), PWMParabola(3,0,2,59,12,25,0),true) );

Hi can anyone explain what the number means so i can alter to my preference?
Thanks :)
Check here:
http://www.easte.net/RA/html/_globals_8 ... de5873f8d6

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 2:07 pm
by ganjero
rimai wrote:It's in the OP.
Use something like this to set the ATO port to what you want:

Code: Select all

pinMode(lowATOPin,OUTPUT);
analogWrite(lowATOPin,45*2.55);
The example above sets it to 45%
Roberto,

Does this

Code: Select all

pinMode(lowATOPin,OUTPUT);
need to be written everetime I modify the speed? or can I write once somewhere in the code and then do different speeds with the second line? Like this
The xxxxxxx are other lines in the code

Code: Select all

xxxxxxxx
         xxxxxxx
         pinMode(lowATOPin,OUTPUT)
         xxxxxxxx
         xxxxxxxx
 if (ReefAngel.DisplayedMenu==FEEDING_MODE)
                StartFeeding=now(); // if we entered feeding mode, register what time it was.
              if (now()-StartFeeding > 1800 && now()-StartFeeding < 5400) // if feeding started between 1800 and 5400 seconds
               analogWrite(lowATOPin,100*2.55);
              else
                analogWrite(lowATOPin,75*2.55);
Thank you again

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 3:49 pm
by lnevo
I'm pretty sure it only needs to be done once.

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 4:14 pm
by rimai
I think you can do once, but just in case keep it everytime you use digitalWrite, just because the ATO port is setup as input and not as output.

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 4:43 pm
by lnevo
Roberto wonder if that may be the problem for the person who had issue in feeding/wc mode with the lowAto.

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 4:52 pm
by rimai
Humm... not sure

Re: WP40 on the ATO PWM & Custom code

Posted: Wed Sep 25, 2013 6:22 pm
by ganjero
Well I tried this

Code: Select all

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
                StartFeeding=now(); // if we entered feeding mode, register what time it was.
              if (now()-StartFeeding > 1800 && now()-StartFeeding < 5400) // if feeding started between 1800 and 5400 seconds
               pinMode(lowATOPin,OUTPUT)
               analogWrite(lowATOPin,100*2.55);
              else
                pinMode(lowATOPin,OUTPUT)
                analogWrite(lowATOPin,75*2.55);
and got an error on "else" - it says "there is not an if" before

so I just changed it to this, and it's working fine

Code: Select all

   ....
            ReefAngel.StandardLights( Port1,14,0,19,0 );
            ReefAngel.StandardLights( Port2,15,0,20,0 );
            ReefAngel.StandardLights( Port3,19,55,22,0 );
            ReefAngel.StandardLights( Port4,14,0,20,15 );
            ReefAngel.StandardHeater( Port5,780,785 );
            ReefAngel.StandardFan( Port6,780,800 );
            ReefAngel.StandardLights( Box1_Port5,22,0,16,0 );
            ReefAngel.DCPump.UseMemory = true;
            pinMode(lowATOPin,OUTPUT);
            ....
            static time_t StartFeeding=0;
              if (ReefAngel.DisplayedMenu==FEEDING_MODE)
                StartFeeding=now(); // if we entered feeding mode, register what time it was.
              if (now()-StartFeeding > 1800 && now()-StartFeeding < 5400) // if feeding started between 1800 and 5400 seconds
               analogWrite(lowATOPin,100*2.55);
              else
                analogWrite(lowATOPin,60*2.55);
             ....
            

Re: WP40 on the ATO PWM & Custom code

Posted: Fri Mar 27, 2015 11:39 pm
by 89delta
What's the difference between the regular cables and the ATO cable for jebao?

Re: WP40 on the ATO PWM & Custom code

Posted: Sat Mar 28, 2015 1:23 am
by cosmith71
You have to remove a resistor (surface mount) on the cable for it to work properly with the 5V ATO signal. There's a thread around here somewhere that points it out.

--Colin

Re: WP40 on the ATO PWM & Custom code

Posted: Sat Mar 28, 2015 6:41 am
by 89delta
Thanks, found it.