Turn on relay when WL is at 100% or >?
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
Re: Turn on relay when WL is at 100% or >?
LOL. He wants to be with Daddy.