Uploading image to Nextion screen via Arduino WITHOUT using microSD card

We are using a Nextion intelligence HMI screen, but have only managed how to show an image on the screen via flashing the microSD card. However, for our project purposes, we would like to be able to upload an image via the Arduino directly from our computer. But when we try to upload an image from the Nextion editor (the image is preloaded), it says the “connection failed”. We have arduino code: #define nextion Serial1 // Use Serial1 on Arduino Due (connect TX1/RX1)

void setup() {
    Serial.begin(115200); // Debugging via USB Serial
    nextion.begin(115200); // Nextion Serial

    delay(500); // Allow Nextion to start

    // Example: Show an image on a page (assuming image ID is 1)
    nextion.print("pic 1,0");  // Display picture ID 1 on component 0
    sendCommand();
}

void loop() {
    // No need for continuous execution
}

void sendCommand() {
    nextion.write(0xFF);
    nextion.write(0xFF);
    nextion.write(0xFF); // Nextion requires three terminating bytes
}

How can we solve this?

We have been following @PerryBebbington ’s Nextion Guidance so far.

I'll have a look later, I am busy at the moment.

Please put your HMI file in a zip file and upload it to the forum.

Thanks
Edit,
The code you posted is incomplete, nowhere have you declared the Nextion serial port.

Hi Perry, thanks for taking a look at this. I accidentally didn’t
paste the first line of our code in, we defined it as:

#define nextion Serial1

Here is our nextion editor HMI file: test2.zip (377.9 KB)

nextion.begin(115200); // Nextion Serial

It appears to me that your Program.s file is setting the baud rate at 9600.

/The following code is only run once when power on, and is generally used for global variable definition and power on initialization data
int sys0=0,sys1=0,sys2=0     //At present, the definition of global variable only supports 4-byte signed integer (int), and other types of global quantity declaration are not supported. If you want to use string type, you can use variable control in the page to implement
baud=9600//Configure baudrate
dim=100//Configure backlight
recmod=0//Serial data parsing mode:0-Passive mode;1-Active mode
printh 00 00 00 ff ff ff 88 ff ff ff//Output power on information to serial port
page 0                       //Power on start page 0

Thank you for the HMI file.

I am not familiar with the Intelligent series of Nextion HMI so they have additional commands I have never used.

@cattledog beat me to it on the baud rate. My advice is always start with the default 9600 baud rate, only increase it when you are happy your code works at 9600, especially given you have a serial problem.

I suggest you are trying to run before you can walk, you have a HMI file with 2 pages and a Program.s file before you have got one simple command to work. Create the most simple file you can that does the minimum of what you are trying to do and only when that works move on to something more complicated.

I suspected so, but leaving it out of the code you posted left a possible gap. Again, keep it simple, use serial1 as serial1, don't define it as something else, this is one more thing that might be wrong.

Another thing that might be wrong is your wiring, please don't say you wired it the way I said or someone else said, show us exactly how you wired it. Clear photos help, as does a schematic.

Your HMI file shows picture ID 1 as already on component 0, so what do you expect that sending this command will do?

Nothing you have told us suggests that your computer is connected to your Nextion. Based on what you have said your Nextion is connected to the Due, not to the computer, so of course it fails.

Hi Perry and Hi @cattledog, thanks for your advice and time. We will double check the baud rate issue in the Nextion editor code, and see whether a more simple HMI file works.

I’ve attached an image and drawn out schematic of our wiring



(The extra breadboard in our photo is due to us connecting an external DAC chip and SMB). As you can see, we have managed to get a static image up, and we recently tested a callback loop for the RX and TX pins, so we know that the arduino pins are functioning as expected.

The line

nextion.print(“pic 1, 0)”;

We expected to indicate to the Nextion screen which picture we wanted to change the screen to.

With regards to the computer connection, do you think it is still possible to upload the image if the Nextion screen connects to the Arduino Due, and then the Arduino Due connects to the computer?

Thanks

Thanks for the photos and showing the wiring, they look correct to me.

While I don't think it is the cause of your problem I do think this is another example of you trying to do too much at once, do one thing only and get it working to your satisfaction before adding anything else, this applies both for code and electronics.

Yes, but when I tried I didn't get it to work. I wrote some code on the Arduino in question to transfer the data from serial to serial1 and back the other way. I didn't investigate very much, I am sure it can be made to work but I gave up trying. Instead I got a USB serial adapter (not RS232, if you don't understand this please ask) and used that to upload directly from my PC to the Nextion. Again, at the risk of repeating the same message, if you want to do this then get this one thing working with a simple HMI file before trying anything more complicated.

I'm not exactly clear about what you are trying to do.

Are you trying to change the image displayed by selecting one of the images stored on the Nextion and shown in the picture resource pane?

Or are you trying to load a new picture during the run of the program? Are you trying to add this image to the picture pane, or are you trying to display directly it directly on the screen? I'm not certain that this later operation is possible.

Are you trying to update the data shown in the graphs of the image?

We have confirmed the function of the DAC chip and SMB part of the circuit and just left it connected, we shall try with it disconnected.

For our project we wanted data to be specifically transferred from Arduino, rather than from a computer connection directly, as we are doing so digital biosignal processing in MATLAB, which cannot interface with the Nextion editor, but it can with Arduino. To clarify, we are not trying to send the data itself, but just a “screenshot”/static image of the plot that is being create after the signals have been processed. Our team is very grateful for your advice, but we are aware that this task seems possible do to there being RX and TX pins but haven’t found evidence of it actually being done. Would you be able to let us know if you manage to get the Arduino code to work? Thank you so much! We will keep testing and debugging as you suggested in the meantime.

Hi Cattledog, sorry for any confusion. We are trying to change the image on the Nextion screen that has been uploaded to the editor, but not flashed onto the microSD card. So I guess you could say it is trying to upload a new picture to the screen via Arduino which is connected to the computer, but not directly via the computer.

It isn’t exactly the data in the graphs, as the graphs are going to be generated in MATLAB on the computer, but the static image of those graphs are what we are trying to upload. Our user will interact with our device and change the variables in the ECG, which then creates new graphs, and we want to be able to display these new graphs each time effectively. Do you think that this is possible with the hardware that we have?

I do not think what you are trying to do is possible. As far as I know, all images must be loaded through the Nextion Editor when you are designing your configuration of the Nextion display.

I have not seen any references to being able to load new images. You can only select from what is in the image panel.

I agree with @cattledog , I don't believe what you are trying to do is possibly.

Well, when I say it's not possible I would clarify that as the Nextion IDE can send a new image then it must be possible for something else to do the same. To do this you would have to decode what the Nextion IDE is sending and replicate it from other software. I suggest that doing so would be difficult and, without wishing to be rude to you or your colleagues, well beyond your current abilities, it would stretch my abilities a very long way.

That makes sense. Thanks again for sharing your thoughts - out of curiosity, what would you advise a team such as ours do moving forward? We are considering looking at other screens, as it is quite a main component of our project.

Be clear what a Nextion HMI is and is not. Although it incorporates a display I think considering it to be a display is misleading. It is not designed to display any random image you send to it on the fly, it is designed to display pre-loaded images in a pre-designed layout. It is designed to make a 2 way interface between human and machine, it is not a general purpose display.

Nextions do have a graph facility, which is called a 'waveform', which might be what you need. I use one to show weather data from instruments mounted on my house. I suggest you investigate that and see if it is what you need.

If you want to display images on a display then you are out of the range of my knowledge, I can't help with that. I also have no idea if a Due has the required processing power, certainly something like a Uno or Mega has nothing like the memory or processing power to do what you want.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.