# Sending numeric value from Nextion display to a const long variable using EasyNextionLibrary

**URL:** <https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101>\
**Category:** Displays\
**Created:** [March 18, 2024, 5:59pm UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101 "2024-03-18T17:59:17Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![papagino](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/papagino/32/1098795_2.png) [@papagino](https://forum.arduino.cc/u/papagino)\
**Post date:** [March 20, 2024, 5:05pm UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101/21 "2024-03-20T17:05:13Z")

</div>

**Can you send data using the Easy Nextion Library commands?**  
I have tried replacing this:

```arduino
const double celsius = thermocouple->readCelsius();
    // Output Temperature on Nextion t1 text field
  Serial2.print("t1.txt=\""); // Changing the value of box t1
  Serial2.print(celsius); // celsius read the temperature from the sensor and output in Celcius
  Serial2.print("\"");
  Serial2.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
  Serial2.write(0xff);
  Serial2.write(0xff);

```

with

```arduino
const double celsius = thermocouple->readCelsius();
    // Output Temperature on Nextion t1 text field
  myNex.writeNum("t1.val", celsius);.

```

and it not doing anything, t1 stayed empty.

What should be the proper code to use the library?

---

<div class="post-metadata">

**Author:** ![papagino](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/papagino/32/1098795_2.png) [@papagino](https://forum.arduino.cc/u/papagino)\
**Post date:** [March 20, 2024, 6:27pm UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101/22 "2024-03-20T18:27:32Z")

</div>

Ok, I think I got it...

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [March 20, 2024, 7:44pm UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101/23 "2024-03-20T19:44:36Z")

</div>

> [@papagino](#):
>
> Then print the variable like:
> 
> ```arduino
> Serial.println (number);
> 
> ```
> 
> ???
> 
> Maybe that's it???

Yes. myNex.readNumber( ) has a return value. If you don't assign that value to a variable or print it, it is lost.

`const double celsius = thermocouple->readCelsius();`

There are special issues with floating point numbers and the Nextion. There is a library example which shows you how to deal with them.

> Ok, I think I got it...

Can you now read a number or text field from the Nextion?  
Have you run the library example programs?

---

<div class="post-metadata">

**Author:** ![papagino](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/papagino/32/1098795_2.png) [@papagino](https://forum.arduino.cc/u/papagino)\
**Post date:** [March 21, 2024, 12:27am UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101/24 "2024-03-21T00:27:44Z")

</div>

Ok, the variable

```arduino
interval = myNex.readNumber("n61.val"); // Store to interval the value of numeric box n61 

```

was located above void setup(){ and when it was there, the program was no longer running.

I moved it in the void setup(){ section and added:

```arduino
unsigned long interval = interval;

```

above the void setup(){ section.

Now in the void loop(){ section I have:

```arduino
void trigger23(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command: printh 23 02 54 17
   * Every time the button is pressed, the trigger23() function will run
   * and the code inside will be executed once
   */
  Serial.println ("SET button pressed");
  //myNex.readNumber("n61.val");
  interval = myNex.readNumber("n61.val"); // Store to interval the value of numeric box n61
  delay (100);
  Serial.println (interval);
}  

```

With this, I can see the value on Serial.print that I placed in the n61 Number field.

This is now working as long as I don't restart/reset my Arduino, if I reset or cut power to Arduino, the "interval" value is not saved.

This is where I'm at, not sure on how to save the value in memory, or EEprom so that it is save after a reboot...

Newbie here :o(

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [March 21, 2024, 2:29am UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101/25 "2024-03-21T02:29:09Z")

</div>

> Ok, the variable
> 
> ```arduino
> interval = myNex.readNumber("n61.val"); // Store to interval the value of numeric box n61 
> 
> ```
> 
> was located above void setup()

> [@papagino](#):
>
> The sketch has over 600 lines and I am only half way in the project...

You say you are a newbie but you are wasting your time if you don't understand the fundamentals of Arduino programming, variable declaration, variable assignment.

It's my fault that I did not ask for more code from you, but it never occurred to me that you were this deep into a project and thought that you could put myNex.readNumber( ) above setup and before the statement of myNex.begin( ) in setup().

Working the Nextion library examples would have shown you how to structure the code.

---

<div class="post-metadata">

**Author:** ![papagino](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/papagino/32/1098795_2.png) [@papagino](https://forum.arduino.cc/u/papagino)\
**Post date:** [March 21, 2024, 3:29am UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101/26 "2024-03-21T03:29:04Z")

</div>

Yep, it all make sense now, yes, even if my sketch has over 600 lines (including comments of course), they're obviously not my entire creation.  
I have over 10 libraries used in this sketch for this project.

I used examples in those libraries, try to make sense of it as I am learning all this, and modified the codes for my project.  
Some of those codes are not from libraries, but rather from existing projects I found online.  
Probably why I'm a bit confused with all this.

The original code

```arduino
const long interval = 10000; 

```

was from a project I found online, it was located above the void setup(){ .  
I wanted to change the fixed value of 10000 to something I would be able to change via the Nextion Display, never noticing that it was in fact above the statement of myNex.begin( ) in setup().

I still have a lot to learn... but I think I will figure it out.

Thanks for shining lights on this...  
Cheers

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 17, 2024, 3:29am UTC](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101/27 "2024-09-17T03:29:58Z")

</div>

Closed on September 17, 2024, 3:29am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/sending-numeric-value-from-nextion-display-to-a-const-long-variable-using-easynextionlibrary/1237101.md?page=1)
