Start a new topic

'nextion' was not declared in this scope

Mega2560

Nextion 2.8


I am very new to the Arduino and am trying to get the nextion-master Examples to verify. I keep getting the error below? this is the example given online.


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

#include <Nextion.h>

Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

void setup() {
  Serial.begin(9600);

if (myNextion.init("Home")) {

  Serial.println(F("Nextion Ready..."));

  } else {

  Serial.println(F("Nextion not responding..."));

  }
}

void loop() {

  myNextion.setComponentText("t0", "Hello");
  delay(1000);
  int value = 1234;
  myNextion.setComponentText("t0", String(value));
  delay(1000);
 
}

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

Error when I verify

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

UpdateText:3: error: 'nextion' was not declared in this scope

 Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

  ^

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




1 person likes this idea

Hello Anthony I have the same problem, have you had any response yet, I have tried with a UNO and a DUE both on a 7" nextion display using the ITEAD Library. Running any of the demo's produces exactly the same error report"'nextion' was not declared in this scope". 

I have been able to run, however, the double Progress Bar demo (can't remember where it came from) that doesn't use the library. See code below:


 

int value=0;
int value2=100;


void setup() {
  Serial.begin(9600);
}

void loop() {
 value++;
  if(value>100){
  value=0;
  }
  Serial.print("j0.val=");
  Serial.print(value);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t0.txt=");
  Serial.write(0x22);
  Serial.print(value);
  Serial.write(0x22);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
 value2--;
  if(value2<0){
  value2=100;
  }
   Serial.print("j1.val=");
  Serial.print(value2);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=");
  Serial.write(0x22);
  Serial.print(value2);
  Serial.write(0x22);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(300);
}

 Has anybody an idea as to what this error means.


You guys forgot to either declare which serial you were using or use softserial.


exe:

SoftwareSerial nextion(10, 11);


or

Nextion myNextion(Serial, 9600);

Nextion myNextion(Serial1, 9600);

Nextion myNextion(Serial2, 9600);

Nextion myNextion(Serial3, 9600);


I am using the second exemples on arduino Mega and works pretty fine.

Hello Filipe


Thank you for your comments but using either the UNO or DUE gave me library errors and despite recommendations from other forums I was not able to fix this. I did find that if I sent serial comms direct, such as 

      Serial1.print("Roller.val=");
      Serial1.print(rpms2,0);
      Serial1.write(0xff);
      Serial1.write(0xff);
      Serial1.write(0xff);

 then I could at least talk to the display. Roller is a gauge component and rpms2 is the value sent. Unfortunately the display 'flicked' a lot despite serial comms being '115200' so I have dropped the idea and written my own 'DELPHI' program to read the Arduino data and display the results on my laptop. Not quite what I was looking for but I was spending too much time getting the display to 'display' so it is now in my failure box.

Thanks for the comments though it is much appreciated.

Hey Christopher


the flickering a lot could have been being caused by the refresh command.  I haven't seen your code for that to comment specifically - but I have seen other code where everything being followed with a ref 0 (refreshing everything on the page).  This causes the every pixel to update, and in rapid succession can cause that.  Ref commands should be used specifically ref t0 (only refreshes the pixels that t0 occupies) and not it rapid succession.


I am curious to your Delphi code for interfacing the comms to Arduino.  Would you perhaps consider sharing the code with me.



Login or Signup to post a comment