Nextion Library and numbers above 65536

Hello everybody

I am using Nextion Library from bborncr; it is really easy and fast.

I have one issue: some of my settings data, which I enter in Nextion display, are above 2^16 (65536); for example (66000), I only received the rest after 65536, which was 464. So, any number above 65536 can't be received correctly. I tried with different values; all were correct except the numbers above 65536.
Please advise.

I moved your topic to an appropriate forum category @HayderIsmael.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

How variable type are you using? unsigned int?.
Try using unsigned long.

unsigned int is from 0 to 65535.

1 Like

What code do you use for that ?
What’s the type of your variable and what does the library expect as type of parameter?

1 Like

I'm not familiar with the library and you have not given us any clue about your code, so what follows is a general outline of how to approach this.

I am guessing you have some kind of keypad on your Nextion into which you enter your 'setting data' (for???). Each key press is a single digit with a value from 0 to 9, no where near the limit of 65535. You send the key presses to your Arduino and have the code on that assemble them into whatever number they represent.

Thank you for the reply.
I have many numbers with the keypad on the Nextion.
The function of receiving these values, for example, is

  NexSmplFrSP = myNextion.getComponentValue("fr.smplfrsp"); 

So if the "fr" is less than 65535, I got all the values correctly. I receive incorrect values if the "fr" is larger than 65535. I think there is a problem in the library itself as it is set to receive int not long. However, I am not sure how to fix the library.

This function defined in the library as int and I am not sure how to fix the library.

Thank you

Thank you, @ruilviana, for your respond.

Yes, my variables are unsigned long. The problem is the library only uses unsigned int, and I do not know how to fix it.

the library has this interface

so setComponentValue takes an int which is 2 bytes on a UNO and the likes or 4 bytes on a 32 bit platforms like the MKRs or ESPs

if you are on a UNO it should not even be able to display more than 32767


the way you could work around this is by providing the textual representation of what you want to see. the library also offers

so you could call

  myNextion.setComponentValue("dashboard.fr", String(FS_1_FlowRate_mill));

side note : I'm not overwhelmed by the quality of the code in the library since it does not even use references for all the String parameters... seems a recipe for disasters. (but I don't use Nextion's screens anyway, so ...)

My sincere apologies, @J-M-L , I meant to say

  NexSmplFrSP = myNextion.getComponentValue("fr.smplfrsp"); 

getComponentValue is also only int.

A few years ago, the library developer fixed the problem with myNextion.getComponentValue by changing it from int to long.
In myNextion.getComponentValue, it is more complicated for me as many lines and sorts of arrays need to be fixed, too.

Again, I am so sorry for putting the wrong function.

use getComponentText() and then use the usual functions to convert the text into the number you want

➜ work with text instead of numbers

1 Like

Do you have more than 32767 individual keys on the keypad? Any reason you could not use a translation table, using the number from the keypad as an index into a table of long integers on the arduino?

Thanks, @david_2018, for your reply
I am not sure I understood the suggestion. What did you mean by 32767 individual keys?
To avoid receiving numbers larger than int, I added variables in Nextion and a timer to divide my values by 100, then in Arduino code I did the following

  NexSmplFrSP = myNextion.getComponentValue("fr.smplfrsp") *100; 

it can be useful but using extra variables in Nextion and timer would eat the memory.

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