Go Down

Topic: Nextion - How to display "Error-Messages" (Read 768 times) previous topic - next topic

Manuel_o

I have a general question.

Lets say i have a simple numfield where i can enter values (via numpad). Only numbers between 0 and 100 are allowed. If someone enters a value that is not in this range, a "error message" should appear. For example "Only number 0 - 100 are allowd".

I know that i just could make "if" - statements, where i force that only values in this range are allowed. But sometimes you just want to display an errormessage.

How would you do that?

I am thinking of a smaller page that overlaps the current page, where the errormessage is displayed, that also can be closed via an button.

Some ideas?




PerryBebbington

Hello Manuel.

First I suggest you don't use the number boxes, they are crap as they only display integers, making something like £12.45 or 67.2% very awkward.

However, if you do want to use the number boxes then you need:
  • A text box to display the error message
  • Code under touch release event to catch the value going over the limit and display the error


The code will need to be something like:

Code: [Select]
if(value over limit)
Display error message


Note that Nextions use a very limited subset of C, more like C--, for programming, and note that you can only have one instruction per line.

Rather than an error would it work to roll the numbers round back to the beginning? So something like 98, 99, 100, 0, 1, 2 etc?

Finally, a plug for my tutorial 'Using Nextion displays with Arduino' which I think will give you the tools to do what you want.



Manuel_o

#2
Jun 13, 2019, 01:13 pm Last Edit: Jun 13, 2019, 01:21 pm by Manuel_o
Hello

Sorry for the late answer. Thank you for your help.

Kinda know what you mean.
I try to be more specific what i want to do:

I measure a value the whole time in a loop. Now, if the value crosses a specific value i want to write a Error-mesages into a different page called "errormessages" on my nextion.

So when i think abou it, the solution isnt that hard on the first look. I think about that:

If (messuredValue > as a specific value)
{
 Write the error message into a textfield into error-message page
}


So far so good.
But if i have different textboxes for different errors, the messages would appear just in the specific textboxes somewhere on my errormessage-page". You know what i mean?

I have no code yet for the problem, i am still in the planing phase

PerryBebbington


Quote
I measure a value the whole time in a loop.
Do you mean on an Arduino or a Nextion? I suggest that on a Nextion you won't get very far, on an Arduino no problem.

For the rest, what you propose is stright forward, get a Nextion and an Arduino and experiment.

Note that since my last reply I have updated the example Nextion code in my tutorial. I have added automatic display dimming, which dims the display after 10 seconds of not pressing any buttons. This uses if() on the Nextion to achieve this, so demonstrates how to use if() on a Nextion.


Manuel_o

Hello. I am still struggling with the idea of how to write simple error-messages into my Nextion.

Or to be more specific. I dont know how to start.

I have a page in my Nextion called: ERROR-messages. There i wanna write different warnings and errormessages if some conditions get triggered.

But do i just use a simple textfield in my nextion and fill it with my error-message when the condition is triggered?

PerryBebbington

Without seeing your code it is impossible to offer much advice. Have you worked through my tutorial?

Manuel_o

#6
Jun 25, 2019, 06:24 pm Last Edit: Jun 25, 2019, 06:26 pm by Manuel_o
Yes sir. i read almost everything of you. Also using yout dim-timer. thanks for that btw

I hope the people here dont kill me because sometimes they are angry that i dont post the whole code. But in this case, for this problem i does not matter (imo)

Here is a example i tried:

Code: [Select]


void loop(void)
{
 
  DateTime now = rtc.now();
  if (millis() - startChrono_clock >= Clocktimer)
  {
  sprintf(tempString, "%02d.%02d.%02d/%02d:%02d:%02d",now.day(),now.month(),now.year(),now.hour(), now.minute(),now.second());
  Zeit.setText(tempString );
  startChrono_clock=millis();
  }

  nexLoop(nex_listen_list);
  if (millis() - startChrono >= interVl){
    //Speichert gemessene Werte in Memvervariablen
    SondePh.set_m_raw(analogRead(Messung_Poti));
    SondePh.set_m_maped(SondePh.mapTheRawInput(analogRead(Messung_Poti)));

    writedoubleToDisplay(mw_raw_main,SondePh.get_m_raw());
    writedoubleToDisplay(mw_maped_main,SondePh.get_m_maped());
    if(SondePh.get_m_maped() <= Alert.get_lowerLimitValue() || SondePh.get_m_maped() >= Alert.get_upperLimitValue())
    {
      alarm1.setPic(5);
      if(SondePh.get_m_maped() <= Alert.get_lowerLimitValue())
      {
        Errorlog.setText("I an a error-messge");
       
      }
    }
    else
    {
      alarm1.setPic(1);
    }

    s0.addValue(0,mapf(SondePh.get_m_maped(),0,8000,0,176));
    //in "Kalibrieren"

    startChrono = millis();
 

  }   
}



So this  is basicly my first idea how to write an errormessage. I defined a textfield "Errorlog" and there should the text appear when the condition is true.

Is this the right direction?. The problem that comes to my mind right now is, that if i have mutliple errormessages from different pages, i only can display 1 message at a time in my textfield Errorlog. Would i use more texfields, the messages would appear on different places on my errorpage. Thats not wht i want.

I hope its kinda understandable what i mean

thank u very much

PerryBebbington

Does this work? Does it print the time on the Nextion correctly?

Code: [Select]
  sprintf(tempString, "%02d.%02d.%02d/%02d:%02d:%02d",now.day(),now.month(),now.year(),now.hour(), now.minute(),now.second());
  Zeit.setText(tempString );



This
Code: [Select]
  nexLoop(nex_listen_list);

Suggests to me that you are using the Nextion libraries, that being the case I can't help much as I don't use them, don't know much about them. You either need to use the Nextion libraries, in which case follow the link from my tutorial to Ray Livingston's version of the libraries and use those, he has fixed a lot of bugs, or use my methods, which don't rely on the libraries, then I can help you. Your code doesn't look much like my examples, so I can't help much as it is.

You have this function call:
Code: [Select]
writedoubleToDisplay(mw_raw_main,SondePh.get_m_raw());


But I don't see the function, so I can't say if I'd expect it to work.

Please also learn to write functions like in my examples, with calls to the functions from loop();, trying to put all your code in loop(); is confusing, difficult to read and difficult to fix.






Go Up