Start a new topic

'Nextion' does not name a type

Trying to compile Update Text example code for Nextion library and getting this error.

exit status 1
'Nextion' does not name a type

The Nextion 0.7.0 library is installed.

I will give you two other tell take signs of the non official library

   if(message =="65 1 2 0 ffff ffff ffff")

seeing message== is almost always this library

and seeing ffff  ... The Instruction Set is clear on 0xFF

I will have to state that a display manufacture does not teach people to code.  If this display is used with an STM32F103RBT6 MCU or an STM32F030F4P6 MCU, is it the job of the display manufacture to teach people how to code?  When I use Kylix3 on an Intel Edison and program in pascal, or mikroPascal on an ESP8285?  Programming and examples is the domain of the programming language used and the compiler.  What to program, is the domain of the MCU to provide the Technical Manuals for what pin functions are for.

The Arduino Nano has such technical manuals, and Arduino's task is to compile your code programmed in their variant of C.  But certainly a display manufacture doesn't teach people in 100's of programming languages in combinations of 1000's of MCUs.  Itead provides the Nextion Instruction Set. 

The Nextion Instruction Set is straight forward, it doesn't matter how you push a byte over serial and receive the returning bytes in whatever language is desired.  All commands are text based.  But learning programming and knowing their MCU chosen that they wish to use is the domain of the User.

By the way @author Wu Pengfei needs to learn how to make comments in example code or maybe ITEAD can hire a coder to create example files with comments so beginners can understand what each line of code means. There will be another hacker like myself who isn't an experienced programmer and for the simplest looking example to copy and paste into their code.
The code is very good, but with debug disabled a lot of it isn't needed. Then I see a random line like   char buffer[100] = {0};    and I wonder what in the world that is for and if I'm going to need to understand why it's there.

Thank you for the answer I was looking for. Now it is clear in my mind what is happening and have deciphered the initial cryptic answers I was getting.

My error was thinking that the initial example that I found in a Google Search was using the same official Nextion.h library that I'm using.  (Github newb alert)  Now I see that the example comes from a non-official library. Assumptions are the root of all evil.

To clarify my finding here.  Hoping I understand this.

command from non-official library to connect

  Nextion myNextion(nextion, 9600);  

replaced with correct way to connect.


How to verify it is working?

- configure for your model Nextion the CompButton.HMI example above

- upload the TFT into your Nextion, either via serial or MicroSD card

- compile the CompButton.ino as listed above

- upload to your Nano

- You should then be able to touch on Nextion and see results

- debug information should show in Serial Monitor

Please open and read Nextion.h in your folder

There is no Nextion class.  Nextion.h defines which files to include

In the CompButton.ino example I listed above, Line 70

   nexInit(); is what establishes your serial connection.

The definition of what nexInit() includes is found in NexHardware.cpp

bool nexInit(void)


   bool ret1 = false;

   bool ret2 = false;





   ret1 = recvRetCommandFinished();

   sendCommand("page 0");

   ret2 = recvRetCommandFinished();

   return ret1 && ret2;


In my folder


there is a class called Nextion.h

What is the command to simply establish a serial connection to the Nextion so I can verify it is working?

The Answer of why

 Nextion myNextion(HMIserial, 9600);

generates the error is because

The class Nextion is not a class of the IteadLib Arduino Nextion Library

It is a class of the other library where your original example came from.

Why are you attempting you use

Nextion myNextion, this is unnecessary

Contents of new NexConfig.h 


 * @file NexConfig.h
 * Options for user can be found here. 
 * @author  Wu Pengfei (email:<>)
 * @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 dbSerial for the output of debug messages. 
#define dbSerial Serial

 * Define nexSerial for communicate with Nextion touch panel. 
#include <SoftwareSerial.h>          // CHANGED AS PER
extern SoftwareSerial HMISerial;     //         REDDIT
#define nexSerial HMISerial         //       ARTICLE

#define dbSerialPrint(a)    dbSerial.print(a)
#define dbSerialPrintln(a)  dbSerial.println(a)
#define dbSerialBegin(a)    dbSerial.begin(a)
#define dbSerialPrint(a)    do{}while(0)
#define dbSerialPrintln(a)  do{}while(0)
#define dbSerialBegin(a)    do{}while(0)

 * @}

#endif /* #ifndef __NEXCONFIG_H__ */


 Contents of ComButton.ino 



 * @example CompButton.ino
 * @par How to Use
 * This example shows that when the button component on the Nextion screen is released,
 * the text of this button will plus one every time.      
 * @author  Wu Pengfei (email:<>)
 * @date    2015/7/10
 * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
 * @convert by Patrick Martin, no other changes made
 * @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.

#include "Nextion.h"
// Master RX, TX, connect to Nextion TX, RX    // ADDED AS PER THE
SoftwareSerial HMISerial(2,3);                 // REDDIT ARTICLE

 * Declare a button object [page id:0,component id:1, component name: "b0"]. 
NexButton b0 = NexButton(0, 1, "b0");

char buffer[100] = {0};

 * Register a button object to the touch event list.  
NexTouch *nex_listen_list[] = 

 * Button component pop callback function. 
 * In this example,the button's text value will plus one every time when it is released. 
void b0PopCallback(void *ptr)
    uint16_t len;
    uint16_t number;
    NexButton *btn = (NexButton *)ptr;
    memset(buffer, 0, sizeof(buffer));

    /* Get the text value of button component [the value is string type]. */
    btn->getText(buffer, sizeof(buffer));
    number = atoi(buffer);
    number += 1;

    memset(buffer, 0, sizeof(buffer));
    itoa(number, buffer, 10);

    /* Set the text value of button component [the value is string type]. */

void setup(void)
    /* Set the baudrate which is for debug and communicate with Nextion screen. */

    /* Register the pop event callback function of the current button component. */
    b0.attachPop(b0PopCallback, &b0);
    dbSerialPrintln("setup done"); 

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.



CompText.ino compiles fine.

Question of this thread is why does this code:

Nextion myNextion(HMIserial, 9600);

generate this error:
'Nextion' does not name a type


The reddit article you gave differs from what you presented.

Try doing it as the reddit article.

I'm using an Arduino Nano and using the following instructions to configure NexConfig.h to use SoftwareSerial.

Now my NexConfig.H looks like this:

#include <SoftwareSerial.h>

extern SoftwareSerial HMIserial;

#define nexSerial HMIserial

This is my code that won't compile for Arduino Nano.

#include <SoftwareSerial.h>

#include <Nextion.h>

SoftwareSerial HMIserial(2, 3);

Nextion myNextion(HMIserial, 9600);

void setup() { }

void loop() { }

sketch_jan14a:4: error: 'Nextion' does not name a type Nextion myNextion(nexSer, 9600); ^ exit status 1 'Nextion' does not name a type Nextion

myNextion(HMIserial, 9600); <--- error on this line

I'm assuming this is not formatted correctly. All I'm trying to do is establish connection to the Nextion to confirm it's working.

Please understand

The ino file you said did not work the first time uses the wrong library.

Now you said you are using the official library ...

And it's not working.

The it's is ambiguous at best ...
- surely you aren't attempting the original example
You already stated forget the example from ...

So you have a new scenario, it's not working
but zero details about the new scenario other than
you are now attempting with the official Iteadlib library

So which is not working now ...

provide the ino file not working Attach a File

and where the example ino file was obtained from

which MCU are you using

and how have you configured your NexConfig.h

what compile error are you receiving

Forget the exmaple code from Ricardo Mena C

I'm using the official ITEADLIB Arduino Nextion Library and it's not working.

Login or Signup to post a comment