Start a new topic

I can not communicate 2 sensors with the nextion display


Hi everyone, I'm having a problem with the program of a flow and pressure sensor communicating with a nextion display. The sensors work on the arduino's serial monitor, but the time I select to display the values ​​on the display will stop sending them. Could someone help me with this situation ??


thank you



#include "Nextion.h"

long lastUpdate;

// vars

int buttonvalue = 0;

char buttonvalue_char[2];

int buttonvalue1 = 0;

char buttonvalue1_char[2];

float pressao = 0;

float valpressao = 0;

float val = 0;

float fluxo;

int contaPulso; //Variável para a quantidade de pulsos

int led1 = 13;

int led2 = 12;

int led3 = 11;

int led4 = 10;

int led5 = 9;

int led6 = 8;

int led7 = 7;

NexText t2 = NexText(0, 15, "t2");

NexText t3 = NexText(0, 16, "t3");

NexText t0 = NexText(0, 18, "t0");

NexText t4 = NexText(0, 17, "t4");

NexButton b0 = NexButton(0, 9, "b0");

NexButton b1 = NexButton(0, 10, "b1");

NexPicture p7 = NexPicture(0, 8, "p7");

/*

* Register a dual state button object to the touch event list.

*/

NexTouch *nex_listen_list[] =

{

&b1,

&b0,

&p7,

NULL

};

void p7PopCallback(void *ptr)

{

uint32_t number = 0;

dbSerialPrintln("p7PopCallback");

p7.getPic(&number);

if (number == 1)

{

number = 13;

}

else

{

number = 12;

}

p7.setPic(number);

}

void b0PopCallback(void *ptr)

{

// JUST PRINT SOMETHING THAT WE KNOW THE BUTTON IS PRESSED AND THE FEEDBACK IS OK

Serial.println("botao desliga pressionado");

// INCREASE THE VALUE WE WANT TO SET AS TEXT TO THE BUTTON

buttonvalue++;

Serial.print("value: ");

Serial.println(buttonvalue);

// CREATE A CHAR OF THE INTEGER TO SEND IT TO THE BUTTON AS TEXT

itoa(buttonvalue, buttonvalue_char, 10);

// SET THE TEXT TO THE BUTTON

b0.setText(buttonvalue_char);

if (buttonvalue!=0)

{

t0.setText("OFF");

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

digitalWrite(led5, LOW);

digitalWrite(led6, LOW);

digitalWrite(led7, LOW);

p7.setPic(12);

}

}

void b1PopCallback(void *ptr)

{

// JUST PRINT SOMETHING THAT WE KNOW THE BUTTON IS PRESSED AND THE FEEDBACK IS OK

Serial.println("botao liga pressionado");

// INCREASE THE VALUE WE WANT TO SET AS TEXT TO THE BUTTON

buttonvalue1++;

Serial.print("value: ");

Serial.println(buttonvalue1);

// CREATE A CHAR OF THE INTEGER TO SEND IT TO THE BUTTON AS TEXT

itoa(buttonvalue1, buttonvalue1_char, 20);

// SET THE TEXT TO THE BUTTON

b1.setText(buttonvalue1_char);

if (buttonvalue1!=0)

{

t0.setText("ON");

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

p7.setPic(13);

}

}

void checkSensor()

{

val = analogRead(pressao);

valpressao = (((val - 0.2)/ 0.0064)/1000-6);

String displayText = String(valpressao);

//Serial.println (valpressao);

t2.setText(displayText.c_str());

}

void checkSensorfluxo()

{

fluxo = digitalRead(fluxo);

//delay (1000); //Aguarda 1 segundo

cli(); //Desabilita interrupção

fluxo =( contaPulso / 7.5); //Converte para L/min

String displayText2 = String(fluxo);

Serial.print(fluxo); //Escreve no display o valor da vazão

t4.setText(displayText.c_str());

Serial.println(" L/min "); //Escreve L/min

contaPulso = 0;//Zera a variável

sei(); //Habilita interrupção

}

void incpulso ()

{

contaPulso++; //Incrementa a variável de pulsos

}

void setup(void)

{

lastUpdate = millis();

pinMode(pressao, A0);

pinMode(fluxo, 2);

nexInit();

pinMode(led1,OUTPUT);

pinMode(led2,OUTPUT);

pinMode(led3,OUTPUT);

pinMode(led4,OUTPUT);

pinMode(led5,OUTPUT);

pinMode(led6,OUTPUT);

pinMode(led7,OUTPUT);

p7.attachPop(p7PopCallback);

// SHOULD HAVE bauds=115200 AS PREINITIALIZE EVENT IN NEXTION EDITOR

//Serial.begin(9600);

b0.attachPop(b0PopCallback, &b0);

b1.attachPop(b1PopCallback, &b1);

Serial.println("setup done");

attachInterrupt(0, incpulso, RISING); //Configura o pino 2(Interrupção 0) interrupção

}

void loop(void)

{

nexLoop(NULL);

if (millis() - lastUpdate > 100)

{

checkSensor();

//checkSensorfluxo();

lastUpdate = millis();

}

/*

* When a pop or push event occured every time,

* the corresponding component[right page id and component id] in touch event list will be asked.

*/

nexLoop(nex_listen_list);

}



Generally provide adequate info when looking for assistance.


Failed to provide important details:

 - what MCU is being used

 - HMI project file missing, no means verify NexComponent declarations


Sorry, but when Nextion works and your issue is sensors

 - Arduino forum to learn programming



Please feel free to ask Nextion related questions.

- Please do not use forum to dump code and expect other users to debug your code.

Okay, but if I knew you were like that with customers, you should not have bought your product. Many times, as in this case, the problem is of nextion because some code that you fail to inform does not work on the display. Thank you very much for your response.

I'm using MCU 7" 

HMI

NexText.h shows that setText() expects a char array.

  - this is within the user domain to review examples of the library.


The Nexion FAQs posted in the Announcements

  - no one is obligated to debug user code


A Flow and Pressure sensor's code is not Nextion

  - How to combine is Arduino coding, sensor does not directly send

    to Nextion, but rather the Arduino is the intermediary and it is

    Arduino that reads the sensor and Arduino sends to the Nextion


Examples are included with the library in a non complex example

   CompText shows how to read and send to Text component


Users are expected to read the documentation and examples provided

Prerequisite programming knowledge is expected, as is electronic knowledge

 - Arduino.cc helps with learning these

 - asking in the correct forum will yield better results.


But honestly, you dumped your code and want others to fix

    this is just not the correct manner to do so.

Ask question to learn, fine, but not code dumps and expect debugging services.

MCU refers to the chip/platform where your Arduino code runs on


7" is not an MCU.   7" might refer to one of three Nextion models.

 - NX8048T070_011

 - NX8048K070_011R

 - NX8048K070_011C


MCU family could be STM32, DUE, UNO, MEGA, TINY, ESP8266, ESP32, PIC, etc


So you were born knowing, people just like you do not know how to work as a team, today it may be me who has a doubt or difficulty, tomorrow may be you. Oh, I forgot you know everything, you'll never need it. Thank you for your help .

I saw where I was wrong in the code. But if you ever need my help I will be at your disposal unlike you

Tip:

 - when you have need to understand something,

   ask those that are knowledgeable about such matters.

   This is a good rule with most things in life.

 - If your question is financial, ask those who deal in money

   if your question is legal, ask those schooled in such matters

   if your question is about health, ask those trained for such.


Nextion is a very simple serial text command device

  page0.t0.txt="123"ÿÿÿ

  page2.n0.val=23ÿÿÿ

setText() and setValue() functions parses into this Nextion format.


One can even format their own without the Iteadlib library

   Serial2.print("page2.n0.val=");

   Serial2.print(myNumber,DEC);

   Serial2.write(0xFF);

   Serial2.write(0xFF);

   Serial2.write(0xFF);

In this simple text command based serial manner, 10,000's of MCUs with serial are supported.


However, when the problem is not Nextion based

 - it makes less sense to ask a display manufacturer why sensor code for MCU doesn't work.

   only because your project includes a display.

 - on the same basis, do you ask a pressure sensor manufacturer how Nextion works only

   because the project contains a pressure sensor?  No.

Then asking in the proper arena suited to the problem is appropriate.


100's or programming languages are used to program the Nextion

 - my favourite language may indeed be Pascal, others use Basic

It is a very wrong assumption that Arduino C++ is such a defacto language

So when issues arise in Arduino C++ for an Arduino MCU in Arduino IDE

 - then seeking assistance at Arduino forums will produce best results for you.

If I had a question using mikroPascal for a given MCU then it makes

   sense to visit the mikroe forums.


Your issue is less Nextion based, setText() works

   understanding how your MCU uses cli() and sei() is not Nextion issue, rather MCU side

   understanding how your MCU responds to a delay(1000) is also not Nextion. rather MCU side

   understanding when and why to use NULL parameters ... again an MCU side issue.


Learning to frame your question, very important

   asking in a correct manner produces better results

 - even in search engines,

   wording a query poorly, results in unrelated results

   wording a query with more thought yields relevant and useful results.


Even if your question had to do with the Nextion Instruction Set

   would make such a difference.

- this is the Nextion forum, so it stands more to reason Nextion related topics

  and this I indeed have provided many such answers for.

- many times,  over and over and over again that no one bothers to read

   so why should it be typed out again ... so that it wont be read, again?


But the Nextion forum is not a personal debugging service to dump code

   sorry, but this is just in the wrong manner.

Forum questions is answered by the forum users.

  - I answer frequent, because if I didn't ...

      perhaps answers may have to wait until the weekend, or

      perhaps possible no one would answer at all

  - but this is my time I volunteer to provide answers.

And I am most certain every question possible has been covered at least twice on forum.

 - users really must only read what is already written to find their answers.


So when it is not Nextion issue, but indeed MCU code issue,

   it is indeed in your interest to seek out your specific MCU and code compiler. (Arduino.cc)


As for teams.

   it is indeed important for a team leader to recruit team members.

   it is more important to inform team members of their areas of responsibilities

It is perhaps a mistake to

   take for granted the said members of your team

And a critical mistake by a team leader

   to assume someone will be part of your team when they have never even been asked to be part.


As for being born knowing ??

    yeah, I knew from early age of 3 weeks age, all technology for 200 years in future.  NOT.

No one is born knowing, such is the result of work and discipline.

Login or Signup to post a comment