Start a new topic

Arduino and Nextion button

Hi Guys,

I'm refering to a topic of 7 months ago ("Arduino and Nextion push button")

I did not find the final comeout and I have exactly the same problem:
I loaded the code of Alex (compbutton.ino) but the only response I get is :

(start up)
recvRetCommandFinished ok
recvRetCommandFinished ok
setup done

and everytime when I push the button, I get on the serial monitor:

[1005:0,5,b0]
[1005:0,5,b0]
[1005:0,5,b0]
[1005:0,5,b0]...

and notting appears in the button on the nextion display.
I don't even get the "button pressed" text on the serial monitor, so I presume that the code:
 
void b0PopCallback(void *ptr) { Serial.println("button pressed"); buttonvalue++; itoa(buttonvalue, buttonvalue_char, 10); b0.setText(buttonvalue_char);
}
 is just not executed...?

Worth mentioning is that the other elements work fine, fe. text, scrolling text, compslider,... ( not in this program - I cut down to the essence) 

Thanks!
Karl
HMI
(925 Bytes)
ino
(907 Bytes)
HMI

Did you do b0PopCallback.attachPush() or did you do b0PopCallback.attachPop()

because you need the first one if you want that it react on button press.


1 person likes this

As per the Nextion Instruction Set Touch Event Return Data

https://www.itead.cc/wiki/Nextion_Instruction_Set#Format_of_Device_Return_Data


Using your modified HMI file (so we are dealing with the correct file)

When you press button in the Debug you will see it returns

0x65 0x00 0x05 0x01 0xFF 0xFF 0xFF

This shows that your button is indeed returning data to your MCU.


As per the Iteadlib Arduino Nextion Library

NexTouch.h defines:

#define NEX_EVENT_PUSH (0x01)

#define NEX_EVENT_POP (0x00)


So how did you expect that your code

b0.attachPop(b0PopCallback, &b0);

was suppose to catch a press event from the checked Send Component ID

in the Touch Press Event of your Button Page0 id 5?

Hi Guys,


It works! In the Nextion editor, I sent out a "touch press" event, instead of a "touch release" event. You can use but you have to use accordingly b1.attachPush() ( yes, this exists but you will hardly find)  and   b1.attachPop() . (Very logical, afterwards and if you are native English spoken : press = push and pop = release)

 

So brief, use the program compslider.ino (of Alex - see also other post: Arduin and Nextion Push button) and make sure to sent out a "press release" event, that is an easy and good start. (And indeed: a good manual would make things a lot faster to understand.)


Best regards

Login or Signup to post a comment