Actually, I'd do that in the Nextion code on the display.
In fact I would do as much as possible on the display and only what's absolutely required in the MCU.
What would you want to get notified about this way?
I'd rather push that info from the display and only "subscribe" to that event via a dedicated callback - as you would do for any touch interaction with the display.
This is called by a timer. But that is not the best way to do it. In the editor there are commands for making the screen go to sleep and wake up on touch. But on wake up it goes to the page it went to sleep on. What i am doing right now is forcing the page to change to the first page based on the timer and then the function for sleep kicks in right after on the now current page. “thsp” sets a timer from last touch but the timer i have set up is active from the moment the page is loaded. What i need is the page to time out from last touch and on wake up go to another page.
I agree with putting most of the program on the touch screen itself and believe me that is what i am trying to do. The only stuff that i want to set up via MCU are the interactive texts and pictures.
In Nextion Editor you can place a Timer component and a Variable component, increment the variable via a timer script, reset the variables via any other components on-touch/on-release script and fire a page select statement in the timer script when the variable reaches a certain value.
No action required by the MCU at all.
But if you want to notify the MCU you can also use printh or several other messages from the timer script to trigger a particular callback.
I’ve no Nextion display with me at the moment, so I can’t provide you a working solution, but I might be able to send you one next week.
What type display have you got?
I am using a NX4827T043_011. To increase the timer i would have to setup the variable to increase on touch of every component on screen. Worst part is that the timer has a limit to 65000 ms and i would actually want time out to be over 2 mins. As always i appreciate your advice greatly.
there is a timer attached to the above function in the MCU. So the page will goto splash regardless of whether the user touched the screen or not which is not a best practice thing. I am following what you are suggesting though now.
Timer starts the moment page loaded
button press resets the timer
as long as something is pressed or touched timer keeps updating.
Only issue is i would have to put that in all the components now. I have about 24 screens as off now. That is why was looking for a shorter way to do this.
Let me know when you can. Using the >= operator does make sense. Its doing what i intended it to do otherwise.
On another note
I also cannot get the screen out of sleep on reset of the MCU. What is the correct way to send a system command like “rest” or sleep=0 using the MCU?
Btw here’s a confirmed bug. Every single get from text or number returns a null in the HMI file i have been working on. The MCU program is fine and runs on another sample file. Set works fine. But i cannot get any value text or otherwise back from the Nextion. All i get is null.
I am using the same version. So i tested a few combinations yesterday and found out the reason i was getting a null. The button object also had a page change code in its last line. I am guessing the page changed before the MCU completed the getText and the text object was a local object so it always returned a null. I was using the same code with different test HMI files which did not have that page change on the button code that is why all the other tests worked. I am now calling the page change code for just those buttons in the MCU after get is completed.
How come the code you show here shows different from the code on my iphone mail.
That comes from a bad habit of mine
I tend to press Reply to quickly, then go back and reread what I just wrote and find errors which I then correct, but the mail notification on your phone will only give you the first version - which happened to be the code I tested against a more OOP-like v0.1.0 of that lib which is not yet public.
It is indeed a better implementation of the library. When will you be making it public. Having a getter for the screen object would make is easier to set constantly changing variables. Ex- i have temp and humidity values that are displayed on certain screens. I use a timer right now to update all of them every 30s.
I’m currently busy with other things, so not much progress there and I had some issues with templating the methods properly, so I got a bit stuck
You can have a look tho’ (but it’s rather messy at the moment)
I have a Float Switch that i want to connect to the Photon directly. I was thinking of hooking up the “+” to D1" pin and the " - " to D2. Set D1 to digitalwrite HIGH and then make a listener method that runs digitalread(D1) in the loop. When the switch is activated it will return a boolean.
I am a bit confused with the power ratings on the spec sheet of the switch. I only wish to run 3v through the switch coming from D1 and read if its received by D2. Is this possible or am i completely missing the point?
In the picture on that web page, it looks like the float switch is a magnetically operated reed switch so your plan should be fine. The data sheet for the switch seems to be saying that is can switch 0.28A (280mA) so you should be fine.