Start a new topic

adjustable temperature sketch doesn't work.

I am trying to construct an aquarium controller. A part of this controller is a  temperature Gauge which is working perfect. In my sketch is a warning system needed for if the temperature is too high or too low. In the adjustable partI want to have the ability to move the values for maximum and minimum ​​up or down every time with one. That doesn't work. Is there someone who has the solution for this problem? 

my screen:  [broken link removed]


Thanks!

Greetings,

Ben.


ino

Ben


You are making the classic beginners mistakes of doing too much and too often in your loop() function.


This block only needs running once when you get to page 3

    dtostrf(maxTemp, 5, 2, buffer_temp);
    if (strcmp(buffer_temp, buffer) != 0)
    {
      t11.setText(buffer_temp);
      strcpy(buffer, buffer_temp);
    }
    dtostrf(minTemp, 5, 2, buffer_temp);
    if (strcmp(buffer_temp, buffer) != 0)
    {
      t12.setText(buffer_temp);
      strcpy(buffer, buffer_temp);
    }

The rest needs calling at 'reasonable' intervals, not every pass through loop()

A good read will help you make better programming choices...

https://learn.adafruit.com/multi-tasking-the-arduino-part-1/overview

You're right, but I know this already, this part is not the problem. This part is working. The problem arises when I want to change the both temperature values, minimum and maximum. I need the temperature space between the minimum and maximum values and it needs to be ajustable. I want to do this with the four buttons and the PopCallbacks for each button. That part doesn't do nothing! And I don't know why.


What are, btw,, in your opinion, reasonable intervals?


Thanks for your reply!


Greetings,

Ben.

Ben


You have not posted your HMI, so I'm somewhat in the dark here.


Try commenting out everything in loop() apart from...

 nexLoop(nex_listen_list);

Then come back and let me know if your buttons are working.


We'll discuss reasonable intervals later.

(Also note that google access is not available everywhere)

( 1/2 the user base can not access, therefore can not assist )

uploaded photo of reasonable size posted in threads please.

That link is broken (for me) anyways, so it's likely much more than half :(

Hello indev2,


Here is my HMI. Btw, I tried to turn everything off but that didn't help me.It's a riddle for me because my adjustable clock works according to the same principle.  It doesn't work fine but it works. ( Look at page 2 in de HMI. ) Just to make my HMI understandable; page 0 is the dashboard page, page one is menu choice, page two is used for an adjustable clock, page three is the one I am now working on, the temperature page. Page four does not excist yet (it is gone be the pH page) and so is page five. The last one is meant for my lighting.


Thank you for your spending time


Greetings,

Ben.


HMI

Basic principle of debugging - Serial Monitor.

  Iteadlib uses dbSerialprintln or just use Serial.println


void b14PopCallback(void*ptr)                 

{

    maxTemp += 1.0;                        

    dtostrf(maxTemp, 5, 2, buffer_temp);    

    t11.setText(buffer_temp);

}


Want to know if the button 0x65 is being received by MCU?

Insert these printlns back to Serial Monitor so you can see  ??


void b14PopCallback(void*ptr)

{

  dbSerialprintln("b14 pop entered");

  maxTemp += 1.0;

  dtostrf(maxTemp, 5, 2, buffer_temp);

  t11.setText(buffer_temp);

  dbSerialprintln("b14 pop complete");

}


The shorter the message, the less it interferes

 - at least until you know that segment isn't causing your issue


You can even insert times

  dbSerialprint("b14 pop:+  ");

  dbSerialprintln(millis(),DEC);

  ...

  dbSerialprint("b14 pop:-  ");

  dbSerialprintln(millis(),DEC);


since this is millis() in milliseconds

 - you even have an idea minus-ing the two how long it took.


But your code includes very little (or none) Serial Monitor debugging

and without such to let you know what is happening when

one gets a bit of that "lost feeling" when it doesn't work as expected


OK,


Thanks Patrick, indeed they are good points to start debugging.


Ben, with everything still commented out in loop() other than...

nexLoop(nex_listen_list);

remove the sendme's  you have at touch release on buttons b14 to b17 and try again.

When it works for page 2 and not page 3

 // all code is not included - such can be in remaining code

    there is certainly no page 2 components in the ino above

I have to question why you have included sendme in every button.


sendme will let you know what the current page is with a 0x66

   0x66 0x03 0xFF 0xFF 0xFF  ... we are on page 3

But your MCU already has this info in a Send Component ID 0x65

   0x65 0x03 0x04 0x00 0xFF 0xFF 0xFF

sendme is best used only once/page say in Preinitialize Event of pages


It makes it difficult for others to dig in for you

 - when links are broken

 - when HMI is not included

 - when ino is partial (when referring to other code not present)

 - when libraries used are missing

 - when MCU used is not told

I was not able to compile your ino.



which MCU Steve, and where do we find the DallasTemperature library he used

For a little clarity


As sendme is triple 0xFF terminated

  - its presence or not will not be an issue with the iteadlib

     other than it is consuming a bit more bandwidth

  - this would be the same that bkcmd returns are not being

    responded to in the user ino, but are still present on the wire.


But adding a serial debug line in function 

  both at beginning and end will allow for him to see

    - if first triggers and is printed, MCU processed button correctly

    - if last triggers and is printed, MCU completed function correctly

    - if first triggers and last does not - error is within function

    - if first and last does not trigger - MCU is not catching button

@Ben


I've stripped out all but page 3 button functionality from the .ino you posted. Running on Uno to Nextion Editor Debug reveals that your code is in fact working, albeit with some corrections required here and there.


Some conditionals to prevent exceeding max or min temps beyond absolutes, would be a good idea, and line 78 should be minTemp 


Thoughts...

Check Send Comp ID on page 1 b2 touch release in HMI. Attach the new PopCallback to page 1 b2 as below, this will populate current temperature data as page loads, and some ideas for absolute Temp settings... 

void b2PopCallback(void*ptr)
{
    dtostrf(maxTemp, 5, 2, buffer_temp);
    t11.setText(buffer_temp);
    dtostrf(minTemp, 5, 2, buffer_temp);
    t12.setText(buffer_temp);
}

void b14PopCallback(void*ptr)
{
  if (maxTemp < 33) {
    maxTemp += 1.0;
    dtostrf(maxTemp, 5, 2, buffer_temp);
    t11.setText(buffer_temp);
  }
}

void b15PopCallback(void*ptr)
{
  if (maxTemp > 25) {
    maxTemp -= 1.0;
    dtostrf(maxTemp, 5, 2, buffer_temp);
    t11.setText(buffer_temp);
  }
}
void b16PopCallback(void*ptr)
{
  if (minTemp < 23) {
    minTemp += 1.0;
    dtostrf(minTemp, 5, 2, buffer_temp);
    t12.setText(buffer_temp);
  }
}
void b17PopCallback(void*ptr)
{
  if (minTemp > 17) {
    minTemp -= 1.0;
    dtostrf(minTemp, 5, 2, buffer_temp);
    t12.setText(buffer_temp);
  }
}

  

First of all: I put "sendme" into the editor because I thought it was a good idea to refer to a page. It didn't work but I forgot to remove it...

@indev2

To put this part down seems logical, but I do not understand why there should be re-values ​​in the following callbacks

void b2PopCallback(void*ptr)
{
  dtostrf(maxTemp, 5, 2, buffer_temp);
  t11.setText(buffer_temp);
  dtostrf(minTemp, 5, 2, buffer_temp);
  t12.setText(buffer_temp);
}


but it doesn't do anything?

Why would you like to put these rules? MaxTemp already has an entered value? By the way, I tried them but they do not work either.

if (maxTemp < 33)


Finally, the question; If I want to print the basic values, I only get this  done when I set the part in the void loop(void). In no other place it sets the values. How is this possible?


 Besides; I have tried all the proposals. I do not have much hair but I am on the point of pulling everything out!  ;-)

Although I do want to thank you all for the important help!

Greetings,

Ben.




Login or Signup to post a comment