Start a new topic

Nextion does not name a type

I can't get rid of the Nextion does not name a type Error on compile. About to chuck laptop out window. Code line is Nextion myNextion(nextion, 9600); Using a mega 265 board. Have downloaded the itead Nextion master library's 3 times. As another post stated it could be corrupt or not official issues. Any help please. Ben.

Sorry Ben.


The Iteadlib Arduino Nextion Library does not use such

   Nextion myNextion(nextion,9600)


Rather nexSerial is aliaised to Serial2 in NexConfig.h and

   nexInit() is called in your setup()

   (nexInit() contents are in the NexHardware.cpp file)


The examples in the examples folder would show how to use.


Code would look something like attached, but certainly no

  Nextion myNextion ....

And the authors of that Nextion muNextion library will probably never answer your questions


ino

1 person likes this

If it isn't clear.

Code using Nextion myNextion is not using the IteadLib


Thus the reason for your compile error.

One must format their code in the format of their chosen library

but not mix code from another library and expect it to work


1 person likes this
Thanks Patrick. It is becoming clearer. All my previous coding was should you say long hand. Never used Libs. However all the examples I am finding now do for the arduino / Nextion interface. Still looking for the most basic code to start me off. I can see snipits of information, bit of this bit of that. The only complete one I have seen is per the one mentioned above but as you correctly point out is is not the standard and requires a custom lib file. (Not found) I am going to delete all the lib files I have downloaded and start again. I am getting constant duplicated messages For the Nextion interface what is the preferred file (or libuary) to download The Nextion send a button state (Ie the message 65 0 1 1 ffff ffff ffff) that the Nextion sends on the link. As seen in the serial window. Am I barking up the wrong tree. Can you code this in long hand or do you need the Libs. Again thanks in advance Ben.
Sorry father to above. Once received the code to turn a digital output on and off I am ushering a mega 256. What is the preferred serial (0,1,2 or 3). Does the USB by default use one of the these. Again sorry for the questions. This is my first trip into serial and Nextion. All previous projects have been hard wired distill inputs and outputs with a lot of magic in between. Ben.

That ffff ffff ffff is another reveal that it is wrong custom lib.

The Nextion Instruction Set clearly states three bytes of 0xFF

so what is with the twisted word 16 bit ffff to represent.


I placed Arduino Nextion Examples in a thread called

* Arduino Nextion Examples

This is a sticky thread that should be remaining at top of Free Chat.

http://support.iteadstudio.com/support/discussions/topics/11000009208


1 person likes this

USB usually takes 0 or Serial for debug.

Any of 1 2 or 3 is users choice as user decides for what all needs to be connected to the MCU

Nextion IteadLib is preconfigured for nexSerial Serial2 in NexConfig.h

 // so no need to adjust if using Serial2




1 person likes this
Thanks again Patrick. This is the issue I am finding. In a word too much wrong information I have looked at the for mentioned examples last night. Still trying to apply them to hear the serial and then drive the digital output. In essence. I have a TFT Nextion 7" inhanced and a mega 256 that I want to drive a set of 8 relays. Yes there is a complete example for this in the forums but as you point out it has custom Libs that's is causing issues. This is the link. (Yes I now know it's not right). http://stackoverflow.com/questions/37258537/nextion-touch-screen-arduino-mega-2560-turning-a-relay-off-and-on Just need a hand with the first code for the first output. Ie Everything else to hear the Nextion and then say // xxxxxx Nextion Libs and set up int ledPin = 13; // LED connected to digital pin 13 void setup() //xxxxxx. Nextion and serial bits set up xxxxxxxxx { pinMode(ledPin, OUTPUT); // sets the digital pin as output } void loop() { // when I hear the serial from above (from say serial2) bit after the button pressed on the Nextion TFT "on" or "off" digitalWrite(ledPin, HIGH); }
Sorry. Looks like from my iPad the formatting mucks up. I'll try the last bit again Just need a hand with the first code for the first output. Ie Everything else to hear the Nextion and then say // xxxxxx Nextion Libs and set up int ledPin = 13; // LED connected to digital pin 13 void setup() //xxxxxx. Nextion and serial bits set up xxxxxxxxx { pinMode(ledPin, OUTPUT); // sets the digital pin as output } void loop() { // when I hear the serial from above (from say serial2) bit after the button pressed on the Nextion TFT "on" or "off" digitalWrite(ledPin, HIGH); //Then When you hear the same serial bit again digitalWrite(ledPin, LOW); }
Try once more. And a picture if not working from iPad Sorry. Looks like from my iPad the formatting mucks up. I'll try the last bit again Just need a hand with the first code for the first output. I e Everything else to hear the Nextion and then say // xxxxxx Nextion Libs and set up int ledPin = 13; // LED connected to digital pin 13 void setup() //xxxxxx. Nextion and serial bits set up xxxxxxxxx { pinMode(ledPin, OUTPUT); // sets the digital pin as output } void loop() { // when I hear the serial from above (from say serial2) bit after the button pressed on the Nextion TFT "on" or "off" digitalWrite(ledPin, HIGH); //Then When you hear the same serial bit again digitalWrite(ledPin, LOW); }
IMG0043.PNG
(777 KB)

So perhaps in this manner

8 dualstate buttons, picture for off/on

button release sends touch release return codes

Arduino holds digitalstateX variable for each relay

when button release is received Arduino passes to proper function

  toggles digitalstate for that relay

  pin high or low depending on new state


Course we only defined on pin as digital out but

this should be sufficient example to see how this works.


There is a Pattern to much of the library making

 each repetitive use easier.


#include <Arduino.h>

#include "Nextion.h"


  // parameters  page #, component .id, component .objname

NexDSButton myButton0 = NexDSButton(0,1,"bt0");  //

NexDSButton myButton1 = NexDSButton(0,2,"bt1");

NexDSButton myButton2 = NexDSButton(0,3,"bt2");

NexDSButton myButton3 = NexDSButton(0,4,"bt3");

NexDSButton myButton4 = NexDSButton(0,5,"bt4");

NexDSButton myButton5 = NexDSButton(0,6,"bt5");

NexDSButton myButton6 = NexDSButton(0,7,"bt6");

NexDSButton myButton7 = NexDSButton(0,8,"bt7");


uint32_t digitalstate1, digitalstate1, digitalstate2, digitalstate3,

              digitalstate4, digitalstate5, digitalstate6, digitalstate7 = 0;


int ledPin = 13;


NexTouch *nex_listen_list[] =  {

  &myButton0, &myButton1, &myButton2, &myButton3,

  &myButton4, &myButton5, &myButton6, &myButton7,

  NULL

}


void myButton0ReleaseCallback(void *ptr) {

  digitalstate0 = 1-digitalstate0;

  if(digitalstate0==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);

  } 

}


void myButton1ReleaseCallback(void *ptr) {

  digitalstate1 = 1-digitalstate1;

  if(digitalstate1==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);

  } 

}


void myButton2ReleaseCallback(void *ptr) {

  digitalstate2 = 1-digitalstate2;

  if(digitalstate2==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);

  }

}


void myButton3ReleaseCallback(void *ptr) {

  digitalstate3 = 1-digitalstate3;

  if(digitalstate3==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);

  }

}


void myButton4ReleaseCallback(void *ptr) {

  digitalstate4 = 1-digitalstate4;

  if(digitalstate4==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);

  } 

}


void myButton5ReleaseCallback(void *ptr) {

  digitalstate5 = 1-digitalstate5;

  if(digitalstate5==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);

  }

}


void myButton6ReleaseCallback(void *ptr) {

  digitalstate6 = 1-digitalstate6;

  if(digitalstate6==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);

  }

}


void myButton7ReleaseCallback(void *ptr) {

  digitalstate7 = 1-digitalstate7;

  if(digitalstate7==1) {

    digitalWrite(ledPin, HIGH);

  } else {

    digitalWrite(ledPin, LOW);  

  }

}


void setup(void) {

  pinMode(ledPin,OUTPUT);

  nexInit();

  myButton0.attachPop(myButton0ReleaseCallback, &myButton0);

  myButton1.attachPop(myButton1ReleaseCallback, &myButton1);

  myButton2.attachPop(myButton2ReleaseCallback, &myButton2);

  myButton3.attachPop(myButton3ReleaseCallback, &myButton3);

  myButton4.attachPop(myButton4ReleaseCallback, &myButton4);

  myButton5.attachPop(myButton5ReleaseCallback, &myButton5);

  myButton6.attachPop(myButton6ReleaseCallback, &myButton6);

  myButton7.attachPop(myButton7ReleaseCallback, &myButton7);

}


void loop(void) {

   nexLoop(nex_listen_list);

}



ino
(2.8 KB)
HMI
(23.3 KB)

1 person likes this
Patrick. Can't wait to get home to try it. You are a legend. Champ champ champ. Thanks so much. Ben. Excellent

Always double check, I always may have an error or two

Yep. I have already named all the outputs 1-8. Changes the int to const int Assigned the pins pin1 though pin8 I hope it works. Quick question. Why is the only void loop nexLoop (nex listen list). Normally I add all the program and digital write stuff in there. The attached has it above the void set up. Is this correct. Again I have not tired it or compiled it. Thanks again.

The call to NexLoop is only needed once per loop()

  Inside NexLoop, it will empty the incoming serial buffer and check if any

  of the touch event 0x65 Nextion Return codes have been received.


Which codes it is looking for was defined in the NexTouch *nex_listen_list[]

    A Nextion Return code for a released event looks like

        0x65 0x00 0x01 0x00 0xFF 0xFF 0xFF

     - where the second byte is page, third byte component id, 4th is pressed 0x01 or released 0x00

    It got these values when you defined your dual state button

       NexDSButton myButton0 = NexDSButton(0,1,"bt0");


But what function it will pass it off to is defined in setup .attachPop or .attachPush

   myButton0.attachPop(myButton0ReleaseCallback, &myButton0);

This says that when the release event 0x65 0x00 0x01 0x00 0xFF 0xFF 0xFF

   then it needs to run myButton0ReleaseCallback


So myButton0ReleaseCallback needs to be defined and what it will do


Further, it makes sense that it you want to toggle when button release is notified

then doing it inside the function that handles that release is probably the best spot to do so.

your relay on/off is tied to Nextion dualstate button's on/off.


Now if we had other non Nextion related operations

   it is best to create a function for each with the logic of when function is called put into loop()


Creating individual functions does not cost much in the branch instruction

but keeps the code a bit more readable (as opposed to a 1000 line loop()


Lastly I believe that Arduino C would allow a function to be defined after main() or loop()

But I am too old school to break good habits of main() being bottom and therefore easy to locate.

My coding style is if a function need be called it will be laid out above the calling functions

 - in this manner, loop calls everything else - thus everything else is above it.


1 person likes this
Login or Signup to post a comment