Nextion button - arduino problem.

I've tried to do that with hardware serial with pin 0 and 1, but nothing. I really don't know why it doesn't work.

If you see that:

My code is the same. I'm using only three attributes: one button and two numbers.

A better communication strategy (sending only changes) would help anyway.

#include <Nextion.h>
#include <Time.h>
#include <TimeLib.h>
#include <SoftwareSerial.h>
int hour_ = 16;
int min_ = 0;
SoftwareSerial nex_com(10, 11); // RX, TX
NexButton b1 = NexButton(0, 5, "but");
NexTouch *nex_listen_list[] =
{
  &b1,
  NULL
} ;

void setup() {
  nex_com.begin(9600);
  Serial.begin(9600);
  delay(500);
  nex_com.print("baud=9600");
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
  setTime(hour_, min_, 0, 12, 4, 17);
  b1.attachPop(b1PopCallback, &b1);  
}
void loop()
{
  nex_com.print("n0.val=");
  nex_com.print(hour());
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.print("n1.val=");
  nex_com.print(minute());
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
    nexLoop(nex_listen_list);
 }
void b1PopCallback(void *ptr)
{
  hour_ = (hour_ + 1);
  nex_com.print("n0.val=");
  nex_com.print(hour());
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
}

Do you think, does it have reason about It that the code doesn't work?

I've seen your code, I don't need videos of its failure ore something unrelated.

Change your code to set hour_ and min_ only if they change,
or - for testing - don't set them at all.

What is your setting for the communication port in NexConfig.h ?

I have

/**
 * Define nexSerial for communicate with Nextion touch panel. 
 */
#define nexSerial Serial2

There is no

    nexInit();

in setup.

Yea, but that is no the problem. I've changed Serial2 with Serial for my arduino Uno. It's happening nothing.

I think I should change the all code with something that examples give me.

But the question is why this code is not working?

I give up.

Good luck with your project.

I give up.

Good luck with your project.

Thanks.

Can someone helps me????????????? ;( :frowning:

Barca1991:
Thanks.

Can someone helps me????????????? ;( :frowning:

you made some changes that may or may not be trying to use Serial2 on an Uno...

Where is your code now?

#include <Nextion.h>
#include <Time.h>
#include <TimeLib.h>
#include <SoftwareSerial.h>
int hour_ = 16;
int min_ = 0;
SoftwareSerial nex_com(10, 11); // RX, TX
NexButton b1 = NexButton(0,5 , "but");
NexTouch *nex_listen_list[] =
{
  &b1,
  NULL
} ;

void setup() {
  nex_com.begin(9600);
  Serial.begin(9600);
 
  delay(500);
  nex_com.print("baud=9600");
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
  nexInit();
  setTime(hour_, min_, 0, 12, 4, 17);
  b1.attachPush(b1PushCallback);  
}
void loop()
{
  nex_com.print("n0.val=");
  nex_com.print(hour());
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.print("n1.val=");
  nex_com.print(minute());
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
    nexLoop(nex_listen_list);
 }
void b1PushCallback(void *ptr)
{
  hour_ = (hour_ + 1);
  nex_com.print("n0.val=");
  nex_com.print(hour());
  nex_com.write(0xff);
  nex_com.write(0xff);
  nex_com.write(0xff);
}

This is my code, I wandered yesterday, but I couldn't solve a problem. Can you help me

Does your code work in the simulator?

The three people who have been trying to help you are masters...Jedi's. You must pay close attention to their instruction and follow their advice. I have learned a ton from all three of them. For example if it is suggested that you use code tags then you should use code tags. If you do not know what code tags are, then maybe you should attempt to find an answer on your own. Don't embarrass yourself by asking questions of the Masters that you should know.