Nextion Touch Screen

Hi All

Im trying to control 8 way relay using a Nextion display and Arduino Nano

Iv downloaded some code from here

I have also installed the Nextion Library but getting compile errors as follows

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function ‘bool NexUpload::_searchBaudrate(uint32_t)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:111:5: error: ‘nexSerial’ was not declared in this scope

nexSerial.begin(baudrate);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function ‘void NexUpload::sendCommand(const char*)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:125:12: error: ‘nexSerial’ was not declared in this scope

while (nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:130:5: error: ‘nexSerial’ was not declared in this scope

nexSerial.print(cmd);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function ‘uint16_t NexUpload::recvRetString(String&, uint32_t, bool)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:145:16: error: ‘nexSerial’ was not declared in this scope

while (nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function ‘bool NexUpload::_setDownloadBaudrate(uint32_t)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:183:5: error: ‘nexSerial’ was not declared in this scope

nexSerial.begin(baudrate);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function ‘bool NexUpload::_downloadTftFile()’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:211:21: error: ‘nexSerial’ was not declared in this scope

nexSerial.write(c);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:225:17: error: ‘nexSerial’ was not declared in this scope

nexSerial.write(c);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function ‘bool recvRetNumber(uint32_t*, uint32_t)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:55:5: error: ‘nexSerial’ was not declared in this scope

nexSerial.setTimeout(timeout);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function ‘uint16_t recvRetString(char*, uint16_t, uint32_t)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:114:16: error: ‘nexSerial’ was not declared in this scope

while (nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function ‘void sendCommand(const char*)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:166:12: error: ‘nexSerial’ was not declared in this scope

while (nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:171:5: error: ‘nexSerial’ was not declared in this scope

nexSerial.print(cmd);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function ‘bool recvRetCommandFinished(uint32_t)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:192:5: error: ‘nexSerial’ was not declared in this scope

nexSerial.setTimeout(timeout);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function ‘bool nexInit()’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:226:5: error: ‘nexSerial’ was not declared in this scope

nexSerial.begin(9600);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function ‘void nexLoop(NexTouch**)’:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:242:12: error: ‘nexSerial’ was not declared in this scope

while (nexSerial.available() > 0)

^

Using library ITEADLIB_Arduino_Nextion in folder: C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion (legacy)
Using library SPI at version 1.0 in folder: C:\Users\Ian\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.23\libraries\SPI
Using library SD at version 1.2.3 in folder: C:\Program Files (x86)\Arduino\libraries\SD
Using library SoftwareSerial at version 1.0 in folder: C:\Users\Ian\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.23\libraries\SoftwareSerial
exit status 1
Error compiling for board Arduino Nano.

Any help would be much appreciated

Ian

If you are using the Nextion libraries I suggest you use the versions developed by Ray Livingston, the originals are full of bugs. Beyond that I can't help as I don't use the libraries.

Ray Livingston's libraries

Thanks for the reply. iv down loaded all 3 files and put them in the libraries folded but still getting errors

In file included from C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.h:18:0,

from C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.h:21,

from C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:16:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function 'bool NexUpload::_searchBaudrate(uint32_t)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:111:5: note: in expansion of macro 'nexSerial'

nexSerial.begin(baudrate);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function 'void NexUpload::sendCommand(const char*)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:125:12: note: in expansion of macro 'nexSerial'

while (nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:130:5: note: in expansion of macro 'nexSerial'

nexSerial.print(cmd);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function 'uint16_t NexUpload::recvRetString(String&, uint32_t, bool)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:145:16: note: in expansion of macro 'nexSerial'

while (nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function 'bool NexUpload::_setDownloadBaudrate(uint32_t)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:183:5: note: in expansion of macro 'nexSerial'

nexSerial.begin(baudrate);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp: In member function 'bool NexUpload::_downloadTftFile()':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:211:21: note: in expansion of macro 'nexSerial'

nexSerial.write(c);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexUpload.cpp:225:17: note: in expansion of macro 'nexSerial'

nexSerial.write(c);

^

Using library ITEADLIB_Arduino_Nextion in folder: C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion (legacy)
Using library SPI at version 1.0 in folder: C:\Users\Ian\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.23\libraries\SPI
Using library SD at version 1.2.3 in folder: C:\Program Files (x86)\Arduino\libraries\SD
Using library SoftwareSerial at version 1.0 in folder: C:\Users\Ian\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.23\libraries\SoftwareSerial
In file included from C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.h:18:0,

from C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:15:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function 'void readDataMsg()':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:87:15: note: in expansion of macro 'nexSerial'

while(nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function 'void parseRx(byte*, int)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:172:15: note: in expansion of macro 'nexSerial'

while(nexSerial.available())

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function 'void sendCommand(const char*)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:458:5: note: in expansion of macro 'nexSerial'

nexSerial.print(cmd);

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function 'void nexBAUD(long int)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:480:5: note: in expansion of macro 'nexSerial'

nexSerial.print("baud=");

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp: In function 'bool nexInit(long int)':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexConfig.h:37:19: error: 'Serial2' was not declared in this scope

#define nexSerial Serial2

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion\NexHardware.cpp:500:5: note: in expansion of macro 'nexSerial'

nexSerial.begin(9600);

^

exit status 1
Error compiling for board Arduino Nano.

update

removed the 2 from the end off line 37 and now compiles

Iv connected the relay's but non are working

Thought I should add that the relay only triggers when a GND is applied to the trigger pins

Please read 'how to use this forum - please read', then post your code as per instructions in part 7, and post a schematic, along with photos of your project.

Thought I should add that the relay only triggers when a GND is applied to the trigger pins

You are asking us to help when we can't see your code or how you have wired things up, there are some clever people here but none of us are telepathic.

Thank you.

My apologies

This is the code so far

[code]#include "Nextion.h"
 
int R1 = 2, R2 = 3, R3 = 4, R4 = 5, R5 = 6, R6 = 7, R7 = 8, R8 = 9;
 
NexDSButton bt0 = NexDSButton(0, 1, "bt0");
NexDSButton bt1 = NexDSButton(0, 1, "bt1");
NexDSButton bt2 = NexDSButton(0, 1, "bt2");
NexDSButton bt3 = NexDSButton(0, 1, "bt3");
NexDSButton bt4 = NexDSButton(0, 1, "bt4");
NexDSButton bt5 = NexDSButton(0, 1, "bt5");
NexDSButton bt6 = NexDSButton(0, 1, "bt6");
NexDSButton bt7 = NexDSButton(0, 1, "bt7");
 
char buffer[100] = {0};
 
NexTouch *nex_listen_list[] = 
{
    &bt0, &bt1, &bt2, &bt3, &bt4, &bt5, &bt6, &bt7,
    NULL
};

// I have added start

//the relays connect to
int IN2 = 2;
int IN3 = 3;
int IN4 = 4;
int IN5 = 5;
int IN6 = 6;
int IN7 = 7;
int IN8 = 8;
int IN9 = 9;

void relay_init(void)//initialize the relay
{ 
//set all the relays OUTPUT
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(IN5, OUTPUT);
  pinMode(IN6, OUTPUT);
  pinMode(IN7, OUTPUT);
  pinMode(IN8, OUTPUT);
  pinMode(IN9, OUTPUT);
//relay_SetStatus(OFF,OFF);//turn off all the relay
}

// I have added end
void setup(void)
{    
    nexInit();
    bt0.attachPop(bt0PopCallback, &bt0);
    bt1.attachPop(bt0PopCallback, &bt1);
    bt2.attachPop(bt0PopCallback, &bt2);
    bt3.attachPop(bt0PopCallback, &bt3);
    bt4.attachPop(bt0PopCallback, &bt4);
    bt5.attachPop(bt0PopCallback, &bt5);
    bt6.attachPop(bt0PopCallback, &bt6);
    bt7.attachPop(bt0PopCallback, &bt7);
    dbSerialPrintln("setup done"); 
}
 
void loop(void)
{   
    nexLoop(nex_listen_list);
}
 
void bt0PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;
    
    dbSerialPrintln("Callback");
    dbSerialPrint("ptr=");
  
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));


// Pinout
const int EnclosureController = 9;
const int PSUFans = 8;
const int EnclosureHeater = 7;
const int ControlBoardFans = 6;
const int AmpMeters = 5;
const int MotorFans = 4;
const int ElectronicsLights = 3;
const int HotEndLights = 2;
    
    
  bt0.getValue(&dual_state);
  bt1.getValue(&dual_state);
  bt2.getValue(&dual_state);
  bt3.getValue(&dual_state);
  bt4.getValue(&dual_state);
  bt5.getValue(&dual_state);
  bt6.getValue(&dual_state);
  bt7.getValue(&dual_state);
 
   if(dual_state){digitalWrite(R1, HIGH);}else{digitalWrite(R1, LOW);}
   if(dual_state){digitalWrite(R2, HIGH);}else{digitalWrite(R2, LOW);}
   if(dual_state){digitalWrite(R3, HIGH);}else{digitalWrite(R3, LOW);}
   if(dual_state){digitalWrite(R4, HIGH);}else{digitalWrite(R4, LOW);}
   if(dual_state){digitalWrite(R5, HIGH);}else{digitalWrite(R5, LOW);}
   if(dual_state){digitalWrite(R6, HIGH);}else{digitalWrite(R6, LOW);}
   if(dual_state){digitalWrite(R7, HIGH);}else{digitalWrite(R7, LOW);}
   if(dual_state){digitalWrite(R8, HIGH);}else{digitalWrite(R8, LOW);}
}

[/code]

This is how its wired up

Diagram attached

That's better :slight_smile:

First off, understand that I do not know anything much about the Nextion libraries so any help I give will be limited and might be wrong. Your wiring looks correct, however I would run separate wires from the PSU to the Nextion, the relay board and the Nano, and I would put a 470μF or bigger capacitor across the Nextion, soldered to the power input connector (they generate a lot of big spikes on the power supply), possibly do the same on the relay board.

char buffer[100] = {0};

I don't know how the compiler responds to that, I would expect either:

char buffer[100];

or

char buffer[] = {value 1, value 2, value 3,.....value 99};

I don't know what it does if you define an array of 100 elements and then specify the value of one of them. If you need to initialise them then initialise all of them. If it's a buffer I wouldn't expect to initialise them. Maybe someone else will come along and tell both of us that what you have done is OK, in which case I will have learnt something too.

int IN2 = 2;

And all the others. Give them meaningful names like:

int Enclosure_controller = 2;

Your setup function

void setup(void) {
// Your setup code
}

Should be the first function at the top after the variables etc have been declared. I don't actually know what the compiler does with it if it's not the first function, but I suspect it won't be compiled properly.
setup should call:

relay_init

To initialise the relays.

In summary:

All declarations
void setup(void) {
    //setup code
    relay_init();
    //more setup code
}

void loop () {
   //loop functions
}
void relay_init() {
//relay initialisation code
}
//other functions...

Nowhere do you initialise a serial port for anything, I don't know if the Nextion libraries do that for you (my guess would be they don't), but you at least need to initialise the serial port for the serial monitor, then you can put Serial.print("some messages"); in strategic places in your code to see what is happening.

I cannot comment about whether the way your callback function works is correct, or any of the Nextion library stuff.

The fact you have made really basic errors with setup and loop makes me think you probably have not learned the basics of Arduino. If that's the case then please work through the various exercises and tutorials on this site, in the IDE and elsewhere.

1st Thanks for the reply

2nd Im completely new to all this, most I have done is altering Marlin Firmware for 3D printers

3rd I got the code from here

and made small changes at a time

Noted about the caps I will check and see what I have.

I have mad some changes as per your recommendations and now looks like this

#include "Nextion.h"
 
int R1 = 2, R2 = 3, R3 = 4, R4 = 5, R5 = 6, R6 = 7, R7 = 8, R8 = 9;
 
NexDSButton bt0 = NexDSButton(0, 1, "bt0");
NexDSButton bt1 = NexDSButton(0, 1, "bt1");
NexDSButton bt2 = NexDSButton(0, 1, "bt2");
NexDSButton bt3 = NexDSButton(0, 1, "bt3");
NexDSButton bt4 = NexDSButton(0, 1, "bt4");
NexDSButton bt5 = NexDSButton(0, 1, "bt5");
NexDSButton bt6 = NexDSButton(0, 1, "bt6");
NexDSButton bt7 = NexDSButton(0, 1, "bt7");
 
char buffer[100] = {0};
 
NexTouch *nex_listen_list[] = 
{
    &bt0, &bt1, &bt2, &bt3, &bt4, &bt5, &bt6, &bt7,
    NULL
};

// I have added start

//the relays connect to
int HotEnd_Lights = 2;
int Electronics_Lights = 3;
int Motor_Fans = 4;
int Amp_Meters = 5;
int Control_Board_Fans = 6;
int Enclosure_Heater = 7;
int PSU_Fans = 8;
int Enclosure_Controller = 9;

void relay_init(void)//initialize the relay
{ 
//set all the relays OUTPUT
  pinMode(HotEnd_Lights = 2, OUTPUT);
  pinMode(Electronics_Lights = 3, OUTPUT);
  pinMode(Motor_Fans = 4, OUTPUT);
  pinMode(Amp_Meters = 5, OUTPUT);
  pinMode(Control_Board_Fans = 6, OUTPUT);
  pinMode(Enclosure_Heater = 7, OUTPUT);
  pinMode(PSU_Fans = 8, OUTPUT);
  pinMode(Enclosure_Controller = 9, OUTPUT);
//relay_SetStatus(OFF,OFF);//turn off all the relay
}

void setup(void)
{    
    nexInit();
    bt0.attachPop(bt0PopCallback, &bt0);
    bt1.attachPop(bt0PopCallback, &bt1);
    bt2.attachPop(bt0PopCallback, &bt2);
    bt3.attachPop(bt0PopCallback, &bt3);
    bt4.attachPop(bt0PopCallback, &bt4);
    bt5.attachPop(bt0PopCallback, &bt5);
    bt6.attachPop(bt0PopCallback, &bt6);
    bt7.attachPop(bt0PopCallback, &bt7);
    dbSerialPrintln("setup done"); 
}
 
void loop(void)
{   
    nexLoop(nex_listen_list);
}

I have mad some changes as per your recommendations and now looks like this

Doens't look to me that you have followed my suggestions...

Hi
I have changed what I understand,
I changed char buffer to char buffer[100]; and got errors
I dident change the other stuff as Im not sure what you ment

IanSuggy:
Hi
I have changed what I understand,
I changed char buffer to char buffer[100]; and got errors
I dident change the other stuff as Im not sure what you ment

Don't give up. You have many miles to run as you are new to programming. :slight_smile:

I didn't change the other stuff as I'm not sure what you meant

The other stuff is important, as your program stands I would not expect it to work.

What do you not understand?

should be the first function at the top after the variables etc not even sure what variables are,

All declarations
void setup(void) {
    //setup code
    relay_init();
    //more setup code
}

void loop () {
   //loop functions
}
void relay_init() {
//relay initialisation code
}
//other functions...

I tryed various ways with adding this and must be getting it wrong

I think I may have bitten off more than I can handle.
I know I should have started at the beginning and learn the basics 1st but the touch screen is going in a project i'm working on

like I said i'm a complete noob to this and apologize if I causing anyone an headache

Iv made some more changes and the code now stands like this

#include "Nextion.h"
 
int R1 = 2, R2 = 3, R3 = 4, R4 = 5, R5 = 6, R6 = 7, R7 = 8, R8 = 9;
 
NexDSButton bt0 = NexDSButton(0, 1, "bt0");
NexDSButton bt1 = NexDSButton(0, 1, "bt1");
NexDSButton bt2 = NexDSButton(0, 1, "bt2");
NexDSButton bt3 = NexDSButton(0, 1, "bt3");
NexDSButton bt4 = NexDSButton(0, 1, "bt4");
NexDSButton bt5 = NexDSButton(0, 1, "bt5");
NexDSButton bt6 = NexDSButton(0, 1, "bt6");
NexDSButton bt7 = NexDSButton(0, 1, "bt7");
 
char buffer[100] = {0};
 
NexTouch *nex_listen_list[] = 
{
    &bt0, &bt1, &bt2, &bt3, &bt4, &bt5, &bt6, &bt7,
    NULL
};

//the relays connect to
int HotEnd_Lights = 2;
int Electronics_Lights = 3;
int Motor_Fans = 4;
int Amp_Meters = 5;
int Control_Board_Fans = 6;
int Enclosure_Heater = 7;
int PSU_Fans = 8;
int Enclosure_Controller = 9;

void relay_init(void)//initialize the relay
{ 
//set all the relays OUTPUT
  pinMode(HotEnd_Lights = 2, OUTPUT);
  pinMode(Electronics_Lights = 3, OUTPUT);
  pinMode(Motor_Fans = 4, OUTPUT);
  pinMode(Amp_Meters = 5, OUTPUT);
  pinMode(Control_Board_Fans = 6, OUTPUT);
  pinMode(Enclosure_Heater = 7, OUTPUT);
  pinMode(PSU_Fans = 8, OUTPUT);
  pinMode(Enclosure_Controller = 9, OUTPUT);
  relay_init(); // IDS

//relay_SetStatus(OFF,OFF);//turn off all the relay
}

void setup(void)
{    
    bt0.attachPop(bt0PopCallback, &bt0);
    bt1.attachPop(bt0PopCallback, &bt1);
    bt2.attachPop(bt0PopCallback, &bt2);
    bt3.attachPop(bt0PopCallback, &bt3);
    bt4.attachPop(bt0PopCallback, &bt4);
    bt5.attachPop(bt0PopCallback, &bt5);
    bt6.attachPop(bt0PopCallback, &bt6);
    bt7.attachPop(bt0PopCallback, &bt7);
    dbSerialPrintln("setup done");
    relay_init ();
          
}
 
void loop(void)
{   
    nexLoop(nex_listen_list);
}

void bt0PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;
    
    dbSerialPrintln("Callback");
    dbSerialPrint("ptr=");
  
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));


// Pinout
const int Enclosure_Controller = 9;
const int PSU_Fans = 8;
const int Enclosure_Heater = 7;
const int Control_Board_Fans = 6;
const int Amp_Meters = 5;
const int Motor_Fans = 4;
const int Electronics_Lights = 3;
const int HotEnd_Lights = 2;
    
    
  bt0.getValue(&dual_state);
  bt1.getValue(&dual_state);
  bt2.getValue(&dual_state);
  bt3.getValue(&dual_state);
  bt4.getValue(&dual_state);
  bt5.getValue(&dual_state);
  bt6.getValue(&dual_state);
  bt7.getValue(&dual_state);
 
   if(dual_state){digitalWrite(R1, HIGH);}else{digitalWrite(R1, LOW);}
   if(dual_state){digitalWrite(R2, HIGH);}else{digitalWrite(R2, LOW);}
   if(dual_state){digitalWrite(R3, HIGH);}else{digitalWrite(R3, LOW);}
   if(dual_state){digitalWrite(R4, HIGH);}else{digitalWrite(R4, LOW);}
   if(dual_state){digitalWrite(R5, HIGH);}else{digitalWrite(R5, LOW);}
   if(dual_state){digitalWrite(R6, HIGH);}else{digitalWrite(R6, LOW);}
   if(dual_state){digitalWrite(R7, HIGH);}else{digitalWrite(R7, LOW);}
   if(dual_state){digitalWrite(R8, HIGH);}else{digitalWrite(R8, LOW);}
}

All relays are now on when booting up but have no controll by the screen

I think I may have bitten off more than I can handle.
I know I should have started at the beginning and learn the basics

Hi Ian,
Yes you have and yes you should. Please go back and learn the basics. The mistakes you are making are very basic. You are asking for the equivalent of diving lessons when you can't swim. Please work through the tutorials on this web site, in the IDE and elsewhere, and ask for help if you get stuck. Put this project to one side for now.

Good luck.

Hello Ian,

I understand that you are new to programming. After all, we all have passed from this stage. I also feel that I am at that stage.

This forum was created as a place for all beginners to get help from each other and from the more experienced as well. So you shouldn't hesitate to ask anything. If someone knows, they will give you the answer or they will guide you. If they don't know, they will not answer.

Where is the .HMI file that you are using?
Please send a link for the .HMI file and for the Nextion library that you are using.

By the way, where are you going to use this little project, that you chose to start your programming experience?

Hi Seithan

This project is going on my HyperCube Evolution 3D Printer, at the moment all the switches are toggle switches that take up a lot off space on the control panel. Going touch screen to save space plus the main control board for the printer is touch screen and there's also an enclosure controller (not my own work) that is touch control. There are also 2 amp meter and a heat controller aswell (would be nice to be all touch screen)
HMI file download here

A very big OYAOY for you. :o
THIS is a project with all the meaning.
Seems very cool with the first sight.

If you could attach the .HMI not the .tft

Sorry Seithan

Must drink less

Here you go