Start a new topic

Calibration on Nextion.

Previously, I put my post in a wrong place. I apologize for that.


I have  a calibration program for an Arduino. But I would like to work from my Nextion.

It has to be translated. But I have no idea where and how to start.For example, how should you send the lowercase letter "m" to the program on the Arduino? Let alone that I know how the rest of this small part should be adjusted.Can anyone help me? I would be grateful for it. Here is the program I would like to get working from Nextion:


#include <EEPROM.h>

#include <AnalogPHMeter.h>



AnalogPHMeter pHSensor(A2);



void setup(void) {

Serial.begin(9600);

pHSensor.initialize();



Serial.println("Analog PH Meter Calibration");

Serial.println("The value will be saved on EEPROM");

Serial.println("Procedure:");

Serial.println(" - Put pH on pH 7 solution");

Serial.println(" - Wait until stable");

Serial.println(" - Press 'm' to calibrate");

Serial.println(" - Same process for pH 4 and/or pH 10,");

Serial.println(" except press 'l' for pH 4, and 'h' for pH 10");

Serial.println();

Serial.println("*to clear calibration value press 'c'");

delay(3000);

}



void loop(void) {

static unsigned long t = millis();

if (millis() - t > 1000) {

Serial.println(pHSensor.singleReading().getpH());

t = millis();

}



if (Serial.available()) {

char c = Serial.read();

if (c == 'm') {

pHSensor.calibrationMid(7.000f);

} else if (c == 'l') {

pHSensor.calibrationLow(4.000f);

} else if (c == 'h') {

pHSensor.calibrationHigh(10.000f);

} else if (c == 'c') {

pHSensor.calibrationClear();

}

}

}


Greetings,

Ben.



Ben


I won't be translating this for you, others may be willing to


But look to the print command

   for Nextion to send an m over serial to the MCU

print "m"  // place inside a button Event as needed


Patrick

  

Hello everyone,


Thanks, Patrick for your reply!


You're not an "Arduino man", I understand that.

Some explanation and simplifying, maybe. Anything under Serial.println can I put in my background. That's not a problem.

For the first part in the "loop" I create a text block, and everything has been solved.for that part too.

But then the bottom part!

By the way, I only need the segment, from that part, where the calibration mid (pH7) is done and the callibrationClear. The rest I don't even use. But there is my difficulty.

I tried a PopCallback with the phrase: pHSensor.CallibrationMid (7.000f); But that did'nt work just like your proposal print "m". The question is thus: What do I put under the button or PopCallback, for "m" and what for "c"? What are the possibilities here? That's a Nextion question, or am I wrong now?

I am grateful for an answer and possible solution!


Regards,

Ben.

if you are going to use IteadLib, you need to add

to the top of file includes

#include "Nextion.h"


to the setup() function

  nexInit();


to the loop() function

   nexLoop(nex_listen_list);


you would need to define

   your four buttons from Nextion side

   your nex_listen_list below your variables

   your four callback handlers above setup()

   your four callbacks in setup

The framework would look something like


 

#include "Nextion.h"

// Declare Buttons
// NexComponent yourvariable  NexComponent(pageno, .id, .objname)
// set the pageno .id and .objname to the values in your HMI design
NexButton for_c = NexButton(0,1,"b0");
NexButton for_h = NexButton(0,2,"b1");
NexButton for_l = NexButton(0,3,"b2");
NexButton for_m = NexButton(0,4,"b3");

NexTouch *nex_listen_list[] = {
  &for_c, &for_h, &for_l, &for_m, 
  // add whatever other buttons/etc you are listening for
  
  // end with NULL
  NULL
};

void PopCallback_c(void *ptr) {
  // code for when c button released on Nextion
  // in c's button Nextion side just check Send Component ID in Release no code

}

void PopCallback_h(void *ptr) {
  // code for when h button released on Nextion
  // in h's button Nextion side just check Send Component ID in Release no code

}

void PopCallback_l(void *ptr) {
  // code for when l button released on Nextion
  // in l's button Nextion side just check Send Component ID in Release no code

}

void PopCallback_m(void *ptr) {
  // code for when m button released on Nextion
  // in m's button Nextion side just check Send Component ID in Release no code

}

void setup(void) {
  nexInit();
  for_c.attachPop(PopCallback_c,&for_c);
  for_h.attachPop(PopCallback_h,&for_h);
  for_l.attachPop(PopCallback_l,&for_l);
  for_m.attachPop(PopCallback_m,&for_m);
  // other setup

}

void loop(void) {
  nexLoop(nex_listen_list);
  // other code

}

 

 

In this fashion the Iteadlib listens for the correct 0x65 Nextion Return Data for

each of the buttons/components in nex_listen_list

When it received 0x65 0x00 0x02 0x00 0xFF 0xFF 0xFF on nexSerial from Nextion

 - this aligns with for_h button being released

NexButton for_h = NexButton(0,2,"b1");

and if there is an .attachPop defined for it, it will trigger your callback 


If you are not using IteadLib,


then you have to define all the Serial2.available() and Serial2.read() procedures

and then work out the Nextion Return Data and based on what is received

trigger your functions based on the set of rules you define.

Patrick,

Thanks for your response!


Indeed, I use IteadLib so I will express your first proposal. And of course I'll let you know if the sketch works.

It's a holiday time, but there may be additions from you or any other readers; Please!


Have a nice day.

Ben.


Hello Patrick,


You probably tell me a joke when you said you did not know anything about Arduino. You gave me the solution to my problem! You do not know how grateful I am for it!

My calibration works! This has become the sketch:


#include <Nextion.h>
#include <EEPROM.h>
#include <AnalogPHMeter.h>

AnalogPHMeter pHSensor(A2);

// -------- Declare Buttons ----------

NexButton for_c = NexButton(0, 3, "b0");
NexButton for_m = NexButton(0, 4, "b1");
NexButton for_l = NexButton(0, 5, "b2");
NexButton for_h = NexButton(0, 6, "b3");

// -------- Declare Textfield ---------

NexText t1 = NexText(0, 2, "t1");

char buffer_pHtemp[10];


NexTouch *nex_listen_list[] =
{
  &for_c,
  &for_h,
  &for_l,
  &for_m,
  &t1,
  NULL
};

void PopCallback_c(void *ptr)
{
  pHSensor.calibrationClear();  // Clear
}

void PopCallback_m(void *ptr)
{
  pHSensor.calibrationMid(7.000f);  // pH 7 single point calibration
}

void PopCallback_l(void *ptr)
{
  pHSensor.calibrationLow(4.000f);  // pH 4 single point calibration
}

void PopCallback_h(void *ptr)
{
  pHSensor.calibrationMid(10.000f);  // pH 10 single point calibration
}

void setup(void)
{
  Serial.begin(9600);
  pHSensor.initialize();

  nexInit();
  for_c.attachPop(PopCallback_c, &for_c);
  for_h.attachPop(PopCallback_h, &for_h);
  for_l.attachPop(PopCallback_l, &for_l);
  for_m.attachPop(PopCallback_m, &for_m);

}


void loop(void)
{
  static unsigned long t = millis();
  if (millis() - t > 1000)
  {
  float pHvalue = (pHSensor.singleReading().getpH());
  dtostrf(pHvalue, 5, 2, buffer_pHtemp);  //conversion pH value to string
  t1.setText(buffer_pHtemp);
  t = millis();
  }


  nexLoop(nex_listen_list);
}


Thanks again!

Regards,

Ben.

Login or Signup to post a comment