Anyone Used Nextion Displays?

MurrayJ

Senior Member
Just googling touch screen displays that I can use with my Picaxe, and found these Nextion displays and they seem perfect - cheap, easy to connect to - serial only, and have a touch screen.

The problem is I haven't been able to find any Picaxe code to get me started, or even if the Picaxe can run these displays, although I can't see why not.

Anyone used these before or can give me a simple starter code to get started?
 

Attachments

hippy

Technical Support
Staff member
Not used them myself but I would expect them to be similar to other LCD graphic displays.

The main problem with graphic displays is the amount of memory required to hold images for them and the time it takes to get data to them, though that's not so problematic if they support raw text display and they can simply be used as very large LCD text displays.

Some displays also have the ability to hold their own graphics and backdrops and it's simply a matter of asking for an image to be put somewhere. The Nextion seems to have some standalone capability in that respect, and an editor which can help with creating displays, images and backdrops, but I don't know much more about them than that.
 

MurrayJ

Senior Member
Not the sort of information my feeble brain can comprehend, back the the drawing board I suppose. The 4D Systems LCD screens look promising.
 

eggdweather

Senior Member
It's not too difficult to use, commands are always in lower case so for example to draw a line on the display connected to port pint b.2 and set to 9600baud you would send to the device:

serout b.2, n9600, ( "line 0, 0, 100, 100, RED")

serout b.2, n9600, ( "cls BLACK") ; clears the screen to black or whatever colour you choose
serout b.2, n9600, ( "fill x, y, w, h, color) ; choose you position x,y then width then height then colour and it fills that space with a colour
serout b.2, n9600, ( "draw 0, 0, 100, 100, RED") ; draw a red rectangle
serout b.2, n9600, ( "cir 100, 100, 30, RED") ; draw read circle
serout b.2, n9600, ( "cirs 100, 100, 30, RED") ; draw a solid/filled circle
serout b.2, n9600, ( "print ""123""") ; Prints 123 on the screen
And so on with the other commands, you can produce really complex screens if required, so it is very powerful and flexible. Check out what folks have done on YouTube as an example, noting its all text based.

So with just text strings you can do quite a lot with minimal PICAXE overhead.

You can upload images to it, get feedback from a touch of the screen and so on.

Some commands need termination characters like 0, 255, 255 but I left those off from the explanation.
 
Last edited:

MurrayJ

Senior Member
Thanks, thats more like the info I need, seems much easier now to understand, I may just be able to use these screens after all. Thanks for the help, it is much appreciated.
 

inglewoodpete

Senior Member
It's not too difficult to use, commands are always in lower case so for example to draw a line on the display connected to port pint b.2 and set to 2400baud you would send to the device...
I'm guessing that there are a couple of typos there? The sample commands you provide are 9600baud.
 

tony_g

Senior Member
im waiting for one of these to arrive, but it shouldnt be an issue to use with picaxe as all of your display for pages ect is all handled by the lcd and the nextion software to create/load onto the lcd.

the picaxe wont have to do all of the grunt work for the display just send and recieve data and process it, if a button is pushed on the screen it spits out a serial data packet and the picaxe can simply read what happened with the display and what button was pressed and carry out an appropriate action or send data to the screen when something happens so it can alert you of something by changing the display.

looking forward to getting mine although i have to decide now what project gets it and what others can wait lol.


tony
 

cloudy

Member
I am using one of these (5") on a 40x2 - works really well

Whilst you can fire off primitive drawing commands - it's better to design the entire GUI with their software, then upload it to the display.

Commands from the picaxe then reference the objects you created and look like

hserout 0, ("j2.val=",#VARIABLE,$FF, $FF, $FF) 'Set Gauge

At 115200 using hserial, I'm able to refresh the values on screen at 50Hz :cool:
It seems to pick up a 3.3V level serial signal fine too
 

johnlong

Senior Member
Hi All
Can the unit be used with any pin on the 40x2 ie serout B.1 serin B.0 or does it require the use of dedicated pins such as serin (pin6) hserin, hserout
regards
john
 

eggdweather

Senior Member
As long as it gets serial data it will operate correctly and the default baud rate is low, I don't expect any problems. I use one too.
 

lewisg

Senior Member
The product description on Amazon is a work of art;

"Nextion is a Seamless Human Machine Interface solution that provides a control and visualisation interface between a human and a process, machine, application or appliance. It is the best solution to replace the traditional LCD and LED Nixie tube.
This solution includes hardware part - a series of TFT boards and software part - Nextion editor. Nextion TFT board uses only one serial port to do communicating. Let you get rid of the wiring trouble. We notice that most engineers spend much time in application development but get unpleasant results. In this situation, Nextion editor has mass components such as button, text, progress bar, slider, instrument panel etc. to enrich your interface design. And the drag-and-drop function ensures that you spend less time in programming, which will reduce your 99% development workloads. With the help of this WYSIWYG editor, GUI designing is a piece of cake."


Looks like a neat device. I hope anyone here working with it posts examples and links! I can't wait to "reduce my 99% workloads" while avoiding "unpleasant results" when replacing my nixie tubes.
 

eggdweather

Senior Member
it's worth having a look at their development tool, you design your screen and objects, say a dial to control a variable and then upload the final result to the display via serial, then call the e.g, dial with the data value to be displayed, it does the rest. There are a few YouTube videos demonstrating the display.
 

cachomachine

Senior Member
How do you program the display using the Nextion editor to tell the Picaxe that a particular button has been pressed or released?
 

eggdweather

Senior Member
You draw your screen and download that to the Nextion. Then say your screen has a button at drawn at some location, and that location is pressed, then the Nextion sends the data item for a touch event to the PICAXE, e.g:
0X67++ TouchCoordinate_X_MSByte+TouchCoordinate_X_LSByte+TouchCoordinate_Y_MSByte+TouchCoordinate_Y_LSByte+TouchEvent_State+End_Sequence 0x01 means pressed 0x00 means no press

So the display will send to the PICAXE when pressed at the location (x,y) of 150,100 the data bytes in this order:

0x67 0x00 0x96 0x00 0x64 0x01 0xFF 0xFF 0xFF

Which means:

0x67 - screen was pressed
0x00 - MSB of x location is zero because 150 fits in one byte
0x96 - LSB is 150 the x location of the press
0x00 - MSB of y location is zero because 100 fits in one byte
0x64 - LSB is 100 the y location of the press
0x01 - it was pressed
0xFF
0xFF
0xFF - end of event marker

All that means a touch event occurred at coordinate 150,100 and the screen was pressed.

Your PICAXE then needs to read the sequence and act on the various messages sent by the screen. SO you'd need to know that 150,100 was say button A that means Up or whatever then programme the PCIAXE to do that command, say speed up a motor or whatever.

The Nextion does not need to know what the screen press at that location over a superimposed graphic of a button means if that makes sense.

When you design your screen you can also call a button a logical name say 'Button 2' and if it was drawn on 'Page-0' and the button was pressed, the screen will return (Check documentation) 0x65 Page0 Button-2 Pressed EndSequence or:

0x65 0x00 0x02 0x01 0xFF 0xFF 0xFF
 
Last edited:

cachomachine

Senior Member
Thanks eggdwewather, I tought that you could write some user code in the touch press event and in the touch release event of the Nextion editor for a particular button.
 

eggdweather

Senior Member
If you took a display new out of the box and switched on and pressed the screen where I did in the example it would respond with the sequence above. There is no programming in the next ion editor all the programming is done in the PICAXE environment.
 

cachomachine

Senior Member
HELP!
I do not seem to have any response from the nextion serial port nor does it respond to a simple command ei:draw 0, 0, 100, 100, RED
I start with a blank nexion display, connect it to the Picaxe editor serial terminal, the only time i receive something from the display is when i power it ON: [00][00][00][FF][FF][FF][88][FF][FF][FF]
If i put a command in the transmit buffer ei: draw 0, 0, 100, 100, RED, nothing happens, the display stay blank(all white)
Touching and releasing the display does no returns any action in the receive buffer.
What did I miss?

Edit:I am connected with USB-serial CH340 at 9600 baud and the display programs correctly with the Nextion editor.
 
Last edited:

eggdweather

Senior Member
What PICAXE serial command at you using, I suspect a polarity problem. Try prefixing speed with an N and then T to see if that solves the problem.
serout 7,N9600,(b1) ; transmit values to serial LCD
or
serout 7,T9600,(b1) ; transmit value to serial LCD

It's odd because the start-up sequence from the display looks about right.

And make sure your PICAXE is running at 8Mhz so that it can send and receive at 9600buad
 

cachomachine

Senior Member
This is the prog i use using a 14M2
Setfreq M8
Let dirsb=%00001000
main:pause 1000
Serout b.3, T9600_8, ( "draw 0, 0, 100, 100, red") ; draw a red rectangle
Pause 1000
Goto main
I am simply using the Picaxe serial terminal to receive and send commands when the display is directly connected to the ch340.
I have tried both T and N 9600
 

eggdweather

Senior Member
Have you tried sending the command string using a simple serial emulator like Putty, so you would type the command line and send the data to the screen. Likewise it should receive the start-up text.

Other things to try is the command 'cls RED' it sounds like a communication problem between the PC and screen, check TX-RX and RX-TX.

Try resetting the screen after connections have been made, then send the command.

Did the Nextion editor work OK with the screen?
 

cachomachine

Senior Member
After many attempts to communicate without success between a Picaxe 14M2 and a basic 3.5 inch Nextion (NX4832T035_011) display, I still need help!
A simple command like rest (Reset Nextion device) is not executed and no parameters are returned from the Nexion device.
I have tried serout b.2, n9600_8, ("rest")
And serout b.2, t9600_8, ("rest"), no luck
I have tried to connect the display through a CH340 USB/TTL adapter and sending commands with the PICAXE Editor’s terminal set at 9600 no parity 8 bits 1 stop, still no luck.
The only way I can have the display to accept commands and to return parameters is to use the Nextion editor in debug mode connected to the same CH340 USB/TTL adapter and to choose to send the command to the Nextion device instead the current simulator.
Can someone help PLEASE!
 

MartinM57

Moderator
Mine is in the post from Itead :)

Are you sending the 3 0xFF that seem to have to follow each command (not got to grips with it all yet - only reading up and playing in the editor so far). I'm planning to use a CH340 as well.
 

hippy

Technical Support
Staff member
If the display can be controlled by the Nextion editor but not by the PICAXE Terminal it suggests the Terminal is not sending what the display is expecting; if the baud rate and settings are correct it may be that some specific command terminator is required which is not being sent.

I am not familiar with your display or its protocol but example code and comments found via Google suggests a terminator of three 0xFF ($FF) bytes is required -

http://support.iteadstudio.com/support/discussions/topics/1000063274

I don't know if that's correct but, if they are required, then unless you are sending those via the terminal it seems unlikely the display will act on what has been sent.

Do you have a link to any document which describes what the serial protocol is for the display ?

Added: eggdweather provided what seems to be an appropriate link in Post #4 ...

http://wiki.iteadstudio.com/Nextion_Instruction_Set

That says; Note: 1. The instruction is end with three bytes "0xff 0xff 0xff"

So it would seem to be, to send a reset command from the PICAXE Terminal, select Transmit Mode: Raw, enter the following including the double quotes and commas, then press Send -

"rest", $FF, $FF, $FF

The following should turn the screen red -

"cls RED", $FF, $FF, $FF

Extra Added: Cross-posted with MartinM57's post above mine.
 
Last edited:

cachomachine

Senior Member
You are both right, the 3 $FF are required for any command.
One precision, one must use T9600_8 and not N9600_8
Thanks to everybody for the help.
 

hippy

Technical Support
Staff member
Looking at the link, it seems colours have a 16-bit value, 5-bit red, 6-bit green, 5-bit blue -

% rrrr rggg gggb bbbb

So, if controlling the display works through the PICAXE Terminal, I would try this to get the display cycling through some colours ...

Code:
#Picaxe 14M2

Symbol TX      = B.3
Symbol TX_BAUD = T9600_8

High TX
SetFreq M8
Pause 2000
SerOut TX, TX_BAUD, ( "rest", $FF, $FF, $FF )
Pause 2000
Do
  For b10 = 0 To 1
    For b11 = 0 To 1
      For b12 = 0 To 1
        w0 = b10 * $F800 
        w0 = b11 * $07E0 + w0
        w0 = b12 * $001F + w0
        SerOut TX, TX_BAUD, ( "cls", " ", #w0, $FF, $FF, $FF )
        Pause 2000
      Next
    Next
  Next
Loop
 

eggdweather

Senior Member
Yes the display uses rgb565 colour the same as a BMP (bit map image). I think the PICAXE editor like most cannot send binary data e.g. 0xFF. Hippy's code above should work for you.
 

hippy

Technical Support
Staff member
Excellent news. I'm quite liking these displays and the smaller ones aren't all that expensive.

Next thing is to push the PICAXE operating speed up as that will be useful later. Change SETFREQ M8 to M32, T9600_8 to T9600_32, PAUSE 2000 to 8000. Check that still works as it previously did.

With screen control under your belt the next milestone is reading touches or button pushes back.

The big question is whether the serial timing from the display is conveniently SERIN compatible or if HSERIN background receive will have to be used.
 

MartinM57

Moderator
...and speed up the somewhat pedestrian baudrate from 9600 to something like 57600 (or even 115200 if the PICAXE can do it - I've lost track of the tricks to get the maximum rate)
...to get everything to go a bit snappier
 

cachomachine

Senior Member
Hippy
Pushing speed to M32 works as well!
SERIN pushed at T9600_32 also still works!
Should not be to difficult to read touches or button pushes back.
Will let you know if it works when i can fine some time.
 

cachomachine

Senior Member
Reading is easy,
first, you create a button or simply a text field in the Nextion editor
You need to tick the send component ID case in the touch release event of that text field.
The display returns 7 bytes, 0x65,(means a push)0x00,(page 0)0x01(button ID1),0x00(not sure about that one), 0xFF,0xFF,0XFF
To change the value of a text string, the the Nextion debug, you type t1.txt="Moon"
I have tried to find the right syntax in Picaxe basic, i tried Serout b.4, T9600_32, ("t2.txt="Moon"",$FF,$FF,$FF) syntax error
Serout b.4, T9600_32, ("t2.txt=""Moon""",$FF,$FF,$FF) syntax error
what is the correct syntax?
 

AllyCat

Senior Member
Hi,

The complier doesn't know how to handle the "" or the """ .

The easiest method is probably to replace the required " with its ASCII value. i.e. $22 or 34 (decimal) . So the following should work:

Serout b.4, T9600_32, ("t2.txt=",34,"Moon",34,$FF,$FF,$FF)

Cheers, Alan.
 

cachomachine

Senior Member
It does work, thanks but why should it be so complicated!
How can someone like me remember that.
i guess i am too hold
 

hippy

Technical Support
Staff member
With PE6 it is possible to give the double-quotes character a name which can make it easier to use ...

Code:
Symbol QUOTES  = "\"" ; = Double Quote, Backslash, Double Quote, Double Quote

SerOut B.4, T9600_32, ( "t2.txt=", QUOTES, "Moon", QUOTES, $FF,$FF,$FF )
 

AllyCat

Senior Member
Hi,

why should it be so complicated!
It's always a (potential) issue with "non-printing" (e.g. TAB) or "control" characters (e.g. "newline", CR,LF) or where the characters have a special function within the "editor" (e.g. the double-quotes). Typical solutions are to use an "escape" character (e.g. hippy's \ ) or to repeat the character, but these are "language dependent".

Since an ASCII character table is included (for example under "Help" in PE5), then using the explicit ASCII value is probably the easiest solution, but you can always use symbols if you wish, e.g. SYMBOL DOUBLE_QUOTES = 34 : SYMBOL SINGLE_QUOTE = 39 : SYMBOL COLON = 58 etc..

However, as WA55 recently noted, to enter each "hard space" in PEBBLE (which employs JAVA), it's necessary to write &nbsp - now that (IMHO) is complicated. ;)

Cheers, Alan.
 
Last edited:

cachomachine

Senior Member
Another nextion problem
I am trying to draw a circle using picaxe variables
This instruction works
Serout nextion_rxd, nextion_baud_rate, ("cir 100,100,100,RED",$FF,$FF,$FF)
This one also works as red is 63488 in nextion language
Serout nextion_rxd, nextion_baud_rate, ("cir 100,100,100,63488",$FF,$FF,$FF)
but this does not even if it passes picaxe syntax
w0=63488
Serout nextion_rxd, nextion_baud_rate, ("cir 100,100,100",#b0,#b1,$FF,$FF,$FF)
or
Serout nextion_rxd, nextion_baud_rate, ("cir 100,100,100"#w0,$FF,$FF,$FF)

Can anybody help.
 

hippy

Technical Support
Staff member
Serout nextion_rxd, nextion_baud_rate, ("cir 100,100,100,63488",$FF,$FF,$FF)

and

w0=63488
Serout nextion_rxd, nextion_baud_rate, ("cir 100,100,100,",#w0,$FF,$FF,$FF)

Should both work the same. Note that comma after the last 100 and before the closing double quote. Without that you will be sending 'cir 100,100,10063488'.

One way to ensure you don't miss those is to code with characters defined by SYMBOL ...

("cir", SPACE, "100", COMMA, "100", COMMA, "100", COMMA, #w0, $FF,$FF,$FF)

Or create #MACRO definitions so you can have -

Circle(100,100,100,w0)

#Macro circle(a,b,c,d)
...( "cir", SPACE, #a, COMMA, #b, COMMA, #c, COMMA, #d, $FF,$FF,$FF )
#EndMacro
 
Last edited:
Top