Start a new topic

Arduino library with variables support and software serial

Hello,


I have modified the library 0.7.1 to add support for variables (get and set value) and use a software serial to communicate with the nextion. That allows to use arduino UNO with debug.


Now the softwareserial is in port 10 and 11, that can be changed in the line 18 of the file NexHardware.cpp.


I have removed all the doc and examples to reduce the size of the file.

rar

5 people like this idea

Hello Francisco,

I've some problems trying to integrate the files that you attached.

I don't know if my procedure will get me the results that I'm waiting.

I copied all the files inside the library "ITEADLIB_Arduino_Nextion-0.7.0", then when I'll go to compile the sketch, It return to me the follow error:


C:\Users\SGR\Documents\Arduino\libraries\Nextion\NexHardware.cpp:18:25: error: conflicting declaration 'SoftwareSerial Serial2'

 SoftwareSerial nexSerial(10, 11); // RX, TX

                         ^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:223:0,

                 from C:\Users\SGR\Documents\Arduino\libraries\Nextion\NexHardware.h:17,

                 from C:\Users\SGR\Documents\Arduino\libraries\Nextion\NexHardware.cpp:15:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:141:25: error: 'Serial2' has a previous declaration as 'HardwareSerial Serial2'

   extern HardwareSerial Serial2;

                         ^

Error compiling.


What I can do to solve the problem?


Tanks for all.


P.D.: Fantastic idea for the NexVar library!!!




https://github.com/itead/ITEADLIB_Arduino_Nextion/pull/4


I add pull 24 august 2015 for Nexvar e Nextimer...

Hi Alberto,


thanks for the changes!!! I see in this modifications a lot of open fronts to have better my projects.

thanks.


But, I have the same problem about the SoftwareSerial conflict with the header file provided by arduino "HardwareSerial.h". See above.


Thanks again!!!

You put a wrong line ...

#define SoftwareSerial Serial 2

The software serial is not in use so, you must change the pin rx tx in:

SoftwareSerial nexSerial (10, 11); // RX, TX

Hola Salvador,


por el nombre entiendo que hablas castellano, así que voy a tratar de poner esta entrada en dos idiomas.


Esa librería está hecha para el Arduino Uno, creo que estas usando un Mega o un Due, que llevan varias lineas serie, y la "Serial 2" ya la tienen definida. Si es así basta con que comentes la linea 18 del fichero NexHardware.cpp.


----------------------------------------------------------------------------------------------------

Hi Salvador,


this library is for Arduino Uno, I think that you are using Mega or Due. That hardware have several serial lines, and "Serial 2" is all ready used for one of that hardware serial lines. If that is the case, you should comment the line 18 in the file NexHardware.cpp and ready to go.




Hola Francisco,

te pongo en situación:

la placa que tengo es la MEGA como lo habías supuesto y estoy realizando un proyecto el cual hay bastante comunicación entre el Nextion y el Arduino. El problema principal que tengo es que solo consigo comunicar con 9600 baudios, en cambio cuando cambio el ajuste en elArduino, ya sea subirlo o bajarlo deja de funcionar, aunque directamente el Nextion si que responde en todas las velocidades.


Al ver tu post, refiriendote a usar el SoftwareSerial, queria probar a ver si lo solucionaba.

A parte de incluir las mejoras en los objetos de las librerias de nextion, no veo como le digo que vaya por Software. He intentado copiar los dos archivos "SoftwareSerial.cpp y SoftwareSerial.h.pero no lo he conseguido.Tambien he comentado la linea en NexHardware y tampoco. Te adjunto el informe de errores que me suelta.


Gracias por todo !!!

_______________________________________________________________________

Hi Francisco,

I'll show you my situation:

My hardware is Arduino Mega as you suposed and i'm programming a project that there ara a lot of comunication between Nextion and Arduino.

The main problem that I have is that I only can comunicate with 9600 baud, then when I change de baud rate in arduino, increasing or decreasing it doesn't work, but extion directly to PC yes.


When I saw your post, referencing to use the SoftwareSerial, I would try to solve the problem.

I added the upgrades in the libraries, but the libraries with Software serial I don't know where or what I can do. I tried to copy the two files "SoftwareSerial.cpp y SoftwareSerial.h" but without success. I had comment the line in the NexHardware but I had the same error. I attach the log file


Thanks for all !!

txt
(8.58 KB)

Buenas,


debes de haber añadido la libreria "softwareserial" al sketch de arduino, quitala, ya que se llama desde la libreria nextion tambien.

Y para usar SoftwarSerial con el Mega, no descomentes la linea de "NexHardware.cpp", y vete a fichero "NexConfig.h", y en la línea 37, cambia "Serial2" por "Serial4" (esto es pq en el Mega ya existen Serial, Serial1, Serial2 y Serial3).


Hi,

I think that you have included the library "softwareserial" in the aduino sketch, remove it, because is already included in the nextion library.

To use softwareserial with the mega, leave the file "NexHardware.cpp" as before, and go to the file "nexConfig.h" and change in line 8 "Serial2" to "Serial4". ( Arduino Mega uses variables Serial1, Serial2 and Serial3)

Buenas,

he estado probando los cambios que me has comentado, pero sin éxito, aunque no me suelta ningún tipo de error. 

Sobre lo de poner el Serial4 es simplemente para que no de error, supongo que comentando la linea 8, ya bastaría. Estoy en lo cierto? 

La comunicación con Nextion no funciona, ya que pongo un Serial.print dentro de la captura del evento y no entra en la función, ni tan solo con 9600 baudios que por hardware si que funcionaba. 

Me podrías hechar un cable con mis librerías y programas ejemplo tanto de Arduino y Nextion? Te adjunto archivo.

Me gustaría probarlo con un Uno, pero no se si existe algún aspecto en las librerías que dependan de esto.


Muchas grácias!!


Hi,

I've been testing the changes that you told me, but without success, however it return no errors.

About changing the name of the serial, Serial 4, is only for no get any errors with the compilation, if i comment the line is the same, is it right?

The communication with Nextion doesn't work, I put a simple Serial.print inside the event function and the program doesn't enter, with the 9600 value not too but when I tested in hardware mode It worked.

Can you help me with the libraries and program test like Arduino & Nextion? I attached.

I would like to test it with an Arduino Uno, but I don't know if exist some featurein the libraries that it depend about.


Thanks for all!!

rar
(9.96 MB)
Buenas, Si, con comentar la linea basta. La libreria tal y como la subi funciona en el Uno, comprobado con mi pantalla. El tema de los baudios no lo tengo tan claro. La verdad es que jugue con la pantalla hace meses y no la he vuelto a tocar. El lunes te digo algo, que tengo la pantalla en la oficina. Hi, Yes, you can comment the line and it's ok. The library that you download is ready for the arduino Uno.

Buenas,


en la funcion nexInit (NexHardware.cpp) es donde se establece la velocidad de cada una de las lineas serie (la de debug y la que comunica con la pantalla). En la libreria que tienes en la código que has subido tienen unas variables en vez de "9600" que es lo que viene en la mia, pero no veo donde modificas esas variables en el código del arduino.

Si quieres que la pantalla vaya a otra velocidad hay una variable de sistema "bauds" que hace que desde que encienda vaya a esa velocidad, y podrías poner dicho valor en la función nexInit y con eso deberia funcionar.


Para que funcione tu ejemplo y poder cambiar los baudios en directo deberias asociar una pulsacion a cada boton que cambia la velocidad en el Nextion para que el arduino lo supiera, y llamara otra vez a nexInit pasandole como argumento la nueva velocidad.

Hello Fransicso,


I downloaded your Nextionarduino.rar file & pasted and replaced its contents in the Arduino libraries folder (photo attached showing highlighted files from your Nextionarduino.rar file are replaced & the remaining non highlighted files are from original github Nextion library (https://github.com/itead/ITEADLIB_Arduino_Nextion)) & I tried to run the CompNumber.ino example. Unfortunately, I got the below errors.

I attached a photo of the contents of the Arduino libraries folder for reference. 

I know the error is "trivial" & "silly" :D but dont know why?


Any ideas please?

Thank you.


CompNumber:28: error: 'NexNumber' does not name a type

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

 ^

CompNumber:47: error: 'n0' was not declared in this scope

     &n0,

      ^

C:\Users\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion_master\examples\CompNumber\CompNumber.ino: In function 'void n0PopCallback(void*)':

CompNumber:59: error: 'n0' was not declared in this scope

     n0.setValue(50);

     ^

C:\Users\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion_master\examples\CompNumber\CompNumber.ino: In function 'void b0PopCallback(void*)':

CompNumber:72: error: 'n0' was not declared in this scope

     n0.getValue(&number);

     ^

C:\Users\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion_master\examples\CompNumber\CompNumber.ino: In function 'void b1PopCallback(void*)':

CompNumber:89: error: 'n0' was not declared in this scope

     n0.getValue(&number);

     ^

C:\Users\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion_master\examples\CompNumber\CompNumber.ino: In function 'void setup()':

CompNumber:102: error: 'n0' was not declared in this scope

     n0.attachPop(n0PopCallback);




ino
(2.83 KB)
photo1.jpg
(159 KB)

Hi Baarini,


the error seems to be in the file NexNumber, that was not included in my library, so I can help you with that.

And the link to download the original library is not working, so I can´t get the same file that you have to try to help you.

Hi Fransicso,


Below I've attached the original Nextion library files for you which I replaced with your Nextionarduino.rar files.

I noticed also that NexDualStateButtion.cpp & .h and NexUpdate.cpp & .h are also not included in your Nextionarduino.rar files. (they are included in the original Nextion library attached below). May they affect the simulation also?

Thank you.

zip

Hi Baarini,


it´s possible that you have in library folder my library and the original with the files overwritted?


Is that is the case, cut my library and paste in other place, because mine doesn´t have NexNumber and the arduino software could be using that instead the one you want to use.


That happened to me, I removd mine and the example works.