Go Down

Topic: How to get a value Nextion editor (Read 235 times) previous topic - next topic

samueljanes

Hi Perry,
Thanks for your postings in this forum.
I would like to know if it possible to read a value from Nextion, just when my Arduino needs it and NOT SEND it from Nextion to Arduino.
Let me explain better what I pretend:
In Nextion I have a page0 where my Arduino updates several data.
I also have page1 and page2 where I can change some values (parameters) that goes to page0 too.
Time to time (not in every loop) my Arduino sketch needs to know a parameter value that is printed in page0.
Question: Can I read that parameter value when I need it (and only when I need it)?
                Can I do this without using a Library?

Thanks in advance for your time.

ballscrewbob

@samueljanes

TOPIC SPLIT
PLEASE DO NOT HIJACK / NECRO POST !


Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.


It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google (who would have thunk it ! ) or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

PerryBebbington

Hi samueljanes,

I'm sure you can but that's not how I designed my methods. I think of no good reason to not send data from the Nextion when it becomes valid or updated. If you explain a bit more about what you are really trying to do then maybe I can help you.

samueljanes

#3
Nov 19, 2020, 12:13 pm Last Edit: Nov 19, 2020, 08:47 pm by samueljanes
Hi again,

First off all I apologize to Global Moderator about the misplaced question, but was no bad intentions.
I just wanted to make sure I interact with Perry. Sorry.


@Perry:



The problem is:
My Arduino controls the temperature and humidity (among other things) in a cheese chamber.
When my Arduino detects something wrong beeps and the user must act immediately changing (or not) a parameter for a new value (in Nextion).  BUT the Arduino cannot react immediately because, with cheeses, everything must be slow. Arduino must wait till the right moment to activate the new parameter value (this can took 1 or 2 days). So, when Arduino find the right conditions in the chamber, needs the new parameter value to initiate a new cure cycle and this is the moment I need to read the value witch is on the Nextion page0.
So, I don't want to have a function/procedure executed periodically to read the Nextion Serial. We can say, the goal is Arduino is the MASTER and Nextion, a mere SLAVE.
You may say: when Arduino beeps, the user change the parameter and Arduino stays waiting the new parameter and keep it till is needed. The problem is the user may not hear the beep for several hours and the Arduino must go one, controlling a lot of things in the chamber.

PerryBebbington

#4
Nov 19, 2020, 09:25 pm Last Edit: Nov 19, 2020, 09:29 pm by PerryBebbington
Hi Samuel,

I infer from what you have said that you are new to this and have not yet learnt to write cooperative non blocking code. I am guessing your code is full of delays and possibly while loops waiting for something to happen. I am also guessing you have put quite a bit of work and thought into it and you will find the idea of re-writing it daunting and perhaps frustrating.

There is absolutely no difficulty in writing code that receives the information from the Nextion when the Nextion sends it while continuing to do the other monitoring and controlling you mention, and probably a whole lot more as well, you just need a different approach. This is the point when you start your transition from beginner to experienced programmer.

I am not going to give you custom lessons because there are plenty of examples of what you need on here and in the IDE, you need to learn how they work and incorporate them into your design. You will probably have to start again (sorry!) but what you have done will give you a good idea of what to aim for; you are trying to do the same things, just in a different manner.

Some relevant tutorials:
https://forum.arduino.cc/index.php?topic=261445.0
https://forum.arduino.cc/index.php?topic=503368.0
https://forum.arduino.cc/index.php?topic=223286.0
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html
https://forum.arduino.cc/index.php?topic=710998.0

Also, the sample code in my tutorial Using Nextion displays with Arduino is entirely non blocking an is in the style you need to learn.

There is also plenty of discussion on this in the forum as this is a common thing beginners have to learn as they try to deal with more complex problems, please do so reading.

Finally, here is a real world example of how I think your code is written now and a hint of how it should be written:
You wouldn't expect this when you go into a restaurant:
A waiter meets you at the door, takes you to a table, gives you a menu then waits by your table while you decide what to order. The waiter takes your order, goes to the kitchen and waits there while the chef cooks your food. However, as the staff in this restaurant only ever deal with one customer at a time your waiter has to wait with other waiters while the chef cooks 5 other meals before starting on yours. When the food is eventually ready the waiter brings it to your table then waits by your table while you eat it. When you've finished eating the waiter takes your plates away and returns to ask if you want anything else.  This continues until you leave. No one else gets served. This is how your code is working at the moment.
I'm not going to describe what really happens in a restaurant as you already know. A waiter uses exactly the same system as a state machine to serve people when they need serving and check to see who needs serving next between dealing with customers. You can build functions for the different tasks a waiter does such as:
Code: [Select]

void takeOrder();
void bringFoodToTable();

You call these from loop(); While in loop the waiter checks to see if any tables need attention, and if they do s/he goes to find out what they need. If not, then s/he keeps checking until someone needs something. Computer code should be written along the same principals.
See Demonstration for several things at the same time for how to implement a state machine in software rather than in a restaurant.
Also look at Using millis for timing, which is also relevant as frequently millis timing and a state machine are used together.


Good luck!


samueljanes

#5
Nov 21, 2020, 08:30 pm Last Edit: Nov 21, 2020, 09:41 pm by samueljanes
Hi Perry,

THANK YOU very much for you elaborated answer and for your time: you are a TEACHER.

I carefully studied all the information sent.

A little bit of history:
That solution I described before: "Chamber Cheese Cure Controller", is working fine for the last 3 years continuous 24/7. In actual design, I use potentiometers for the user settings with an oled screen, and works perfectly.
Then, I discovered Nextion and it becomes a "nice to have" for Version 2 of my device.
To have a NEW DESIGN of the same device without potentiometers and a touch screen for settings, becames my goal for this new version.
I have no problem, at all, to rewrite the solution.
My question was: preserving the Version 1 (AnalogRead's of the potentiometers) to have a reading of the setting values, that are present in page0 in Nextion.

Just suppose a music jukebox that is playing 5 musics in a row with a volume, let's say, 2 and in the meanwhile, you put a coin for a new set of 5 songs  but you want a volume of 7 and adjust it.
The jukebox MUST finish the current set of musics (at level 2) and then starts your set of your 5 musics at the yours level chosen.  Only when your set of musics starts, the jukebox will read the volume you chose.

Will be this, a new paradigm for the most advanced programing thecnics with Nextion and Arduino?
You said: "I'm sure you can but that's not how I designed my methods."
 
Thanks in advance for your thoughts.

PS. I thought about in another example against your restaurant example:
If you have an accident and need go to a hospital, you arrive in an ambulance, enters and you need 6 doctors to care of you you. Will they treat others in the meanwhile?

PerryBebbington

#6
Nov 21, 2020, 09:25 pm Last Edit: Nov 21, 2020, 09:31 pm by PerryBebbington
In your jukebox example it would read the volume when it was set, remember it and use the new setting with the appropriate record. No need to defer reading the setting, just need to keep track of which setting relates to which record.
DEEP PURPLE: Everything louder than everything else (careful not to burn the place to the ground)
MORRISSEY: Minimum volume (don't want any suicides)

The restaurant example applies everywhere and to everything in life; how many jobs do you do every day where you start something, leave it for a bit then come back? Do you wait by the washing machine while it washes your clothes? Do you cook only potatoes and only start peeling carrots once the potatoes are cooked? Do you plan your holiday, tell your boss you want a week off, pack your stuff and leave for the airport all on the same day (I know!)? Did you sit by your computer waiting for my reply while doing nothing else at all?

At every step in the program you test to see if something needs doing immediately, if it does you do it, if not you move on to check the next thing. If you get some information form the Nextion before you need it you save it somewhere so when it is needed it's there waiting.

samueljanes

Sorry, I've just updated my post with an example I remembered while I cooking my dinner

PerryBebbington

#8
Nov 21, 2020, 10:57 pm Last Edit: Nov 21, 2020, 10:58 pm by PerryBebbington
Consider the question in the context of the doctor's whole working day. 1 big difference between what humans do and what a processor does is the timescale. The processor only ever does one thing at a time, but unlike you and me it can easily do 100000 or a 1 million things in 1 second. The principal is the same, however.

samueljanes

Ok. Let me mature it in my mind.

My big problem is about a cheese chamber with 6 cheeses and if ONE cheese has a problem, the Arduino must treat it and watch if the others 5 are not suffering with the treatment for that one.
Then multiply this for 100 chambers, 600 cheeses maturating at the same time and sending info to a server that have a Management Board with semaphores per chamber and per cheese.
It's something big for adventures and for a new version with Nextion's as I told early.
We are talking about a business family with 600.000€ of invoicing/year.

This new version must be maturate (slowly like a cheese) and with, at least, one year of  prototype testing.

Thanks any way for your efforts.

PerryBebbington

Sounds very interesting. Are you in the UK? East Midlands?

Very tentatively I might be interested in getting involved.

Go Up