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);
}
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?
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.
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.
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
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
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.
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.
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.