Start a new topic

Send variable from Nextion display to Arduino

Hi, 


I want to send a 1 from Nextion display to arduino once a timer has ended.


I used the command  

print 1

 to send but I have no idea how to fetch this 1 value...


The goal is to change a variable in arduino once the timer has ended.


Any help pse.


Thanks in advance


To my didn't work it gives a lot error
There is some one the can write the right code for me please...

i have always the same error serial error and many more...

so thanks for your halp but i don't think you 

can help me




it seems that does not call the library...

and point 2. include the library is #include <Nextion.h>

not # include "Nextion.h"

If you can't get from the example given

no one is going to write your program for you

- You must learn and code it yourself.


if you are using ITEAD Library

Use


NexVariable va0 = NexVariable(0,1,"va0"); 



add &va0 to your Nex_listen_list 


in your loop or when you have a function callback, use, va0.getvalue(&number) and va0.sendvalue(&number) 



If you can attach your .ino file and HMI file. I can take a look into that.

When your compiler gives errors it is not enough to say it has given errors.

You must look at the errors that it gave to solve your compile error.

This is basics of programming.


No one can see what errors was given

(and don't want to either - so please do not post 200 lines of compile errors)

Can I attach the HMI file and then you tell me which will be the best code o way?

Francesco


Please download and install the Iteadlib Arduino Nextion Library

If you need the link let me know.  Let me know when this task is complete

Task 2: Open the CompNumber_v0_32.HMI attached below

- Ensure to change the settings for your Nextion Device Series and Model

- Ensure to Save the file so that it is saved in v0.43 format from the Nextion Editor

- Build this HMI and upload to your Nextion Device.

HMI

Task 3: Open the corresponding CompNumber_v0_32.ino file below.

Examine the code.


Number component is defined near top as


     NexNumber n0 = NexNumber(0, 3, "n0");


To read a number from the n0 component you need an Arduino side variable of type uint32_t

Look at the b0PopCallback function you will see number is declared


      uint32_t number;


You will see two lines down where the read is done.


      n0.getValue(&number);


To send this value to serial monitor you need to use dbSerialPrintln


      dbSerialPrintln(number);


To set the number on the Nextion use the setValue function


       n0.setValue(number);


To have Arduino listen for a Touch Press/Release Event the n0 needs

to be included in the nex_listen_list[], you will see this near the top


       NexTouch *nex_listen_list[] =

       {

           &n0,

           &b0,

           &b1,

           NULL

       };


But it also needs to have in the setup which function Iterate will pass

the Touch Press/Release touch event to.  To define a press (PUSH)


       n0.attachPush(n0PushCallback);


To define a release (POP)


      n0.attachPop(n0PopCallback);


After this is defined in setup, you must actually have the function code

that you just stated


      void n0PopCallback(void *ptr)

      {

        // your code when n0 is released

      };


      void n0PushCallback(void *ptr)

      {

        // your code when n0 is pressed

       };


Setup must also have a call to initialize nextion Serial


    nexInit();


Finally, the whole listening aspect has to be done inside loop

So that each run through loop the Arduino can look for the event


     nexLoop(nex_listen_list);


ino
Yes right...I will do it but I am still waiting how do you write to include the library... I know how to read a cod already written as you done... it's easy like that...

Arduino has their flavour of C

C programming languages are Case Sensitive.


Core Libraries in installed space are included with angle brackets

#include <Arduino.h>

Other Libraries in user space are included with double quotes

#include "Nextion.h"


Looking to Nextion.h file will reveal this file merely includes all other needed files


So why to my don't work,do you have any idea? I installed the library as you sed I open the file that you attached and I keep give to me the error which is library not present and nexNumber=nexNumber(0,3,n0) is not named as declares

nexNumber=nexNumber(0,3,n0) needs to have an Arduino side variable for Component


nexNumber myNumber =nexNumber(0,3,n0);

uint32_t temp;


then myNumber is the variable for Component

temp is the numeric 32 bit unsigned value


  myNumber.setValue(number);

Login or Signup to post a comment