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.



Sorry


Answered this question too many times

Look through forum for answer

Use someone else's library, someone else's code - Ask them how it works.


But how to expect mixing library and code from another

 is suppose to have anything else but an error.


When the error is displayed by your compiler, you have to learn your compiler, learn the language you are coding in, and read the code you are trying to run.


Just tossing code is never an approach to programming


I've been searching for an answer for over 5 hours!

There's nothing out there that says 'Nextion' does not name a type.

No example I find will work. I've tried Nextio+Arduino tutorials and always get this error. Uninstalled, deleted all my Arduino files. Reinstalled Ardunio IDE 1.8.0, reinstall Nextion library 0.7.0. The in an empty Arduino project all I do is paste the following three line and it won't compile. It just says 'Nextion' does not name a type.


#include <SoftwareSerial.h>

#include <Nextion.h>

SoftwareSerial nexSer(2, 3);
Nextion myNextion(nexSer, 9600);   <--- this line generates error that 'Nextion' "does not name a type".


My NexConfig.h looks like this. 
#define nexSerial nexSer


It would be great if someone helped on this thread since the subject is the error message. Then in the future people will EASILY find it with a search. Please do a Googe search for  "'Nextion' does not name a type" or local search here on this forum and tell me where you see this being answered.

Your ino requests Nextion.h that is not Iteadlib Nextion.h


#include <SoftwareSerial.h>

#include <Nextion.h> SoftwareSerial nexSer(2, 3);

Nextion myNextion(nexSer, 9600);   <--- this line generates error that 'Nextion' "does not name a type".


My NexConfig.h looks like this.

  #define nexSerial nexSer


Wrong library

When you use example from the library you referenced

contact the author for answers.

Ricardo Mena C ricardo@crcibernetica.com http://crcibernetica.com


But he hasn't updated this in over 1 year.



When you want to have no issues use the Iteadlib Arduino Nextion Library

You will find this at the Itead github


In Nextion Editor v0.43

Select Help under the Help Menu

  - Goto Related Downloads

  - Follow link for Arduino Library for Nextion

  - use official library

Forget the exmaple code from Ricardo Mena C ricardo@crcibernetica.com

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

 https://github.com/itead/ITEADLIB_Arduino_Nextion



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


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


I'm using an Arduino Nano and using the following instructions to configure NexConfig.h to use SoftwareSerial. https://www.reddit.com/r/arduino/comments/4b6jfi/nexconfigh_for_nextion_display_on_arduino_uno/


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.

The reddit article you gave differs from what you presented.


Try doing it as the reddit article.

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



???

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:<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. 
 */
#include <SoftwareSerial.h>          // CHANGED AS PER
extern SoftwareSerial HMISerial;     //         REDDIT
#define nexSerial HMISerial         //       ARTICLE


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

 

 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:<pengfei.wu@itead.cc>)
 * @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[] = 
{
    &b0,
    NULL
};

/*
 * 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;
    dbSerialPrintln("b0PopCallback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)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]. */
    btn->setText(buffer);
}

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

    /* 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.
     */
    nexLoop(nex_listen_list);
}

 


HMI

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.


In my folder

..\Arduino\libraries\ITEADLIB_Arduino_Nextion-0.7.0


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?

Login or Signup to post a comment