External button to change page on Nextion

Hi, Nextion /Arduino noob here, I have had some great help from Line 6 Midi Facebook group, but I have bothered them enough for now.I've had some good examples but wondered if there was another way.

I've built a simple 4 button MIDI foot controller to use with my HX Stomp with a Nextion 2.8" basic screen as graphic "scribble strip", no functionality needed from the touch screen.
This is functioning and communicates between Arduino Mega and HX.

I have 4 pages (for now) in the Nextion Editor and all I want to do is trigger the Nextion page changes from the momentary switches via Arduino. I may add more to correspond with double click and long press.

You might ask why I don't just send text and colour changes from the Arduino, well, I thought this might be simpler!Maybe it isn't...

Your advice / help is most welcome.
I have attached page 1, the text should just change on the other pages according to button pressed
Thanks
Rog

Hello Rog_BY,

Welcome to the Arduino fora.

Support for Nextion on these fora is pretty much as follows:

You can follow the methods I set out in using Nextion displays with Arduino. My methods do not use the Nextion libraries, so I can offer help on using my methods but I cannot offer anything very helpful for any Nextion library.

The original Nextion libraries are full of bugs. There is a link from my tutorial to to some improved Nextion libraries created by Ray Livingston, I suggest those might be worth trying if you prefer to use a library.

There's also a guy on here called Seithan who has also developed his own ways of dealing with Nextion displays, you can find his methods in his tutorial on how to write code with Nextion and Arduino.

Beyond that the odd person occasionally offers a bit of help but not much.

I want to trigger Nextion page changes from the momentary switches via Arduino. I may add more to correspond with double click and long press.

You might ask why I don't just send text and colour changes from the Arduino, well, I thought this might be simpler!Maybe it isn't...

This is confusing, first you say you want to trigger page changes then you say you want to send text and colour changes, what exactly do you want to do? Change pages? Change colours? Change text?

I thought this might be simpler!Maybe it isn't...

It's very simple.... I realise you are new here but the general idea is you show us what you've done, explain what it does and how it is different from what you want it to do and ask for help. You've not shown anything of what you've tried, which raises the suspicion that maybe you've not tried anything much. Please take a moment to read General guidance
And
How to use this forum, both of which give advice on getting the best out of these fora.

When you've done all that, tried something and got stuck please don't hesitate to ask for more help.

Thanks.

PerryBebbington:
Hello Rog_BY,

Welcome to the Arduino fora.

Support for Nextion on these fora is pretty much as follows:

You can follow the methods I set out in using Nextion displays with Arduino. My methods do not use the Nextion libraries, so I can offer help on using my methods but I cannot offer anything very helpful for any Nextion library.

The original Nextion libraries are full of bugs. There is a link from my tutorial to to some improved Nextion libraries created by Ray Livingston, I suggest those might be worth trying if you prefer to use a library.

There's also a guy on here called Seithan who has also developed his own ways of dealing with Nextion displays, you can find his methods in his tutorial on how to write code with Nextion and Arduino.

Beyond that the odd person occasionally offers a bit of help but not much.
This is confusing, first you say you want to trigger page changes then you say you want to send text and colour changes, what exactly do you want to do? Change pages? Change colours? Change text?
It's very simple.... I realise you are new here but the general idea is you show us what you've done, explain what it does and how it is different from what you want it to do and ask for help. You've not shown anything of what you've tried, which raises the suspicion that maybe you've not tried anything much. Please take a moment to read General guidance
And
How to use this forum, both of which give advice on getting the best out of these fora.

When you've done all that, tried something and got stuck please don't hesitate to ask for more help.

Thanks.

Thanks for the response. I do appreciate what you have said, and I have read through all those tutorials, trouble is there are a number of suggestions for skinning this particular cat, and that has left me confused.

I only want to change 4 pages to correspond with the 4 buttons, but it seems that sending code from Arduino to change text is the most normal way. As the Nextion is a passive graphical display in my case, I thought there might a simple way to get this page change done.
Thanks again
Rog

Rog,

I don't really know what to tell you beyond referring you to the tutorial. I don't know what you mean by 'a simple way'. You send a text string to the Nextion, that's how they work. The text string tells it to do something. Is that not simple enough? My tutorial is full of functions that do exactly that. Take one of those functions and modify it for whatever it is you want to make the Nextion do.

Thanks I'll try that today.

This is as far as I've got, it compiles but I'm not sure how to call the pages and how to make 3 more instances of the Digital button on pins 3 4 5.
Any help would be appreciated.

#include <doxygen.h>
#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 <MIDI_Controller.h> // Include the library

const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)


// Create a new instance of the class 'Digital', called 'button', on pin 2, that sends MIDI messages with note 'C4' (60) on channel 1, with velocity 127

Digital button(2, 1, velocity); 


NexPage page0    = NexPage(0, 0, "page0");
NexPage page1    = NexPage(1, 0, "page1");
NexPage page2    = NexPage(2, 0, "page2");
NexPage page3    = NexPage(3, 0, "page3");

NexTouch *nex_listen_list[] = 
{
    &page0,
    &page1,
    &page2,
    &page3,
    NULL
};

void page0PopCallback(void *ptr)
{
    dbSerialPrintln("page0PopCallback");
    page1.show();
}

void page1PopCallback(void *ptr)
{
    dbSerialPrintln("page1PopCallback");
    page2.show();
}

void page2PopCallback(void *ptr)
{
    dbSerialPrintln("page2PopCallback");
    page3.show();
}

void page3PopCallback(void *ptr)
{
    dbSerialPrintln("page3PopCallback");
    page0.show();
}

void setup()

{nexInit();
    dbSerialPrintln("setup begin");
    
    page0.attachPop(page0PopCallback);
    page1.attachPop(page1PopCallback);
    page2.attachPop(page2PopCallback);
    page3.attachPop(page3PopCallback);
    
    dbSerialPrintln("setup end");}

void loop() {
  // Refresh the button (check whether the button's state has changed since last time, if so, send it over MIDI)
  MIDI_Controller.refresh();nexLoop(nex_listen_list);
}

Hi Reg,

Unfortunately, as I have already mentioned, I don't know anything much about the Nextion libraries, so I can't offer much help on code based on them. What you have is not based on the methods I demonstrate in my tutorial. If you use my methods I will try to help.

I can tell you that you only need to include <Nextion.h>, I assume all the others are included automatically if you include <Nextion.h>.

++Karma; // For correctly using code tags the first time you posted code.

Thanks, maybe someone else might see this and have an idea.

I've created an array of buttons and they all TX from Arduino but still no comms with the Nextion

#include <Nextion.h>



#include <MIDI_Controller.h> // Include the library
static const byte switchPin[] = {2,3,4,5}; // pins for footswitch inputs
static const byte switchCount = 4; // number of footswitches used
static bool switchPressed[switchCount]; // current state of footswitches
static bool switchLastState[switchCount]; //previous state of footswitches (used for long press detection)
const uint8_t digitalPins[] = { 2,  3,  4,  5};
const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t channel = 1; // MIDI channel 1

// Create a new array  of the class 'Digital', called 'button', on pins 2-5, that sends MIDI messages with note 'C4' (60) on channel 1, with velocity 127
  Digital buttons[] = {
  { 2, 1, velocity }, // button connected to pin 0, velocity 127
  { 3, 1, velocity },
  { 4, 1, velocity },
  { 5, 1,velocity },
  };

NexPage page0    = NexPage(0, 0, "page0");
NexPage page1    = NexPage(1, 0, "page1");
NexPage page2    = NexPage(2, 0, "page2");
NexPage page3    = NexPage(3, 0, "page3");

NexTouch *nex_listen_list[] = 
{
    &page0,
    &page1,
    &page2,
    &page3,
    NULL
};


void page0PopCallback(void *ptr)
{
    dbSerialPrintln("page0PopCallback");
    page1.show();
}

void page1PopCallback(void *ptr)
{
    dbSerialPrintln("page1PopCallback");
    page2.show();
}

void page2PopCallback(void *ptr)
{
    dbSerialPrintln("page2PopCallback");
    page3.show();
}

void page3PopCallback(void *ptr)
{
    dbSerialPrintln("page3PopCallback");
    page0.show();
}

void setup(){

  
  Serial.begin(115200);
}



void loop() {
  // Refresh the button (check whether the button's state has changed since last time, if so, send it over MIDI)
  MIDI_Controller.refresh();nexLoop(nex_listen_list);
   }