A dumb question about Nextion IDE

I don't consider myself a dumb coder, but this one has me stumped!

I can't find the place in the Nextion IDE where I can put shared code. By shared I mean that I will trigger events from a test page on the Nextion before I hand off control to the serial input from an MCU.

It has to be there somewhere - I just can't find it.

Please help!

Thanks.

Hello Screwloose (really?!)

I'd like to answer your question, but I don't understand it. I don't know what you mean by shared code. Shared with what? To do what? What are you trying to achieve?

Also this:

Before I hand off control to the serial input

What does that mean? You don't have to hand off control to the serial input, data arrives on the serial input and the Nextion processes it.

Hi and thanks for your time to reply.

I want to have two page on the Nextion, one that will be the HMI and one that will be my testing screen.

There's some mathematics involved that will affect many gauges/controls etc on the main screen.

I want to send raw data from a testing page/screen on the Nextion, just like the MCU will do at a later date.

What I'm struggling to find is the place in the Nextion IDE where I can write a few functions such that I can push in values from my test screen and then very simply switch over to pushing in values derived from the MCU.

Does that make sense?

Where in the Nextion IDE can I attach a whole bunch of shared functions to either a button click on my HMI test page and later switch over to what the MCU is sending?

Thanks!

Right, erm...

I think I got that, but if this doesn't sound like the answer to your question then it's because I didn't understand the question properly!

Page 0, the actual page you want to use.
Page 1, a testing page which will generate stuff to be sent to page 0. Is this correct?

You can define objects on the Nextion as global, which means they don't go out of scope when you change pages. Be aware that the memory is limited so you risk running out. If you define on page 0 a global variable then what you do on page 1 can affect it. If you don't define objects as global then nothing that happens on page 1 will affect anything on page 0.

However, I don't understand why you are taking this approach. You can test the response of a page using the debug option from the menu bar on the IDE. Debug opens a simulation of the display and gives you an area to type in instructions exactly as they might arrive on the serial port, and to see the response that would be sent to the serial port.

Finally a plug for my tutorial: 'Using Nextion displays with Arduino'

There's some mathematics involved that will affect many gauges/controls etc on the main screen.

Send the button presses to the host, do the maths there, send the results back to be displayed.

Where in the Nextion IDE can I attach a whole bunch of shared functions to either a button click on my HMI test page and later switch over to what the MCU is sending?

You don't need to. If a valid instruction is under a button it will be processed when the button is pressed. If a valid instruction arrives on the serial port it will also be processed, just the same.

Thanks everyone.

I'll try again :slight_smile:

Somewhere I want to write

void updateWidget(int _value)
{
// do my stuff here with _value
}

I want to call this from many places, be that events on my test page or events on receiving something from the MCU down the serial line.

Is there a place in the Nextion IDE where I can put what I call 'common code' - i.e. centralised code that I can call from events generated from a whole heap of different objects?

Thanks again for your patience :slight_smile:

Thanks everyone

Is there more than one of me? OH! :slight_smile:

Somewhere I want to write

void updateWidget(int _value)

{

// do my stuff here with _value
}

While you can write code on the Nextion it is very limited, more C-- than C++ (or even just C). You certainly can't put that!

Create a button and put your code under either touch press event or touch release event as you see fit. You can then use:

click <object name>,1
click <object name>,0

Under other buttons to execute the code.

Now you are thinking that you don't want random buttons all over the display. Make the buttons 1 pixel by 1 pixel and make their background colour match the display background. Put them somewhere on the display where they are out of the way, such as in a corner.

Thanks for your time and advice - I really appreciate it :slight_smile:

I suppose what I was hoping for was the ability to have a 'global function' just like you can have 'global Vars'. (if that makes sense).

I'm not set on using this device (Nextion display) yet and I was trying to divorce the display coding from the MCU. I don't want to pollute my MCU code with Nextion specific commands.

I'm just trying to figure out my inter-device interfaces such that hopping to a new HMI would cause the least number of problems!

Regards
Screwie.

It's like any product, you have to understand what it can and cannot do.

My most complex project is a heating controller with a Nextion as the interface, it has 5 pages. I do very little processing on the display, almost all is done on the host.

In terms of the most amount of on display processing; I have a DAB radio with an Arduino controlling it. The available stations are displayed in red, the station currently being listened to in green. The changes to the text colour are done with code on the Nextion.

I don't want to pollute my MCU code with Nextion specific commands.

There's no way to have no Nextion (or any other kind of display) code on your MCU (unless you can find a telepathic interface...). I generally have a separate file to hold all the Nextion related code so it is separate from everything else, with calls to the Nextion code when needed. If you were to look at my various projects you'd see the Nextion code is basically the same on each, with modifications to suit the individual projects.

Hi Perry,

I just wanted to let you know that I've made a massive amount of progress on this project due to all the help and information you wrote in this thread.

I'm slowly teasing it all apart to get to what I'd term in Java coding terms as a 'clean interface'.

Hopefully I'll be able to share some code that doesn't rely on Nextion.h

Thanks again for your help - I really mean that.

Glad to be of help and glad you are making progress :slight_smile: