@fantasydoom, @sanjoy-roy345 and other Nextion users,
I’ve added new functionality to my Nextion library and created a tutorial on hackster. The library can now detect touch events and keep track of page changes.
Happy xoding!
@fantasydoom, @sanjoy-roy345 and other Nextion users,
I’ve added new functionality to my Nextion library and created a tutorial on hackster. The library can now detect touch events and keep track of page changes.
Happy xoding!
Oh man…I am SO tempted to buy one of these displays & a mega now…
Dear Sir,
I have tested your new Nextion library. It is well organised and very useful documents. I am personally very thankful for help. Keep it up Sir with new great library.
Regards,
Sanjoy
Gracias @wayland, la comunidad XOD seguro que estará beneficiada una vez más por este tipo de aportes.
Dear Wayland,
I am facing the same problem on a different page. Previous page data getting lost. I want to turn on the button and remain on until not turned off. I have attached an example. Please modify it and send it to me.
Thanks
Sanjoy Roy
XOD_NEX.xodball (13.8 KB)
(Attachment xod-gui.HMI is missing)
Hi @sanjoy-roy345,
Thanks for the feedback. It looks like your HMI couldn’t be uploaded because it isn’t a supported file type. No worries, I’ve been able to replicate the problem. There are actually two issues: (i) maintaining the state of a button when the page changes, and (ii) failure of the arduino to read the state (value) of a button.
Maintaining the state of a button when the page changes
For the nextion display to remember the value of dual-state button when the page changes, the vscope (variable scope) property of the button must be set to global, e.g.:
The default is local. I hadn’t realised this - I’m still learning!
Failure to read the state of the button
Internally the read-number node uses a function called readNumber to read the value of the specified attribute of an object. In the case of the val (value) property of a dual-state button, a successful read will return 0 if the button is off and 1 if the button is on. However, if readNumber is unable to read the value of the button it will return 777777. The read-number node was returning the 777777 error code, which was potentially a problem. For example, when reading a button, a non-zero value would be interpreted as on.
I’ve now modified the read-number node so that it only outputs valid numbers (i.e. anything that isn’t 777777). I’ve also added a new pulse output Read which fires on a successful read of a valid number. The Done node fires on all attempts to read a number.
Example
Here is an example that I think demonstrates the issues have been resolved.
N.B. Please install the latest version (0.0.4) of my nextion library before trying this example.
XOD Patch:
HMI
Page 1:
Download link for HMI:
https://github.com/WaylandM/xod-nextion/raw/master/hmi/Sanjoy.HMI
Dear Wayland,
It’s looking like that project what I was waiting for such a long time. Thanks again for your speedy reply.
Regards
Sanjoy
Dear @wayland
While working with Nextion V4 I have found this two problems 1)How to implement Ex-ReadCustomCommand-Page-2 from GitHub - Seithan/EasyNextionLibrary: A simple library for Nextion display that uses only four functions. You can easily benefit from Nextion's wide range of features and advantages in just a few easy steps. The library uses a custom protocol that can prove to be a powerful tool for advanced users as it can be easily modified to meet one’s needs. in your library. And another 2) I found issue for example-when n2 number is selected in keyboard mode, after implementation n2 number in keyboard, the previous and current page number is changing to same page number. So data getting lost that two pages.
Thanks
Sanjoy
Hi @sanjoy-roy345,
I didn’t attempt to implement the easyNexReadCustomCommand function from Seithan’s EasyNextionLibrary, because I didn’t think there would be much demand for it. Also, I thought that the nodes I’d created would provide users with all the functionality they required. However, I’ve probably overlooked some use cases. Please could you describe how you would like to use custom commands and I may be able to suggest an alternative approach, using the existing nodes.
I can’t tell what the 2nd problem might be from your description. Please can you share your XOD patch and HMI file?
Dear @wayland
I have solved the first problem with help of your nextion example04-touch-event. That example I have changed n0 value from printh 23 03 53 03 to printh 23 03 53 and added second line prints n0.val,1 then It works.
I have shared XOD patch but not able to upload HMI file. Here some screen shots I have shared.
Thanks
Sanjoy
Hi Sanjoy,
It appears that the preinitialize event of the current page is called a 2nd time when the numeric keyboard is used. This means that the Nextion sends the page change notification ( printh 23 02 50 XX
where XX
is the page number) to the Arduino twice. Each time this notification is received, the EasyNextionLibrary updates its currrent and previous page IDs as follows:
This works fine every time for the current page ID, even if the same page change notification is sent multiple times. However, if the same page change notification is sent more than once, the previous page ID will be updated to the current page ID.
I’ve now updated my fork of the EasyNextionLibrary to fix this issue. To get the new version of the library you will need to delete the old arduino library from your system. Shutdown XOD IDE, then navigate to the following location in your home directory: xod\__ardulib__
. You should see a subdirectory named EasyNextionLibraryXOD
. Delete EasyNextionLibraryXOD
, then restart XOD IDE. Next time you try to use the XOD Nextion library, the latest version of EasyNextionLibraryXOD will be downloaded automatically.
A couple of other things to note. I saw in your XOD patch that you are using the Arduino’s first hardware serial port for communication with the Nextion. If you have an Arduino with multiple hardware serial ports (such as a Mega), I would recommend reserving the first serial port for programming/debugging and using a different serial port for communicating with the Nextion. You cannot use a single serial port to simultaneously debug and communicate with the Nextion.
Secondly, trigger commands from the Nextion should be of the following format:
printh 23 02 54 XX
where XX
is the numerical ID of the trigger in hexadecimal notation. See Use Nextion displays with XOD - Hackster.io
Hope this helps!
Hi @wayland
I have replaced EasyNextionLibraryXOD as you told and tested your all nextion example. I found that ex4 touch event is not working after updating. Then I tested with old EasyNextionLibraryXOD, the ex4 touch event was working but previous keyboard problem was there. Please see the issue. Now I have tested all the ex with Mega and serial1 with debag. Secondly, is it possible to get one more hex like(printh 23 02 54 XX XX) from Nextion to in your library.
Thanks wayland giving your precious time for XOD.
Sanjoy
Hi @sanjoy-roy345,
Thanks for testing the library. I’ve fixed the bug you reported (and learnt a bit about scope in C++ case statements along the way). If you reinstall EasyNextionLibraryXOD as before, then everything should work. I’ve tested the updated library with two of my examples (4 and 5) and with the example you sent me.
How would you like to use the additional byte in your example printh 23 02 54 XX XX
?
Hi @wayland
I have send your email two HMI (1.Source_HMI and 2.Set_result) files and one XOD Patch (Set_result) file for your reference. I modified the first HMI to second one and tested XOD Patch. Its working fine. From first HMI I got this type of byte as I told you and you can see screen shot. I was unable to figure out this type of byte. So I used buffer node to transfer the number data from Nextion to Arduino Mega. It is working nicely. What I am thinking there may be other way to solve the problem. Now my most of the problem have solved and we came to close to end of helpful nextion discussion.
Set_Result.xodball (40.0 KB)
Thank you
Sanjoy
Hi @sanjoy-roy345,
Thanks for sending me the xodball and HMI files. For the benefit of other readers, your Nextion user interface looks like this:
The values of n0, n1, n2 and n3 are adjusted using the + and - buttons. If I’ve understood correctly, when you click on SET button b2, you want to send the value of n0 to the arduino. The arduino will then write this value to n4. The other SET buttons will be used in a similar way.
In the touch release event of b2 you had the following code:
printh 23 03 53 00
prints n0.val,1
These instructions are not understood by the EasyNextionLibrary. Without modification, the EasyNextionLibrary understands only two types of commands:
printh 23 02 50 XX
printh 23 02 54 XX
The design of the EasyNextionLibrary does make it easy to add custom commands, but this involves modifying the library. However, I think that you should have all the functionality you need without having to define new custom commands.
In the Touch Release Event of you SET buttons you should put the following code:
printh 23 02 54 00
printh 23 02 54 01
printh 23 02 54 02
printh 23 02 54 03
Then you can use the following XOD patch on your arduino:
The listen node responds to triggers by outputting the numerical ID of the trigger from TrigID and sending a pulse from Trig. The trigger ID is used to identify which number box should be read and which should be updated.
Hi @wayland
I tested the patch, but it was not working with Source_ HMI. I think nth node is not giving right output. So I tested with debug but I found the same result. Then I replaced nth node with select node and I have done some modification. It was working. In this example how I can take four hardware output like LED please explain. I send XOD patch for your reference.
Source_HMI.xodball (18.7 KB)
Test_Number.xodball (10.2 KB)
Thanks
Sanjoy
Hi @sanjoy-roy345,
Did you modify Source_HMI.HMI as I suggested? Alternatively, did you try the Source_HMI_modified.HMI I sent to you by email yesterday? I tested Source_HMI_modified.HMI with for_source_HMI.xodball and they did what I expected them to (see post above) on my hardware (Arduino mega and Nextion Enhanced 7.0’’ HMI Touch Display NX8048K070_011).
If you simply want to switch LEDs on/off from the Nextion, I would recommend using dual-state buttons, as in this example:
https://www.hackster.io/wayland2/use-nextion-displays-with-xod-4a99f2#toc-example-3–dual-state-buttons-7
Alternatively, if you want to control the intensity of an LED, then you could read the value of a number box, slider or some other widget in the Nextion HMI and send it to the LUM pin of the LED node.
Hi @wayland
In my library xod/core was not updated that was the reason nth input was not functioning properly. Now I have updated. I apologize for the inconvenience.
Thanks for your suggestion.
Regards
Sanjoy
No worries. Great to hear that you’re up and running.
Just when I think I’ve finished prototyping a project, you bring Nextion into the game. Thank you Wayland, great work and back to the drawing boards for me!