Using the Nextion display: Hit a issue

A project log for Building the Thor robot

Building a 6-axis robot based on the Thor robot. When size DOES matter!

Olaf Baeyens 08/20/2017 at 12:350 Comments

When developing the Arduino code I appear to have an issue when I use the Dual-State button.

As far as I have learned, in the Arduino I need to instantiate an  object from class NexSDButton  with the the page number and object ID per button. (The description is important when you send commands to the Nextion display)

So I created some constants for the pages and the buttons to define them. I do not seem to be able to change the ID once I created the button in the Nextion editor.

(The NexSDButtonExt will be explained later)

The implementation of NexSDButton hides the pageID (pid) and the ComponentID (cid). I need that access because I want to have only one call-back. Not 100's of call backs for every

By inheriting from NexSDButton I extend the class NexSDButtonExt and expose the methods: getObjPid() and getObjCid()

My call-back can now be simplified. Code above shows for MotorControl_Page and MotorEnable_E0_ID I will activate the debug LED when the state = 1 and shut off the debug LED when state=0

Only it does not work. I see no state change at the Thor part.

(The code works perfectly inside the Nextion HMI processor)

Going to the debug screen in the Nextion editor I can see what commands are being send to the Thor controller. You recognize the second byte as page 1 and the third byte the component ID in hex. The components state which is "1" and always "1" when I click the button on or off. I think this is the reason why I only see a "1" state at the Thor controller side.  (Incorrect!)

UPDATE:  I checked the code on the Nextion forums and it appears that this is normal. 0x65 is marked as "button click" event. The second 0x01 means "button pressed" and 0x00 means "button released".

The example code I found to get the value (bool buttonState = btn->getValue(&dual_state) ), seems to send a second request to the Nextion display for that particular value. Then it should return with it. For some reason the value never returns.

Compare it with a normal button and here you do see the state change.

I may have to revert to a simple button, or maybe use a "variable".  Whatever the solution is, I want the number of transmissions between the controller and the Nextion HMI as low as possible. A good solution no quick hack.