Start a new topic

Problems with Nextion 2.8" and Arduino Mega

Hi, I've just got my Nextion display, downloaded Arduino library for it (https://github.com/itead/ITEADLIB_Arduino_Nextion) for starters I've tried to do CompText example. I've compiled the Arduino code and Uploaded successfully ti to my Arduino Mega, then compiled the HMI file to the SD card. I've successfully uploaded the file to my Nextion display. The file runs on the display, but for some reason when I  press buttons + and - , nothing happens, I've also opened Serial port on my Arduino IDE and noticed 3 lines there:


recvRetCommandFinished err

recvRetCommandFinished err

setup done


The Arduino Mega is connected to the display using TX2 and RX2 pins, and no change to NexConfig.h were made by me. Any suggestions ?


I'm having the same problem. My Nextion is a 3.5 ". When testing the examples, I get the same messages.


recvRetCommandFinished err

recvRetCommandFinished err

setup done

 same here


on arduino mega i have
NexConfig.h #define nexSerial Serial2
and connect

                            TX     →   RX2

                            RX     →   TX2


yes i still get the problem :

recvRetCommandFinished err
recvRetCommandFinished err
setup done


using CompText example ?


i tried all the other TX/RX option and they all generate the same problem. ? Is my screen defective ?

i added this line in NexHardware.cpp "Serial.println(c, HEX);"

i get this when touching the button from the CompButton sample code :
4D
FD
FF
1
0
0

So i do  get something, but the codes don't seem to register  with the arduino lib ?

 

Hi guys I am using Arduino Mega and the nextion 5'' and I cannot communicate between the two of them. I really need this to work with mega. I tried connecting to an Arduino nano and it works without problem. I tried on all the RX TX on mega and none of them I get response. Maybe the nextion library needs some mod? Let me know if you guys were able to make it work. Thanks Filipe

I remember modding the NexConfig.h file of the library a bit, liiks like that (with tx2,rx2 connected to the display):

/**

 * @file NexConfig.h

 *

 * Options for user can be found here.

 *

 * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)

 * @date 2015/8/13

 * @copyright

 * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n

 * This program is free software; you can redistribute it and/or

 * modify it under the terms of the GNU General Public License as

 * published by the Free Software Foundation; either version 2 of

 * the License, or (at your option) any later version.

 */

#ifndef __NEXCONFIG_H__

#define __NEXCONFIG_H__

/**

 * @addtogroup Configuration

 * @{

 */

/**

 * Define DEBUG_SERIAL_ENABLE to enable debug serial.

 * Comment it to disable debug serial.

 */

#define DEBUG_SERIAL_ENABLE

/**

 * Define dbSerial for the output of debug messages.

 */

#define dbSerial Serial

/**

 * Define nexSerial for communicate with Nextion touch panel.

 */

#define nexSerial Serial2

#ifdef DEBUG_SERIAL_ENABLE

#define dbSerialPrint(a) dbSerial.print(a)

#define dbSerialPrintln(a) dbSerial.println(a)

#define dbSerialBegin(a) dbSerial.begin(a)

#else

#define dbSerialPrint(a) do{}while(0)

#define dbSerialPrintln(a) do{}while(0)

#define dbSerialBegin(a) do{}while(0)

#endif

/**

 * @}

 */

#endif /* #ifndef __NEXCONFIG_H__ */



1 person likes this

Cant give you the whole library, as I modded the hell out of it due to the requirement to use global variables and full synchronization with Arduino.

and, yeah, it works perfectly fine with Mega. 

Dear all, already did try Svjatoslavs Krasnikovs's code. Now i can upload without any error but in serial monitor still got recvRetCommandFinished err

recvRetCommandFinished err
setup done

Can anyone help me please?

You mean, that you can upload the numbers to the display, but still receive the error massages ?

With a little bit of struggle, it works now, but I'm a noob on nextion so please help me with some answers.

I want to make the display change page pressing a pushbutton connected directly to arduino( not using the touchscreen). Is it possible to arduino to send signal to the display to know that button b0 is pressed? or how else can this be done? Please can you help me?

it's actually not that difficult as Arduino communicated to Nextion using UART. The key factor here was to find the command that ITEAD library used to transmit ASCII commands of UART. The thing You asked for can be done in following manner :

You need to use sendCommand("STRING"); method that is already sefined inside the ITEAD library.

Say when event occurs you need to get display to the page 1:

if (digitalRead(pushButton) != 0)

{

sendCommand("page 1");     //THIS EXACT COMMAND WILL GET YOU TO PAGE 1

}


same with page 2 will be sendCommand("page 2")


If you actually spend time and explore how the UART commands are built in the ITEAD library you can find a lot of interesting stuff, and loads of stuff on how to make your life easier. Personally I modded the hell out of the original library. 


1 person likes this

The method I've shown is called button polling, shall you have Arduino Due you can use interrupt perform the sendCommand("page x") in your interrupt handling routine, but that's completely different business.

Well thank you for the quick answer. You are the first person that provides me help beside tutorials. Sounds much more easy then expected. Again, thank you.

No problem, ask here if you need any help with Nextion.


1 person likes this
Login or Signup to post a comment