Turn on relay when WL is at 100% or >?

Do you have a question on how to do something.
Ask in here.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

It doesn't seem to be working.
I have the ATO reservoir filled and I re-calibrated the sensor because even full it was reading 95%
It's now reading 100% on the RA menu and on my phone, but is reading 0 on the Portal and Port3 has not turned on.

Image

Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Yes you got the code right. Here's the scenario. The water level needs to be below the 100 percent mark and then hit 100 and it will then set stopTime to 3600 seconds in the future. Also found and error. it should be now()<stopTime not 3600. Carryover from the initial example. Sorry for always clutzing up on you. I code on my phone...
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

That looks like it did it after I fixed that last coding issue.

No problem with the mess ups, I just appreciate the help.

Besides I did figured some things (well 1) out on my own.

I'm starting to pick this up, but still have a long way to go.
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Turn on relay when WL is at 100% or >?

Post by binder »

Sacohen wrote:That looks like it did it after I fixed that last coding issue.

No problem with the mess ups, I just appreciate the help.

Besides I did figured some things (well 1) out on my own.

I'm starting to pick this up, but still have a long way to go.
no worries there. it is a continuous learning experience. i even have issues at times too! :-)

glad you were able to get things figured out.


Sent from my iPad mini
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Thanks. Curt. It was Lee that did it, but I was proud that I was able to figure out what was wrong when he mis-coded something. That's 1000x better then when I started in here.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

The final working code is...

Code: Select all

//Mix Kalkwasser
static unsigned long Kalk_Mixing = 0;

static unsigned long stopTime = 0;
static byte prevWL=0;

if (ReefAngel.WaterLevel.GetLevel(1)>=100 && prevWL<100) {
  stopTime=now()+3600; // Get time one hour from now.
}
prevWL = ReefAngel.WaterLevel.GetLevel(1); // Store the water level

if (now() < stopTime) { ReefAngel.Relay.On(Kalkwasser); } else { ReefAngel.Relay.Off(Kalkwasser); } 
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Lee thanks again for this code.
There seems to be some problems with it still.

When the Water Level reaches 0 the Kalkwasser pump (Port4) turns on.

That shouldn't happen because there is not enough water in the Reservoir to have it run without cavitating.

Also when the water is below 0 or at 0 for too long it starts reporting the WL at 200%.
This is not problem with the code I think it's an issue with the design of the WL sensors or when the ATO pulls more water and actually falls below the calibrated 0 level.

This causes another problem with the line of code that says and previous WL is less than 100, because it doesn't stay at less than 100.

I tried changing the code to equal to 100 and got "value required as left operand of assignment"

Code: Select all

static unsigned long Kalk_Mixing = 0;

static unsigned long stopTime = 0;
static byte prevWL=0;

if (ReefAngel.WaterLevel.GetLevel(1)=100 && prevWL<100) {   
  stopTime=now()+3600; // Get time one hour from now.
}
prevWL = ReefAngel.WaterLevel.GetLevel(1); // Store the water level

if (now() < stopTime) { ReefAngel.Relay.On(Kalkwasser); } else { ReefAngel.Relay.Off(Kalkwasser); } 
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

You need == that causes the error you had.

Its an issue with the water level sensor code. I'll have to check but yeah it wraps around to 200...and at 0 its probably jumping to 200 where you can't see it.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

OK. That did it.
I don't think it's jumping to 200% right away, but that would make sense because it gets to 0, jumps to 200 and turn on the port since it is above 100 like the code says to.

That 200% thing is going to cause an issue since it will not start the hour stirring process if the last level was not below 100.

This is the first step in automating my RO/DI and SW container refills.
My thought was when WL reaches 0% the RO/DI water turns on and starts filling whichever reservoir is low and calling for it to be turned on.

When it reaches 100% it shuts of the RO/DI maker and turns on the pump for an hour (Maybe 2 for the SW) and then the water in each reservoir is ready to use.

Obviously I would try to build in something that disables the ATO or AWC while the reservoir is refiling and mixing.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

I would not start anything at the 0% mark :) i'd even suggest recalibrating so that 0% has some amount of liquid in it. But yeah it's like debouncing any other sensors, you may not see it because the screen refreshes every 5 seconds i believe but the sensor definitely has some bounce in it so it could be bouncing to 200 and you wouldnt se it necessarily. We need to fix that part. Maybe need to change the result to an int so we can get a negative percent.

Another thing we can do is read the raw value from the sensor and check if we're lower than the calibrated minimum...i'm not sure that function exists, but I've wanted it a few times...
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Ok. Right now. I'm testing an issue I had with the multi WL dropping faster then it actually is. Roberto wanted me swap my single with my multi and see if it moves with the swap or it it stays.
I put that off while working on the dev libraries with you guys.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

No problem. Have to figure out the best way to solve the wrap around...constrain/negative number/something else...
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Ok. Thanks
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

So there is a function to get the raw value.

ReefAngel.WaterLevel.Read() and ReefAngel.WaterLevel.Read(byte Channel)

I took a quick look at the code and it's first doing a map and then a constrain, so I think the wrapping is happening first int the map function, because the constrain is from 0 to 200. So if it were less than 0 then it would be 0..
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

OK. You're speaking greek to me Lee, but it sounds like you can do something about it.
Again nothing major. When you can get to it.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

I dont have a solution yet. Although maybe I have an idea...just as I wrote that..

But for now you can do the read function above and compare it to the InternalMemory.WaterLevelMin_read() function to see if the raw uncalculated value is less than "0".
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Ok, I figured out the issue!!!

Roberto, in the WaterLevel::Convert function... why is t an "unsigned" long. Here's the issue. First we do a map of the value read from the sensor to the min/max calibrated values. We assign this to t (which is unsigned...) So, if the value read is less than 0 we will get a negative number. Since t is unsigned, this causes the number to wrap around and thus we get an extremely large number instead of a negative. Then when we do the constrain so that the number gets held within the 0-200 range it gets set to 200.

So the solution is to either convert the unsigned long t to just long t or we have to wrap the first map with the constrain so that it's constrained to a positive number before assigning it to t. If we do that, then t could really just be a byte instead of an unsigned long.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Ok, I know why t is an unsigned long, because your using t to also de-bounce the sensor and taking 20 readings in a row. Therefore to not change this behavior and not introduce any other unexpected behavior, I recommend we do:

t=constrain(map(t, WLmin,WLmax,0,100),0,200);

That should prevent having the negative wrap during the assignment to t since t will always be constrained. Also I would propose changing the range to 0-255 just because we can :) and in code would look better because level[x] is a byte. So the constrain rather than be an arbitrary range is ensuring we stay within the confines of our destination variable.

If you agree, I'll create a pull request tonight.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Turn on relay when WL is at 100% or >?

Post by rimai »

0-255 range is fine :)
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Sounds good. I'll patch it up tonight! Anyone able to help test it? My reservoir is still half full and I don't feel like siphoning all the water out... :)
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

I just filled mine yesterday, but I would think if I pull the pipe out of the reservoir that is the same as emptying the reservoir.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Yeah Steve, that'd work. I have no way to get to mine the way it's mounted. If you can test it that way, it would definitely help. I plan to load my controller with this too, but it will be a few days before I'm at that point to know it's working. It's an annoying bug because I have to manually put water in until it's back to 0 so my refill function will work :)
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

I'll be glad to test it when I get home tonight.
Let me know when the code is up.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Has the code been put up?
Is it in your branch Lee or has it been merged into the dev code?

Let me know and I'll test it.
It's a simple test should know right away if it works or not.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Just finished getting things cleaned up. Man I hate git still sometimes :)

Anyway, my branch is here: https://github.com/lnevo/Libraries/tree/waterlevelfix

And I made a pull request to Roberto. Needed to make sure the branch had all the fixes I made so far...
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Ok. Just finishing dinner.
I'll download it a bit.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Works great.
I really didn't even need to lift up my WL1 pipe to test it.
The other 3 WL sensors on the multi level sensor were all reading 0 before I even got back to my tank to pull the WL 1 pipe out of the sump.

I did it anyway as a double check and it's perfect. :D
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Sweet!!! I'm pretty pleased with this one :) as soon as my 16mo old goes to bed.. :)
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Putting a 16 month old to bed at 9:50? :o
I just put my 10 year old to bed at 9:30. :-)
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

He's insane. Hates his crib. Should have stuck with one ;) lol
Post Reply