Hoping someone can help me out here. I have been trying to get a Low\high temp display to work on my controller. The High temp works just fine. The low temp ALWAYS reads 0. I have copied the relevant code below. I have tried this multiple different ways. no matter what I do the Low temp always reads 0 on the display.
int T1MinTemp=9999;
int T1MaxTemp=1;
int T1Temp=1;
T1Temp=ReefAngel.Params.Temp[T1_PROBE];
if ( T1Temp > T1MaxTemp ) T1MaxTemp = T1Temp;
if ( T1Temp < T1MinTemp ) T1MinTemp = T1Temp;
//lines of code that show the variables on the display from my screen section below
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,76, "SAL:" );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,60,76, "L" );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,90,76, "H" );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,76, ReefAngel.Params.Salinity );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,69,76, T1MinTemp );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,98,76, T1MaxTemp );
OMG I am so f'ing pissed right now! I just spent an hour and a half typing out a walk through of this code process and when I hit post I was no longer logged in and LOST IT ALL! GRRRRR
OK lucky I had a big section in my clipboard. So it was not too painful to reconstruct. lol
Thanks for the reply.
I'm trying to understand. I am not sure I understand how "if !=0" will help. This means if not equal to 0 do something correct? like run the comparison lines... Even when starting if my variable was somehow 0 (which it should not be because I set them to 9999 and 1 when I initialized them) I don't know how it would matter. As soon as the variable is something other than 0 (the first probe read which happens before the display, it should work correctly anyhow no? The High Temp display works fine and has always worked fine. It has been for over a year, but the low temp has NEVER worked. ALWAYS shows 0 ALWAYS! I have even reversed my comparisons, tried multiple ways to compare etc. test for low temp first then high and also test for high temp first then low. Makes no difference. The low temp is ALWAYS displayed as 0.
Below is how I understand the code and maybe I just don't understand... But here is a walk through on how I interpret the code as working through 4 loops...
int T1LowTemp=9999; //initializes as an integer and sets initial value to 9999 a higher than normal value.
int T1HighTemp=1; //initializes as an integer and sets initial value to 1 a lower than normal value.
int T1Read=1; //initializes as an integer and sets initial value to 1.
-----------------
above is all in my init's just under my includes at the top of my sketch.
-----------------
-----------------
Loop1 Pass (lets say its 75.0 degrees (750) in the tank)
-----------------
T1Read = ReefAngel.Params.Temp[T1_PROBE]; //reassigns T1Read to whatever the libs state the current temp from the probe is as the code executes this line... for loop1 pass lets say 750 (75.0 degrees)
T1LowTemp = min(T1LowTemp, T1Read); // Compares T1LowTemp (9999 from inits) to T1Read (750) and sets T1LowTemp to now equal 750 because it is the min of the two in loop1 pass.
T1HighTemp = max(T1HighTemp, T1Read); // Compares T1HighTemp (1 from inits) to T1Read (750) and sets T1HighTemp to now equal 750 because it is the max of the two in loop1 pass.
//lines of code that show the variables on the display from my screen section
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,69,76, T1LowTemp ); //this line should display T1LowTemp (now 750) on the LCD screen in loop1 pass.
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,98,76, T1HighTemp ); //this line should display T1HighTemp (also 750) on the LCD screen in loop1 pass.
-----------------
Loop2 Pass (lets say its now 74.0 degrees (740) in the tank)
-----------------
T1Read = ReefAngel.Params.Temp[T1_PROBE]; //reassigns T1Read to whatever the libs state the current temp from the probe is as the code executes this line... for (loop2 pass) lets say 740 (74.0 degrees)
T1LowTemp = min(T1LowTemp, T1Read); // Compares T1LowTemp (now 750 from loop1) to T1Read (now 740) and sets T1LowTemp to now equal 740 because it is the min of the two in loop2 pass.
T1HighTemp = max(T1HighTemp, T1Read); // Compares T1HighTemp (now 750 from loop1) to T1Read (now 740) and sets T1HighTemp to now equal 750 (again for loop2) because it is the max of the two in loop2 pass.
//lines of code that show the variables on the display from my screen section
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,69,76, T1LowTemp ); //this line should display T1LowTemp (now 740) on the LCD screen in loop2 pass.
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,98,76, T1HighTemp ); //this line should display T1HighTemp (still 750) on loop pass2.
-----------------
Loop3 Pass (lets say its now 76.0 degrees (760) in the tank)
-----------------
T1Read = ReefAngel.Params.Temp[T1_PROBE]; //reassigns T1Read to whatever the libs state the current temp from the probe is as the code executes this line... for (loop3 pass) lets say 760 (76.0 degrees)
T1LowTemp = min(T1LowTemp, T1Read); // Compares T1LowTemp (still 740 from loop2) to T1Read (now 760) and sets T1LowTemp to again equal 740 because it is the min of the two in loop3 pass.
T1HighTemp = max(T1HighTemp, T1Read); // Compares T1HighTemp (still 750 from loop2) to T1Read (now 760) and sets T1HighTemp to now equal 760 because it is the max of the two in loop3 pass.
//lines of code that show the variables on the display from my screen section
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,69,76, T1LowTemp ); //this line should display T1LowTemp (still 740) on the LCD screen in loop3 pass.
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,98,76, T1HighTemp ); //this line should display T1HighTemp (now 760) on loop pass3.
-----------------
Loop4 Pass (lets say its now 73.0 degrees (730) in the tank)
-----------------
T1Read = ReefAngel.Params.Temp[T1_PROBE]; //reassigns T1Read to whatever the libs state the current temp from the probe is as the code executes this line... for (loop4 pass) lets say 730 (73.0 degrees)
T1LowTemp = min(T1LowTemp, T1Read); // Compares T1LowTemp (now 740 from loop3) to T1Read (now 730) and sets T1LowTemp to now equal 730 because it is the min of the two in loop4 pass.
T1HighTemp = max(T1HighTemp, T1Read); // Compares T1HighTemp (still 760 from loop3) to T1Read (now 730) and sets T1HighTemp to now equal 760 (again) because it is the max of the two in loop3 pass.
//lines of code that show the variables on the display from my screen section
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,69,76, T1LowTemp ); //this line should display T1LowTemp (now 730) on the LCD screen in loop4 pass.
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,98,76, T1HighTemp ); //this line should display T1HighTemp (still 760 from loop3) on loop pass4.
----------------
etc.
----------------
etc.
----------------
etc.
----------------
Sensors are tricky and you dont see the milisecond readings that happen when the screen redraws every few seconds. You are iniializing the low temp variable to 1 but of the T1 reading ever hits 0 for just one blip it will show 0 always. Thats why i said to do an if on the real temp probe reading and if it's 0 ignore it. I'm not at my computer but i'll try and post in code what i mean tomorrow.
lnevo wrote:Sensors are tricky and you dont see the milisecond readings that happen when the screen redraws every few seconds. You are iniializing the low temp variable to 1 but of the T1 reading ever hits 0 for just one blip it will show 0 always. Thats why i said to do an if on the real temp probe reading and if it's 0 ignore it. I'm not at my computer but i'll try and post in code what i mean tomorrow.
he could even look in the libraries in the display updating and we use code to prevent those sudden spikes. i dont remember where it is off hand but it is in the main reefangel class and in the showinterface function i think.
lnevo wrote:Sensors are tricky and you dont see the milisecond readings that happen when the screen redraws every few seconds. You are iniializing the low temp variable to 1 but of the T1 reading ever hits 0 for just one blip it will show 0 always. Thats why i said to do an if on the real temp probe reading and if it's 0 ignore it. I'm not at my computer but i'll try and post in code what i mean tomorrow.
I see what you are saying now... if my T1Read variable is EVER set to 0 even for 1 loop cycle it will drop my low temp down to 0 and it will stay there until it goes negative or the controller resets. After all it is lower, AND technically the code would be working correctly. All I need is one 0 to be caught on the probe by the T1Read line of code. However if I still follow that logic and include an if not 0 a very similar thing will happen if the T1Read line of code catches a 1 or a 5 or even a 10, an unrealistically low temp. I already know my probe occasionally goes to 1390+ once in a while it has been causing my overheat to trip up until I updated my libs. However when I updated my libs my high temp has not been displaying 139 degrees lately. Just seems odd that the high temp seems to work fine and the low temp doesn't work.
lnevo wrote:Sensors are tricky and you dont see the milisecond readings that happen when the screen redraws every few seconds. You are iniializing the low temp variable to 1 but of the T1 reading ever hits 0 for just one blip it will show 0 always. Thats why i said to do an if on the real temp probe reading and if it's 0 ignore it. I'm not at my computer but i'll try and post in code what i mean tomorrow.
he could even look in the libraries in the display updating and we use code to prevent those sudden spikes. i dont remember where it is off hand but it is in the main reefangel class and in the showinterface function i think.
Sent from my iPad mini
Yes, these spikes have been what was causing my overheat to trip on a daily basis. Seems much better with the 1.1.0 libs for the high temp. is it common for the probe to throw out 0's on a frequent basis?
Think I will try the if not 0 to see what happens. I also will try another probe that has not been sitting in saltwater for almost two years, maybe it will have less "jitter" and I can see something other than a 0 on the low side.
What you can do too is average out the sampling and look at the average low temp over x samples and then do your comparison. You might still need to drop 0 values but lets see what happens with your check let me know if you still need sample code.
With the if not 0 the code works. somehow in the early loops through the code it was always getting a 0 first and setting the low to 0. still having some weirdness. When I took the probe out of the tank and let it float in the air the low temp drifted all the way down to 592 as a low (its 77 degrees in the room (or 770), proving again the compare logic is working when 0 is not getting in the way. Then it started drifting back up toward room temp. Probe back in the tank and things seem to be working ok for now.
lnevo wrote:What you can do too is average out the sampling and look at the average low temp over x samples and then do your comparison. You might still need to drop 0 values but lets see what happens with your check let me know if you still need sample code.
I was thinking about doing a rolling average when i saw the number float down down down to 593 or so earlier. seems if the probe is in the water it seems pretty stable. I put the probe back in the water. It's been back in there for about 10 minutes and the delta between my hi and low is only 005 (half a degree) I can live with that if it stays that way. I wouldn't even waste the time with a rolling average for that small of a fluctuation.
Again Thanks lnevo that zero has bugged me for a long time.