Start a new topic

Problems with arduino mega and nextion

Hello!
My name is Victor and I write to you from Spain. I recently bought a Nextion screen model: NX4832T035_011 and I do not know how to communicate with arduino. I've tried several examples and I've never made it work.

In one of the examples the arduino serial port showed this:


RecvRetCommandFinished err
RecvRetCommandFinished err
Setup done

I have also tried codes without libraries like this:

 

//codigo original http://blog.iteadstudio.com/

//declaracion de entradas y salidas

int led=13;

int char1,char2;

int charflag=0;

 

void setup() {

 Serial.begin(9600); //configuracion del puerto serial

 pinMode(led,OUTPUT);

}

 

void loop() {

 if (Serial.available()>0)

{

 if (charflag)

 {

 char2=Serial.read(); //lee el puerto serial y almacena el dato en char2

 if (char2==1) //

{

digitalWrite(13,HIGH);

}

 else if (char2==0x00)

{

 digitalWrite(13,LOW);

}

 charflag=0;

 Serial.print(char2);

 }

 else

 {

 char1=Serial.read();

 if(char1==0x65) charflag=1;

 }

}

}



But I can not get it to work.

Could you pass me some example with libraries that work safely in arduino mega and the connection? I do not know what else to do

I have tried connecting arduino to all serial ports that are 4 (Serial0, Serial1, Serial 2 and serial3)

Regards, and thank you very much



Understanding your Arduino - Arduino has plenty of resources.

Nextion is a Serial Device.


So even simple Serial can send char/bytes to Nextion


byte ter[3] = {255,255,255};


Serial.print("t0.txt=\"Hello\"");

Serial.write(ter,3);


Serial.print("n0.val=23");

Serial.write(ter,3);


Serial.print("page page1");

Serial.write(ter,3);


1 person likes this
Thanks for your reply.

Could you tell me a simple example with the nextion library?

The pins of tx and rx connect them to 16 and 17. Is it correct?

Thank you. a greeting

 

One your hard parts is understanding your Arduino

  - for this you really need to refer to your MCU docs

  - I can not be a librarian to look up MCU side docs.


Assuming you have connected to RX2 and TX2 for Serial2

   (Serial2 maybe 16/17, you check. 

     RX to TX, and TX to RX, GND to GND

     Nextion powered with good 5V 1A recommended)

     Your MCU side you must take care for)


The IteadLib is configured by default for Serial2

Assuming you haven't changed default baud of 9600 on Nextion

Assuming you have a t0 and an n0 component on page0 ot HMI

Assuming you have compiled and uploaded this HMI to your Nextion

Assuming Iteadlib has been installed correctly


#include <Arduino.h>

#include "Nextion.h"


void setup(void)

{

  nexInit();

  SendCommand("t0.txt=\"Hello\"");

  SendCommand("n0.val=23");

}


void loop(void)

{

}


This minimally will let you know you are connected to Serial2 correctly.

From there see the *Arduino Nextion Library Examples thread

My screen still does not work.

I have written this code and it douesnt work...
In the serial you can read the following:

la_prueba_definitiva_de_la_pantalla:12: error: 'SendCommand' was not declared in this scope

  SendCommand("t0.txt=\"Hello\"");

  ^

exit status 1
'SendCommand' was not declared in this scope



#include <Arduino.h>

#include "Nextion.h"


void setup(void)

{

  nexInit();

  Serial.print("t0.txt=\"Hello\"");

  Serial.print("n0.val=23");

}


void loop(void)

{

}

I have installed the nextion library in my documents / arduino / libraries

The NexConfig.h file that I have read that needs to be modified this way:

/**
 * @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 Serial2

/**
 * Define nexSerial for communicate with Nextion touch panel.
 */
#define nexSerial Serial


#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__ */



#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__ * /


The nextion pin rx is connected to the arduino pin 16 (arduino PIN TX2) and the nextion screen pin tx is connected to the arduino pin 17 (arduino pin RX2)

Any ideas??

Thanks for your quick response

 

Yep,


In NexConfig.h

A)  change dbSerial Serial2 back to dbSerial Serial

B)  change nexSerial Serial back to nexSerial Serial2


Ensure Nextion connected to Serial2  RX2/TX2

dbSerial goes through USB to Serial Monitor with Serial0 or known as Serial


Don't forget to have Nextion GND and Arduino GND connected common.

Review the .h and .cpp code files of the IteadLib.


It was my typo in SendCommand, should be sendCommand.

My native language of pascal is not case sensitive.


You need to be familiar enough with the library files and Arduino C++ style

to see such, catch and change as need be.

It is rare you get perfect code from net


ino
(157 Bytes)
Changing what you told me on the serial port of the arduino appears this:

recvRetCommandFinished err
recvRetCommandFinished err

The screen still does not work :(

 

attempt switching RX / TX wires on Mega side

Nextion is which model and powered how?

GND of Mega Connected with GND of Nextion?

The GND of nextion is connected to the GND of the arduino. The RX and TX cables have tried on all the pins (RX and TX)  and interchanged them and it does not work.

The Nextion model is NX4832T035_011

regards

 

How  is Nextion being power?

Regular Arduino things been double checked?

   Your Arduino IDE version?
   Certain you have correct board selected in IDE?
   Certain you have your port.

   Compiles with no errors?


Multimeter things: 5V supply is 5V 500mA as recommended

    https://www.itead.cc/wiki/NX4832K035


Attached some images

 

 I know that there is no supply problem but anyway I tried this way to rule out errors.

The screen remains the same ...


I attached an image of my arduino IDE and the new connection form


regards

image.png
(135 KB)
How I change default baud of 9600 on Nextion??

Regards

 

First from usb adapter GND there also needs to be GND to MEGA ... all need to be common

Login or Signup to post a comment