Turn on relay when WL is at 100% or >?
Re: Turn on relay when WL is at 100% or >?
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.
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.
Re: Turn on relay when WL is at 100% or >?
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...
Re: Turn on relay when WL is at 100% or >?
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 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.
Re: Turn on relay when WL is at 100% or >?
no worries there. it is a continuous learning experience. i even have issues at times too!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.
glad you were able to get things figured out.
Sent from my iPad mini
Re: Turn on relay when WL is at 100% or >?
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.
Re: Turn on relay when WL is at 100% or >?
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); }
Re: Turn on relay when WL is at 100% or >?
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"
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); }
Re: Turn on relay when WL is at 100% or >?
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.
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.
Re: Turn on relay when WL is at 100% or >?
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.
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.
Re: Turn on relay when WL is at 100% or >?
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...
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...
Re: Turn on relay when WL is at 100% or >?
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.
I put that off while working on the dev libraries with you guys.
Re: Turn on relay when WL is at 100% or >?
No problem. Have to figure out the best way to solve the wrap around...constrain/negative number/something else...
Re: Turn on relay when WL is at 100% or >?
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..
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..
Re: Turn on relay when WL is at 100% or >?
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.
Again nothing major. When you can get to it.
Re: Turn on relay when WL is at 100% or >?
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".
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".
Re: Turn on relay when WL is at 100% or >?
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.
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.
Re: Turn on relay when WL is at 100% or >?
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.
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.
Re: Turn on relay when WL is at 100% or >?
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...
Re: Turn on relay when WL is at 100% or >?
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.
Re: Turn on relay when WL is at 100% or >?
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
Re: Turn on relay when WL is at 100% or >?
I'll be glad to test it when I get home tonight.
Let me know when the code is up.
Let me know when the code is up.
Re: Turn on relay when WL is at 100% or >?
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.
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.
Re: Turn on relay when WL is at 100% or >?
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...
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...
Re: Turn on relay when WL is at 100% or >?
Ok. Just finishing dinner.
I'll download it a bit.
I'll download it a bit.
Re: Turn on relay when WL is at 100% or >?
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.
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.
Re: Turn on relay when WL is at 100% or >?
Sweet!!! I'm pretty pleased with this one as soon as my 16mo old goes to bed..
Re: Turn on relay when WL is at 100% or >?
Putting a 16 month old to bed at 9:50?
I just put my 10 year old to bed at 9:30.
I just put my 10 year old to bed at 9:30.
Re: Turn on relay when WL is at 100% or >?
He's insane. Hates his crib. Should have stuck with one lol