Nextion serial display fail

I’ve not looked too close, but you are sending four 0xFF bytes and why do you not do the page change in the Nextion without a µC?

Thank you! Damm it, I didn’t see that.

I wanted to do this way so I can know that the display wants to go to settings page. So my photon prepares to receive any data related to that. In other case, my photon is doing some stuff nothing related to this.

But, I am just testing the connection between both devices. I don’t have anything coded yet about this.

After some delay I’m resuming work on this. I am now able to send a few basic commands to the display and see the results there.

But I decided it might be better to power the Nextion from a separate 5 V wall wart rather than using the Vin pin on the Photon (which is plugged into a PC USB port), just for load distribution.

However, I discover that when I do this, the display seems to ignore all serial input from the Photon. I’m going to guess that this is due to some ground level difference between the PC’s USB port and the wall wart powering the Nextion.

I’m not that great at hardware, so before I let out any magic smoke anywhere, is it OK to tie together the ground of the wall wart and the PC (by connecting them on the breadboard the Photon is sitting on)? Or is that maybe not even the problem? I don’t want to fry my display, and especially not the PC. Obviously confused…

You need to make sure the GND from the 5v output on the wall wart is connected the GND on the Photon so data communication between the 2 units can work. They need a common ground.

Thanks! That’s what I suspected, but I didn’t want to make a costly mistake if there was going to be something wrong with that. That worked perfectly.

Now I’m wondering if anyone can point me to some documentation for the ITEAD_Nextion library I’ve looked at https://github.com/LukeUSMC/ITEADLIB_Particle_Nextion-master/tree/master/doc/Documentation but that just prints raw HTML and doesn’t give what I’m looking for. I’d like just a list of all the functions I can call and the arguments they take.

All I really need to port my weather station code from the Sparkfun serial LCD display to the Nextion is the ability to do:

  • move the cursor to an x,y location
  • change font, font size and color,
  • print some text,

I don’t know about the cursor, like a mouse? Font, font size and color, you have to see if those properties are green on the element you want to change. If they are green, you can modify them, if they don’t, you cannot. I don’t have nextion ide installed right now, so I can’t check.
In case they are green, I guess you should do something like: “t1.font=3” to modify text to font number 3. Fonts and font sizes are related. You have to create fonts before you can apply them.

To print some text: “t2.txt=hello”.

I usually do like this:

void menu_print_ff(void) {
    Serial1.write(0xff);
    Serial1.write(0xff);
    Serial1.write(0xff);   
}

And then:
        Serial1.print("t");
        Serial1.print(i);
        Serial1.print(".txt=");
        Serial1.write(0x22);
        Serial1.print(text_to_print);
        Serial1.write(0x22);
        menu_print_ff();

If you use my ITEADLIB_Nextion library there are extra fuctions to do some drawing and text output without a dedicated widget too.

But for most cases you should be good with the widgets - that’s the main advantage of these HMI displays.

Thank you both for the replies. I guess I’m having trouble understanding the work flow here. With the Sparkfun display, I just call functions to set the cursor position (by which I mean just where on the screen the next text will appear), and print text, done.

I’d like to do the same thing on the Nextion, but I don’t get how the Nextion editor is involved with this. All the editor examples seem to create text objects or fancy gauges or whatever and then leave it at that. They don’t give any runtime applications that actually use these UI’s.

So do I understand correctly that if I want say some large font, I first have to create it with the editor, then create a text object that uses that font, then save an HMI file and send it to the display? Then how do I refer to that in my Photon code?

Right now I can say

NexText t0 = NexText(0,1,"t0");
t0.setText("Hello world\0");

without invoking the editor at all and I get the default font. But what if I declared a t0 object in the editor? Can I then just do the t0.setText from the Photon at runtime without declaring t0 at all there? Seems wrong.

These displays are not text based but graphical, so you don’t write/print to the screen but draw text.

And the samples in my lib do actually interact with the widgets you place on the screen with the Nextion Editor.
But these displays are smart. They can do a lot of the work even without anexternal µC via the proprietory script language in the editor.

These sentences don’t seem to make sense

what now? Declared or not?

If I create a text object in the editor named t0 and send the resulting HMI file to the display, then what do I say in my own Photon code to put text into t0 so it will appear on the display?

If I just say

t0.setText("Hello world\0");

it fails to compile.

For example, your example
https://github.com/LukeUSMC/ITEADLIB_Particle_Nextion-master/blob/master/examples/CompText/CompText.ino
declares (and uses) a t0 object, but it doesn’t seem to have come from the editor. I admit, I’m clearly missing something on a fundamental level here.

It may be a bit confusing since you are using t0 for both things: The Nextion widget is called t0 and the C++ object you use to communicate with that widget is also called t0.
So you’d need to keep these two apart when talking about them.

And whenever you state something like

The common call is: “What exactly does the error message tell you about the reason?”

And this is where the two t0 entities (widget & C++ object) get bound together

/*
 * Declare a text object [page id:0,component id:1, component name: "t0"]. 
 */
NexText t0 = NexText(0, 1, "t0");

You could call the C++ object whatever you like, but the parameters in the object constructor have to correspond to the properties of the widget.
like

NexText myText = NexText(0, 1, "t0");
...
  myText.setText("Hello world");  // string literals don't require an explicit \0, the compiler does that already

OK, now it’s really screwed up. I tried uploading an HMI file via the serial port through the Photon. As it was going, very slowly, I realized I’d made a mistake so I decided to fix that and restart the download. I clicked on cancel and fixed my code. But now when I try to upload the Nextion Editor tells me

"Connection failed
Forced interrupt!"

I read somewhere that the way to fix this is to upload the file via an SD card. But when I do that, the display goes

"SD Card Update...
No Find File"

even though there is exactly one file on the whole card and it is an HMI file.

Arrrgh. Now what?

Update

Never mind. For the benefit of anyone else here, this fixed it for me.

  1. Forget the SD card.
  2. Unplug the display.
  3. Power cycle the Photon.
  4. Plug in the display.
  5. Create an empty TFT file (a project with nothing in it).
  6. Enter Debug mode in the Editor and connect to the Photon’s serial port at 9600 baud. This should work.
  7. Exit Debug mode.
  8. Now you can click on Upload and it should work.

See the last post at http://support.iteadstudio.com/support/discussions/topics/1000061009/page/2?url_locale=

To update a display via SD card you need to put the compiled TFT file on the SD card, not the HMI source file.

1 Like

OK, that explains that. I’ve corrected my previous post. Thanks.

Now I have a new problem. When my TFT file finally finished uploading via the serial connection, I got this on the display screen:

Model does not match
Device model:
NX8048K070_011R

But what I’ve selected in the Nextion editor is NX8048K070_011 (without the trailing “R”), ie. the 7" Enhanced display. And that is exactly what is silkscreened on the back of the display. There is no choice for a model ending in R in the editor.

But if I upload the TFT file to the display via SD card it works fine. ???

That’s the reason why I always use SD card.
I regularly got failing serial uploads and with that speed the time wasted is just not worth it IMHO.

I’m inclined to agree with you now. This serial upload business reminded me of the old 110 baud teletype days. It’s not worth it. Thanks.

I think I’m finally starting to get the hang of this. I have begun creating the objects needed to port over my weather display from the Sparkfun LCD.

Just one thing - is there any way to adjust the display brightness? I tried saying

Serial1.write("DIM=50\x00\x00\x00");

but the brightness doesn’t change.

You need to terminate a command with three times 0xFF not 0x00
But isn’t there a command in my lib for that?

There might be, but I can’t find it. Is there a simple list of all the functions in the library by name? I’ve found lots of examples, but no list of functions. That would be great.

In any case

Serial1.write("DIM=30\0xFF\0xFF\0xFF");

still doesn’t work for me either. I’m calling this from the Setup section of the Photon code. Is there some buffer-flushing command I need to send too perhaps?

… update …

Well upon further googling, I discovered setCurrentBrightness and

setCurrentBrightness (20) ;

works like a champ. But I’d still like to be able to browse a list of things I can set.

I want to print a temperature as a number that ends in a degree symbol (ASCII 248). But when I say

TempF.setText ("72\0xF8\0") ;

it just prints “72”. Does the Nextion not support extended ASCII? Or am I doing somethign else wrong again?