Start a new topic

How many times a button is touched in NEXTION touch

Hi guys,

I have been looking in the forum and cannot find any help. Let's hope here someone can help me.

I am trying to count in arduino how many times a button B0 was touched in a NEXTION 2.8'' touchscreen.

I tried"b0.val")  but it does not work..

thanks in advance

Maybe this can help you :

- Send component ID on "touch pressed/release event" then count with your MCU each time you receive the component ID.
- Or : add a variable in your page, increment your variable each time the button is pressed, read the variable with your MCU when you want to know how many times the button was pressed.

Hi Robin,

thanks for your post, but how can I count whatever is sent to the serial port, I cannot figured how to count because what is send to the serial is not always the same, here it is:

Pressed button 1st time:





Pressed button 2nd time:




Attached my NEXTION file.

Here the code I am using to turn on / off led pin 13 and check what is going on in the serial port:


int char1,char2;
int charflag=0;

void setup() {

void loop() {
 if (Serial.available()>1) 
 if (charflag)  
  if (char2==0) digitalWrite(13,HIGH);
  else if (char2==0x01) digitalWrite(13,LOW);
   if(char1==0x65) charflag=1;


let me know your thoughts.

(344 KB)

Hi Felipe,

Did you solve that problem? I am trying to communicate with raspberry pi with python. I could write data from pi to nextion. When i try to read the data coming from nextion, i have the same problem as yours. Please let me know if you solved that problem.

Thank you.

Login or Signup to post a comment