Start a new topic

Arduino and Nextion push button

Hello guys, bought a nextion display and I really struggle with it. Display will be connected to arduino, but i want to change pages form 2 push buttons not from nextion.



How can i make this happend ? is it possible for arduino to control nextion - pushing buttons ? 


Can anyone help PLEASE ? 

Good luck! You're NOT gonna get help here or anywhere for that matter. 


I bought a 7 inch enhanced display about a month ago and I still can't get it to do anything with the Arduino Uno. Their documentation sucks their videos suck and their tech support sucks. Three strikes and you're out. It's nothing more than a $95.00 dollar paper weight.


1 person likes this

so true....  :(

The documentation is fine.

You should have some basic skills!


Check the function at Touch Release "Send Component ID" in Nextion Editor for the button you want to use in Arduino.

Now if you added the library correct you will have the callback to use the button for whatever you want.


It is not so hard and you can use the examples as a how-to.


The library can be better and the displays can be better and faster with the serial communication but it is realy one of the easiest ways to do an easy GUI and Arduino project.


If you want help, upload your arduino sketch and HMI file. Then we can see where the problem is.

I am not  sure about the wiring and configuration of the Uno, i use hardware serials because of other MCU.


Let`s do it simple with this sketch:

Not tested but should work.

Just get rid of all that pointer stuff, it can be much better for beginning.

 

#include "Nextion.h"

// vars
int buttonvalue = 0;
char buttonvalue_char[2];

NexButton b0 = NexButton(0, 1, "b0");

NexTouch *nex_listen_list[] = 
{
    &b0,
    NULL
};

void b0PopCallback(void *ptr)
{
  // JUST PRINT SOMETHING THAT WE KNOW THE BUTTON IS PRESSED AND THE FEEDBACK IS OK
    Serial.println("button pressed");

// INCREASE THE VALUE WE WANT TO SET AS TEXT TO THE BUTTON
    buttonvalue++;
    
// CREATE A CHAR OF THE INTEGER TO SEND IT TO THE BUTTON AS TEXT
itoa(buttonvalue, buttonvalue_char, 10);

// SET THE TEXT TO THE BUTTON
b0.setText(buttonvalue_char);
    
}

void setup(void)
{   
  // SHOULD HAVE bauds=115200 AS PREINITIALIZE EVENT IN NEXTION EDITOR 
  Serial.begin(115200);
    nexInit();
    b0.attachPop(b0PopCallback, &b0);
    Serial.println("setup done"); 
}

void loop(void)
{   
    nexLoop(nex_listen_list);
}

 

I tried the sketch you suggested above but it did not work. There was no errors when uploaded but there was no serial ommunicationat at all.


 // SHOULD HAVE bauds=115200 AS PREINITIALIZE EVENT IN NEXTION EDITOR

What does this comment mean?


I don't know how to set the baud in the

PREINITIALIZE event in the nextion editor. How do I do that?

 

If I change the baudrate back to 9600 baud in the Arduino code and the

serial monitor it does the same thing as before and write the Same messages

in the serial monitor.



 



Hi all,


I am trying to run the example CompButton display on an Arduino Uno provided by the Nextion Arduino Library but I can't get it to work.


If anyone else has successfully run this example and would like to see my setup its here.


 CompButton Example


Any help would be appreciated.


Thanks

Gene-


You don't have to set the baud but i recommend it.

Just clock on the first page in nextion editor and put this in the preinit:

bauds=115200

Now the display is set to 115200 baud.


I don't know about the nextion example, it should work but why don't you use my example?


just don't use the "Serial.begin(115200);"


It should work.

Everytime you press a button the value should increase.

you can also print it:

Serial.print("value: ");

Serial.println(buttonvalue);


Is it possible that your wiring is wrong?

Connect +5V to 5V on the Arduino

Connect TX to pin 2 on the Arduino

Connect RX to pin 3 on the Arduino

Connect GND to GND on the Arduino


Okay, I made the change using the nextion display editor  and recompiled it and put it on the display.


I am using the code you provided above.


I tried your wiring above but that does not work. I am using an UNO and I currently have it wired as such.


This is the only way I get any response from the button on the display using the original CompButton.ino file. I don't see what difference the baud rate is as long as it's the same for both display and serial monitor. In ant case it does not work.In fact none of the examples work with the arduino uno board.


Again my Dropbox link is CompButton Example

 can anyone knows how to hold down a button,and thereby to order a value to grow?

for example:   keep pressing volume up push button, that send on serial the same command, until I release it 

 (without arduino)

This is possible with some work.

I recommend to use a timer.

Start Timer with touch press. the timer is used i.e. for 100ms to check if a variable like "button pressed" which is true with "touch pressed" and false with "touch released".

As long as touch is pressed TRUE the timer checks every 100ms and increase your value.

When you release the button the signal is FALSE and nothing happens.

Not so hard to do that.


1 person likes this

nice tips, I will try, hope to work
thank you Alex !

  my best regards, from alex :)

Hi!

Please help me!

I don't know that it is a bug or not,but:

I made a work with nextion and arduino. So I have a lot of buttons on my nextion which have to do a lot of things by the arduino code.

but the buttons which change pages and 2 other button which work as switch don't work well or just rather rarely. The another buttons works well. So what I could do? Where is the trouble?

Thank you!

1) issue a touch_j command to recalibrate touch sensors.

    screen will ask for 4 corner touch points to be pressed,

    reboot when completed


2) check that the button .id attribute in the HMI file is what is in your code file.

Login or Signup to post a comment