I am working with a Particle Electron board and a Nextion Enhanced HMI,

I am working with a Particle Electron board and a Nextion Enhanced HMI, and I can not read the numerical value I write from the Nextion HMI with a keybdB, to verify that the Electron board manages to read this value I try to show it in another numeric box.
My code is based on the examples that there are for Particle board.
I hope you can help me
Thanks

#include "Nextion.h"
#include "Serial4/Serial4.h"
USARTSerial& nexSerial = Serial4;
void n0PopCallback(void *ptr);
void n1PopCallback(void *ptr);
void n2PopCallback(void *ptr);
void b0PopCallback(void *ptr);
void b1PopCallback(void *ptr);
/*
* Declare a number object [page id:0,component id:3, component name: "n0"]. 
*/
NexNumber n0 = NexNumber(0, 3, "n0");
NexNumber n1 = NexNumber(0, 4, "n1"); //input sp temp
NexNumber n2 = NexNumber(0, 5, "n2"); //Show SP Temp
/*
* Declare a button object [page id:0,component id:1, component name: "b0"]. 
*/
NexButton b0 = NexButton(0, 1, "b0");
/*
* Declare a button object [page id:0,component id:2, component name: "b1"]. 
*/
NexButton b1 = NexButton(0, 2, "b1");
char buffer[100] = {0};
char buffer2[100] = {0};
int LED=D7;
/*
* Register object n0, b0, b1, to the touch event list. 
*/
NexTouch *nex_listen_list[] = 
{
&n0,
&n1,
&n2,
&b0,
&b1,
NULL
};
/*
* number component pop callback function. 
*/
void n0PopCallback(void *ptr)
{
dbSerialPrintln("n0PopCallback");
n0.setValue(50);

}
void n2PopCallback(void *ptr)
{
dbSerialPrintln("n2PopCallback");
n2.setValue(50);

}
/*
* Button0 component pop callback function.
* In this example,the value of the number component will plus one every time when button0 is released.
*/
void b0PopCallback(void *ptr)
{
uint32_t number;

dbSerialPrintln("b0PopCallback");
n0.getValue(&number);
number += 1;
n0.setValue(number);

if(number) 
{
digitalWrite(LED, HIGH);
}


}
/*
* Button1 component pop callback function.
* In this example,the value of the number component will minus one every time when button1 is released.
*/
void b1PopCallback(void *ptr)
{
uint32_t number;

dbSerialPrintln("b1PopCallback");
n0.getValue(&number);
number -= 1;
n0.setValue(number);

if(number) 
{
digitalWrite(LED, LOW);
}

}
void n1PopCallback(void *ptr)
{
uint16_t len;
uint32_t number;

dbSerialPrintln("n1PopCallback");
n2.getValue(&number);
n2.setValue(number);
} 
void setup(void)
{
/* Set the baudrate which is for debug and communicate with Nextion screen. */
nexInit();
/* Register the pop event callback function of the current number component. */
n0.attachPop(n0PopCallback);
n2.attachPop(n2PopCallback);
/* Register the pop event callback function of the current button0 component. */
b0.attachPop(b0PopCallback);
/* Register the pop event callback function of the current button1 component. */
b1.attachPop(b1PopCallback);
n1.attachPop(n1PopCallback);

dbSerialPrintln("setup done");

pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
digitalWrite(n2);

}
void loop(void)
{
/*
* When a pop or push event occured every time, 
* the corresponding component[right page id and component id] in touch event list will be asked.
*/
nexLoop(nex_listen_list);
}

image

image

For me that code works.
Have you double checked your wiring?
Is your display running on the default baudrate 9600?

Hello @ScruffR
Thanks for answering my problem

I understand that my connection is correct, because a part of the code itself works.
But when I write a number from the keyboard it is not visible on the numerical display.
About the baud I understand that it is in default, I want to review it, but sincerely I have no idea how to validate that information.
Is there another way to solve that topic?

image
image

Thanks

When you start an SD update the device tells you what default baudrate has been set on it.
The library uses 9600 as default, if your display has been set to anyhting else you should provide that baudrate via nexInit(yourBaudRate) (e.g nexInit(115200)).

With your code above I do geht the increment/decrement when hitting the respective buttons and when I tap the number controls the values get updated to 50.
In your case, what works and what doesn't?

BTW, for a number pad like in your first image I'd do the actual key handling on the display without even involving the Electron. It should be enough to transfer the final result when you hit OK.

@ScruffR
It’s correct, the baud rate is (9600)

That is working: "I do get the increment/decrement when hitting the respective buttons and when I tap the number controls the values get updated to 50".

That is not working:
What I’m trying to do with the keyboard (n1) and the number (n2), is to verify that n1 sends the value to the electron and shows it in n2, that’s what I can not do, this I’m trying to do to be 100% sure I’m writing a value in the electron.

I hope, I explain myself well.
Thanks.

If I understand correctly, I'm not surprised that it doesn't work as expected since you do this

void n1PopCallback(void *ptr)
{
uint16_t len;
uint32_t number;

dbSerialPrintln("n1PopCallback");
n2.getValue(&number);
n2.setValue(number);
} 

where you probably should do this instead

void n1PopCallback(void *ptr)
{
  uint16_t len;
  uint32_t number;

  n1.getValue(&number);
  n2.setValue(number);
}

You want to collect the value from n1 and send it to n2 - your original code sends the value n2 already contains back to it which seems to make little sense but worked as expected in my test :wink:

1 Like

Hello @ScruffR
Exactly that is what trying to do.

Thanks for the information, I already made the change, but it is not yet shown in value of n1 in n2.

#include "Nextion.h"
#include "Serial4/Serial4.h"
USARTSerial& nexSerial = Serial4;

void n0PopCallback(void *ptr);
void n1PopCallback(void *ptr);
void n2PopCallback(void *ptr);
void b0PopCallback(void *ptr);
void b1PopCallback(void *ptr);

/*
 * Declare a number object [page id:0,component id:3, component name: "n0"]. 
 */
NexNumber n0 = NexNumber(0, 3, "n0");
NexNumber n1 = NexNumber(0, 4, "n1");  //input sp temp
NexNumber n2 = NexNumber(0, 5, "n2"); //Show SP Temp
/*
 * Declare a button object [page id:0,component id:1, component name: "b0"]. 
 */
NexButton b0 = NexButton(0, 1, "b0");
/*
 * Declare a button object [page id:0,component id:2, component name: "b1"]. 
 */
NexButton b1 = NexButton(0, 2, "b1");


char buffer[100] = {0};
int LED=D7;

/*
 * Register object n0, b0, b1, to the touch event list.  
 */
NexTouch *nex_listen_list[] = 
{
    &n0,
    &n1,
    &n2,
    &b0,
    &b1,
    NULL
};

/*
 * number component pop callback function. 
 */
void n0PopCallback(void *ptr)
{
    dbSerialPrintln("n0PopCallback");
    n0.setValue(50);
      
}

// void n2PopCallback(void *ptr)
// {
//    dbSerialPrintln("n2PopCallback");
//    n2.setValue(50);
      
// }


/*
 * Button0 component pop callback function.
 * In this example,the value of the number component will plus one every time when button0 is released.
 */
 void b0PopCallback(void *ptr)
{
    uint32_t number;
    
    dbSerialPrintln("b0PopCallback");

    n0.getValue(&number);
    number += 1;
    n0.setValue(number);
   
     if(number) 
    {
        digitalWrite(LED, HIGH);
    }
    
  
}

/*
 * Button1 component pop callback function.
 * In this example,the value of the number component will minus one every time when button1 is released.
 */
void b1PopCallback(void *ptr)
{
    uint32_t number;
    
    dbSerialPrintln("b1PopCallback");

    n0.getValue(&number);
    number -= 1;
    n0.setValue(number);
    
     if(number) 
    {
        digitalWrite(LED, LOW);
    }
    
 }

_void n1PopCallback(void *ptr)_
{

_uint16_t len;_
_uint32_t number;_

 _n1.getValue(&number);_
_ n2.setValue(number);_
}   



void setup(void)
{
    /* Set the baudrate which is for debug and communicate with Nextion screen. */
    nexInit();

    /* Register the pop event callback function of the current number component. */
    n0.attachPop(n0PopCallback);
//    n2.attachPop(n2PopCallback);
   

    /* Register the pop event callback function of the current button0 component. */
    b0.attachPop(b0PopCallback);

    /* Register the pop event callback function of the current button1 component. */
    b1.attachPop(b1PopCallback);
    n1.attachPop(n1PopCallback);
    
    dbSerialPrintln("setup done");
    
    pinMode(LED, OUTPUT);
    digitalWrite(LED, LOW);

}



 

void loop(void)
{
    /*
     * When a pop or push event occured every time, 
     * the corresponding component[right page id and component id] in touch event list will be asked.
     */
    nexLoop(nex_listen_list);
   
   
}

Will you have any other advice that can help me?
Thanks

Regards

This is what works for me
https://go.particle.io/shared_apps/5c8216e2e1386c000a9af513

It behaves slightly different.
When you tap/release n1 I’m not transfering n1 to n2 but rather transfer the value from n0 - which you can increment/decrement via the +/- buttons - to n2.

This is my .HMI file for that sample

https://www.dropbox.com/s/g8zozl06l3rsr0l/test.HMI?dl=1

And here is a video that shows that it works

1 Like

Hello @ScruffR

Yes, it works a little different, but it works.

I think I can not use the keyboard as I had thought.

Thank you very much for the help

Why is that?
If you want to send me your HMI file with the actual keyboard I may be able to help.

Hello @ScruffR

This is my Nextion file:
https://drive.google.com/open?id=14B0n4Mcm3zn4PJ7ppfYZA6emSdSsVMUH

If you have problems downloading the file let me know.

thanks

Regards

I was actually hoping to get this HMI
image

Hello @ScruffR

I think it’s available, try again.
https://drive.google.com/open?id=1lNtwVtBtFIxBXL4_V9MgCSRceqrZoaS0

When press n0, the numeric keypad appears.

Thanks

I missed the overlay screen.
That explains things.
I’ll give it a go.


@eavendano, I think I found your issue.
You haven’t activated the event trigger for Touch Release (nor for Touch Press) which you have on the other components.

You also have no component n2 but only n0, n1 and t0 and the component IDs don’t match the IDs in your code.

It is true, I am very sorry, try to do other tests and forget that I had modified the project.

https://drive.google.com/open?id=1eDpZUgadE3q9BrBS6U6eLr4DLvMSYjen

I just returned to the original, I hope this helps.

Thanks

I can now see your problem and there would be a way to hook up the controller to the OK button of the keyboard, but I’d rather keep the controller out of the equation and just modify the OK touch release event to also update the n2 component.