As a brand new member of the forum and a complete novice of the world of arduino (and coding in general) i have undertaken a task that may well be too much for a first attempt. I have designed a HMI interface with a nextion 3.5 basic and need said HMI to control 3/4 relays on a elegoo 4 way relay module. I have had a attempt at the coding (please be kind this is a first ever attempt) but cant seem to get it to function. Intially all i need this code to do is push b1 and for digital pin 13 to give an output which will switch the relay. Once pressed again i would like said relay to turn off. in the code below there will be 6 buttons, but b1 b2 b3 are the important 1s, the rest i will worry about later. I will list the code and pic of my setup below and hope that some1 could point me in the direction of where i am going wrong. Thanks in advance IMG_20191205_215405
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>
#include "Nextion.h"
const int gas = 13;
const int oil = 12;
const int fan = 11;
NexButton b1 = NexButton(3, 3,"b1");//manual control gas
NexButton b2 = NexButton(3,4,"b2");//manual control oil
NexButton b3 = NexButton(3,5,"b3");//manual control fan
NexButton b4 = NexButton(2,2,"b4");//30min cycle
NexButton b5 = NexButton(2,3,"b5");//60min cycle
NexButton b6 = NexButton(2,4,"b6");//90min cycle
NexTouch *nex_listen_list[] = {
&b1,
&b2,
&b3,
&b4,
&b5,
&b6,
NULL
};
//button1
void b1PushCallback(void *ptr){
digitalWrite(13,HIGH);
}
//button2
void b2PushCallback(void *ptr){
digitalWrite(12,HIGH);
}
//button3
void b3PushCallback(void *ptr){
digitalWrite(11,HIGH);
}
void b1PopCallback(void *ptr) {
digitalWrite(13,LOW);
}
void b2PopCallback(void *ptr) {
digitalWrite(12,LOW);
}
void b3PopCallback(void *ptr) {
digitalWrite(11,LOW);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//registering the push and pop callback function of the components
b1.attachPush(b1PushCallback);
b1.attachPop(b1PopCallback);
b2.attachPush(b2PushCallback);
b2.attachPop(b2PopCallback);
b3.attachPush(b3PushCallback);
b3.attachPop(b3PopCallback);
}
void loop() {
// put your main code here, to run repeatedly:
nexLoop(nex_listen_list);
}
Hello Darren,
Welcome to the forum.
For posting your code correctly and generally asking a well formed question in line with the forum rules on your first post ++Karma;. I just wish every new person took as much care.
I don't know or use the Nextion libraries, so I can't give much advice on them. While there are people on here who do know them reasonably well advice about them is is bit thin on these fora.
The original Nextion libraries from ITEAD were full of bugs. If you go to my tutorial 'using Nextion displays with Arduino' (at the top of the displays' section of forum) you will find a link in the first post to a version of the Nextion libraries created by Ray Livingston. Ray has tidied them up and removed many of the bugs.
You could of course try my methods as set out in my tutorial, however my approach is quite different to the way the libraries work, so you will have to understand how to use my methods. There is, however, support for them (me!).
If you prefer to use the libraries then the only advice I can give beyond trying Ray's version is to strip back your code to something very simple that only controls one output. Get that working first, then add in the other stuff.
PerryBebbington:
Hello Darren,
Welcome to the forum.
For posting your code correctly and generally asking a well formed question in line with the forum rules on your first post ++Karma;. I just wish every new person took as much care.
I don't know or use the Nextion libraries, so I can't give much advice on them. While there are people on here who do know them reasonably well advice about them is is bit thin on these fora.
The original Nextion libraries from ITEAD were full of bugs. If you go to my tutorial 'using Nextion displays with Arduino' (at the top of the displays' section of forum) you will find a link in the first post to a version of the Nextion libraries created by Ray Livingston. Ray has tidied them up and removed many of the bugs.
You could of course try my methods as set out in my tutorial, however my approach is quite different to the way the libraries work, so you will have to understand how to use my methods. There is, however, support for them (me!).
If you prefer to use the libraries then the only advice I can give beyond trying Ray's version is to strip back your code to something very simple that only controls one output. Get that working first, then add in the other stuff.
Thanks for the reply Perry,
Believe it or not Perry i had actually already had a read through your post via google search and found it quite informative as well as witty lol. For the moment i will continue the way i have started (i dont want to confuse myself any more by starting with a new way of programming)and see if i can get anywhere but i certainly appreciate you offering your time. I will take your advice a have a look at rays version of the libraries and hope this may iron out the initial problems i am having.