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

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.




Sorry,

For my last question I meant this part:


 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);
  }

@Ben


Your original question concerned non-working buttons on page 3 of your HMI.

Using the code you supplied, I have been able to load that code to an Uno and do some tests.

It works!


My other suggestions, were just suggestions, you do not have to implement them.

I just thought it prudent on a life sustaining system that things like temperature settings should have absolute limits high or low.

The callback on b2 was just a way to populate current data to t11 and t12 whenever you went to page 3.

That works also!

Your issues in loop() are still present, so please refer to the article I first pointed you to.

I would think in a system that will vary temperature in rather slow manner, you shouldn't need to call readings more than once a minute perhaps?  

Ben,


Trying to run this block in loop() is a flawed idea. 

      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);
      }

 Because strcpy() changes buffer twice to differing values, the if's will always return true next time round the loop(). So a print to Nextion will be executed every loop() iteration.

A reasonably free running loop() will run at tens of thousands times per second, is that what you intended???


The callback I proposed on b2 does the same job :) 

Hello indev2,


Although I'm Dutch, I've noticed your previous messages, better still, I've read them!

;-)


I have also managed to change a value a few times. So the problem will indeed be: overloaded.! The following section I changed. It only writes away if something really changes. This helps a bit but not enough. I really need to look further.


 sensors.requestTemperatures();
  float x = sensors.getTempCByIndex(0);
  dtostrf(x, 5, 2, buffer_sensor);
  if (strcmp(buffer_sensor, buffer) != 0)
  {
  //Conversion temperature to round meter values
  // Temperature (linear)
  // temperature = 0, angle = -45 degrees
  // temperature = 50, angle = +225 degrees.
  // range of temperature is 50
  // range of angle is 270 (225 + 45)
  //float temperature;
  float angle = (x / 50.0 * 270.0) - 45.0;
  int degrees = int(angle);
  temp.setValue(degrees);
  if (angle < 0)
  {
  angle += 360;
  }
  strcpy(buffer, buffer_sensor);
  }


Btw, if I only use your b2 suggestion, from which I think its a logical one, is doesn't print anything on field 11 and 12. Isn't that odd?

Thanks again!

Ben.


hey Ben


First, please put a serial.print at beginning of function and at end of function

 - this is to determine if the function is even triggering.


Second, is sensors.requestTemperatures(); being called within the function?


Third, put a timer around sensors.requestTemperatures();

 - this is to determine how long it is taking

Ben


The b2 callback does work in Nextion Debug simulator, I can't test on a real display as I don't own one of that size.

Are you sure your sketch has all necessary code for it to work.

Initial declaration...  

NexButton b2 = NexButton(1, 3, "b2");

In 

NexTouch *nex_listen_list[] =
{
  &b2,
  &b14,
  &b15,
  &b16,
  &b17,
  &t11,
  &t12,
  NULL
};

 And in setup() 

  b2.attachPop(b2PopCallback, &b2);

 

You could try adding a small delay to the callback print... 

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

 


Here's my modified .ino

ino

Please note I also resized the text boxes in the HMI to at least a size that shows one digit after the decimal point ;)

Checking the Send Comp ID for touch release on page 1 b2 is also a requirement in the HMI 

At this moment, I'm already testing your ideas. They are, up and till now, not yet complete to my satisfaction, but that is also because of the style of my program. Actually, I'm just a beginner.Therefore, I want to change the program model. I would like to do the following. For each component I create separate pages that I call from the Arduino with PopCallbacks. So I get a Main or Dashboard page, a page for referrals to all set pages and of course for each setup page separately.This way I get not only more overview but also I do not have to bother anymore our less of overload problems.This does, of course,  not mean that I'm not very grateful for your contribution, I have learned a lot! We will see where this ends...


Thanks, again!

Regards,

Ben.




Serial overload is more char/bytes then can be handled

 - at 115200 baud, 10 bits per byte, that's 11520 bytes per second

 - a button press/release sends a 0x65 return of 7 bytes.

 - requesting a number via returns a 0x71 of 8 bytes

A little math 1/11520 is around 86us per byte incoming or out going

Arduino provides a millis() as well as microSeconds() for timing


As the programmer you can certainly change your MCU model

 -  but we have less chance of changing the behaviour of Nextion.

As a beginning programmer,

  my thoughts that a structured programming model (Iteadlib) is useful.

I would be less inclined to suggest changing programming models until

one has a handle on the existing.  change is perhaps more advanced.


To the MCU a list of 150 function pointers is not that much of an issue

 - a 0x65 press/release comes in via nexLoop() in NexHardware.cpp

   which when successfully parsed is passed to iterate() which goes

   through the nex_listen_list for a match.  If a match is found because

   an attachPush or an attachPop was declared - then it passes it off

   to the function you declared with the attach.

This is not difficult of a task for the MCU even if the list is 2400 long.


It does become a bit more for the user trying to scroll through so many

lines of code looking for where such-and-such was, but not so much of

an issue for the MCU which is designed to compare number values.


But best wishes on whichever approach you finally decide on



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.

Login or Signup to post a comment