Anyone Used Nextion Displays?

MartinM57

Moderator
I think the order of b1 and b0 needs an experiment - I don't recall any document from Nextion that specifies the endian-ness of large integers. but it may exist.(*)

However, there is a comma missing in your last two commands, after the r value...
Serout nextion_rxd, nextion_baud_rate, ("cir 100,100,100,"#w0,$FF,$FF,$FF)

(*)Edit - yes, of course - all commands are text-based, so you need to send the text characters "63488" (but no quotes)...plus the missing comma
...and I don't know what's happened to PICAXE forum time, but I've just edited this post in about 47 minutes time :)
 
Last edited:

cachomachine

Senior Member
Once again, you are right again, the coma is required between the 100 and the last ".
now, i have another problem with the line command
w1=63488
Serout nextion_rxd, nextion_baud_rate, ("line 100,100,100,10,",#b2,#b3,$FF,$FF,$FF)
is works and draw a line but
b0=100
b1=10
w1=63488
Serout nextion_rxd, nextion_baud_rate, ("line 100,100,",#b0,#b1,#b2,#b3,$FF,$FF,$FF)
does not work
something still missing?
 

hippy

Senior Member
Post # 42; "Sending two bytes for a word value won't work when a textual value is expected". And you need to ensure those commas are everywhere they are needed. Possibly ...

Serout nextion_rxd, nextion_baud_rate,
("line 100,100,",#b0,",",#b1,",",#w1,$FF,$FF,$FF)

Adding spacing usually helps -
( "line " , "100" , "," , "100" , "," , #b0 , "," , #b1, "," , #w1 ,$FF,$FF,$FF)
 

grim_reaper

Senior Member
Adding spacing usually helps -
( "line " , "100" , "," , "100" , "," , #b0 , "," , #b1, "," , #w1 ,$FF,$FF,$FF)
Personally, I find that adding the character number for commas (and quotes when there's a lot of them) makes it easier to read, e.g.

("line ", "100" , $2C, "100", $2C, #b0, $2C, #b1, $2C, #w1, $FF, $FF, $FF)

Probably down to taste! I've used $2C here instead of 44, since you're putting numbers in for your actual data.
 

johnlong

Senior Member
Hi Ibenson
If you look on youtube Andreas Spiess does a couple of good videos on the nextion they are arduino oriantatated
but he does show you a lot about the nextion editor his first tutorial is #56 nextion display showing how to achive what
I think your after altering settings ect.
I myself managed to screw mine up (screen displays system error) dont how just good like that
But I think you will have better success than me. He also has an over veiw of the enhanced modle in video around the #90's
I do like the look of the display and will be getting a new one in the future to have another go with it and yes screw it up as well
have a look at the first 2 tutorials the best explinations I have found so far
regards
and a good new year to all the forum members lets hope for a more peaceful 2017
john
 

cachomachine

Senior Member
I can say that i am pretty well in control of a Nextion display now (with the help of the Picaxe forum and Itead studio forum)
@johnlong, i tink that you have corrupted you display system memory. Contact Itead studio forum for help, they have a way to reset your display.
 

johnlong

Senior Member
Thanks for that
have got a new (old) laptop things seem so much clearer when you dont
have a blue back drop to veiw from
so I will re download the nextion editor and have another try with it
regards
john
 

stan74

Senior Member
Looks a neat display,glad you got it working. Aren't the guys here fantastic! I've seen touch displays for RPi but they won't work with picaxe and other GLCD displays with a pre-programmed pic interface are a bit expensive. I'm thinking of getting one to use with both.
Please keep us informed as to how it's going.
 

cachomachine

Senior Member
IMGP4287.jpgIMGP4288.jpg
This is a project that i called ‘’ Do nothing useful l project ’’.
I wanted to demonstrate the strength of a Picaxe 14M2 connected to a 3.5 inch Nextion display.
My project consist of 2 homemade PCB.
The main PCB has a Picaxe 14M2 with his programming socket, a DS3231 real time clock, a CH340 USB to TTL serial adapter and a HC12 RF transmitter receiver.
The Satelite PCB only has a Picaxe 14M2, a RGB LED and a HC12 RF transmitter receiver.
The DS3231 real time clock provides , hour and temperature at the Picaxe to be displayed on the Nextion display.
The CH340 USB to TTL serial adapter is used to program the Nextion display during developpement.
The HC12 RF transmitter receiver pair is used to transfer over the air LED color data from the main to the satellite PCB. (Over 16 million possible colors)
The 14M2 is kept busy reading the real time clock and refreshing the year, month, day of the week hour, minutes,seconds and temperature display fields.
It is also communicating with the display reacting to any button press and navigating through
the 9 display pages.
He also updates the satellite PCB LED color chosen by the display buttons.
The Nextion program utilizes just about any function available (button, text field, numeric field, scrolling text field, picture, crop, waveform, slider, timer, variable)
Now i am looking for a usefull project using Nextion Display
 

stan74

Senior Member
Top work cachomachine, I'm getting one! I did my best ,with help here, to use a serial GLCD. £9 but for extra you get colour and don't need switches or knobs. Nice one sir. https://youtu.be/kL3c1wry9ok
PS Can you read Nextion screen ram?
 
Last edited:

johnlong

Senior Member
Curses Cachomachine
had put the nextion away while I try to learn how to use Eagle to design my intended board and figured
stick with the axe133. You have rekindled my intreast with the nextion lovely work
I do like your gosub FF deals nicely with typing all thoses $FF at the end of all the comands.
A peek at the nextion code would be of great intrest to me and I am sure others here on the forum
as the Chinglish it is writen in sometimes is unfathomal.
Had a quick look on the nextion forum yesterday and it seems I need to send either a blank tft to it or reload the demo file
tried reloading the demo didnt like that so will try the the blank file approach if that doesnt work more digging required
once again sterling work I think you may be spurring on others here to look into this product
regards
john
 

cachomachine

Senior Member
@stan74, I never tried to read the screen ram but one can read a text or number value(.val or .txt) with the Nextion command print.
@jonnlong, How do you program your display, the serial port or the SD card. I think that you have to use the SD card to restore your system memory.
 

cachomachine

Senior Member
I am trying to attach my Nextion code but it is 3.94 meg and probably too big for the forum
Is there another way to do it?
 

MartinM57

Moderator
I'm having good luck with a 5" version (not with a PICAXE unfortunately :()...multi-page, on screen numeric keypads to set time etc.

It forces you to think carefully about the overall design and how you split up the processing between the (PICAXE) and the display - for example, my uController doesn't know anything that's being done on the Nextion for time setting (ie selection of the setting page, user pressing the on-screen keys, including making sure the time is valid etc) until it gets, say, a "T1234" ascii string sent to it (to set the time on a connected DS3232(*) to 12:34). If the Nextion has the power to do all that, might as well use it!

The Nextion code capability makes you jump through hoops quite a lot to get things done, but it's OK if you persevere. I spent ages cussing that I couldn't put any comments in the code to explain the hoops to myself later (I found nothing in any documentation/forum)..but a line starting with two slashes i.e. // is a comment and is nicely colour coded as well

(*)-yes there is an onboard RTC on the Nextion but it's disappointingly inaccurate compared with a DS3232
 

techElder

Well-known member
There are size limits. Obviously, I don't know what they are.

However, break the file in a text editor and send both halves with instructions on combining them.
 

AllyCat

Senior Member
Hi,

I am trying to attach my Nextion code but it is 3.94 meg and probably too big for the forum
Is there another way to do it?
Try copying the code from PE5. ;)

Somewhere, there's a thread that lists all the various file size limits, but "Search" can't find it for me. :(

Cheers, Alan.
 

hippy

Senior Member
I am trying to attach my Nextion code but it is 3.94 meg and probably too big for the forum
Is there another way to do it?
What exactly is this code. Almost 4MB seems too big for anything which is useful to share with anyone unless it's an executable file of some sort.
 

lbenson

Senior Member
Well, this is too cool. Color me impressed.

Two days ago I hadn't read through this thread completely. Today I'm running a real picaxe (14M2) which is driving the Nextion simulator for a 2.4" touch OLED (which should arrive from Amazon tomorrow).

The task: update 14 variables with "-" / "+" tick up/down buttons. Here are 4 images of the OLED simulation.
oled1.jpg
The upper left image is of the initial screen with the first variable, "OATCoolMn" selected and its value (76) shown. The upper right image is after "+" is clicked twice (emulating two touch presses of the screen). The lower left image is after "NEXT" button is pressed to scroll through all the variables to the last one. The lower right image is after the "-" is pressed 3 times. "DONE" is not fully coded yet (additional pages will be involved).

The program puts the 14 variable names in a table, and the initial values in eeprom. Changes to the variables are saved back to eeprom so they will survive power cycling (but not reprogramming the picaxe (unless the "#no_data" directive is included)).

On the Nextion side, two things in particular need to be remembered: use the "Tools" menu option to initialize fonts (I created Arial 16 point and Arial Bold 32 point (for the "-" and "+")); and in coding the action for a button press (or release in this case), put in a simple output for the button. I used 'print "!0"' through 'print "!4"' for my 5 buttons. The picaxe program uses select case statements to decode which event ("!" means button release) and which object ("0" means button 0) has been selected.

On the picaxe side, I tested the code in the P6 simulator before programming the chip. "Transmit Buffer" in the serial terminal helped with initial debugging. After programming the 14M2, I connected my picaxe output to a usb/serial module and used putty to connect at 9600 baud. I manually entered the messages the Nextion should send to the picaxe ("!0", "!1", "!2", "!3", "!4") and debugged the picaxe output.

When I connected the picaxe input and output pins (B.1 and B.2) to my usb/serial adaptor and the Nextion simulator on the correct COMM port, I got no picaxe output on sertxd when I power-cycled. Hmmm. I've seen this puzzle before when connecting "True" resting-level serial to the picaxe--it is phantom powered over that pin. In the past I've put in a series resistor on that line, but I've forgotten what value. I'll dig it out, but for now, when power cycling, I disconnect the cable to B.2 and quickly plug it back in after powering on.
Code:
' 14Nextion.bas drives Nextion oled
#picaxe 14m2
'#terminal 76800 ' 32mHz
'#terminal 4800 ' 4mHz
'#terminal 9600 ' 8mHz
#terminal 19200 ' 16mHz

table 0,("OATCoolMn",0,"OATHeatMx",0,"OATSup1Mx",0,"OATSup2Mx",0,"TankFeedMn",0,"TankFeedMx",0,"TankReturnMn",0,"TankReturnMx",0,"YardFeedMn",0,"YardFeedMx",0,"YardReturnMn",0,"YardReturnMx",0,"AirZoneSetMn",0,"AirZoneSetMx",0,0)

data 1,(75,60,45,35,35,120,35,110,33,120,33,120,40,99)

'symbol pNextion = C.1
'symbol nextion_baud_rate  = T9600_32
'symbol nextion_baud_rate  = T9600_8
symbol nextion_baud_rate  = T9600_16
symbol pNextionOut = B.1  ' B.0
symbol pNextionIn  = B.2
'symbol nextion_baud_rate  = N4800 ' for simulation debugging
symbol ramAddrOffset = 28 ' offset in ram of variable table addresses
symbol ramValOffset = 27 ' offset in ram of variable values (+nVars)

symbol nvars  = b4
symbol tblptr = b5
symbol cnt    = b6
symbol ch     = b7
symbol val    = b8
symbol var    = b9
symbol ActionCode = b10
symbol ActionVal  = b11
symbol oldVal     = b12

'Setfreq M32
'Setfreq M8
Setfreq M16
pause 8000 ' once for M8, twice for M16
pause 8000
sertxd("14Nextion",cr,lf)
bptr = ramAddrOffset ' first ram byte
tblptr = 0   ' just used as a variable
@bptrinc = tblptr ' address of first variable name
do
  readtable tblptr,ch ; read value from table
  inc tblptr
  if ch = 0 then
    @bptrinc = tblptr ' save address of first byte of next variable
    readtable tblptr,ch ; check for final 0
  endif
loop while ch <> 0 and tblptr < 255

nvars = bptr - ramAddrOffset - 1
sertxd(#nvars," min/max variables",cr,lf)
bptr = ramAddrOffset+nvars ' beginning in ram of variable values
for cnt = 1 to nvars
  read cnt,val ' move values from eeprom
  @bptrinc = val
next cnt

bptr = ramAddrOffset ' value in ram of table address of first variable
for cnt = 1 to nvars
  peek bptr, tblptr
  inc bptr
  readtable tblptr,ch
  inc tblptr
  sertxd(#cnt," ")
  do until ch = 0
    sertxd(ch)
    readtable tblptr,ch
    inc tblptr
  loop
  read cnt,val ' value for variable
  sertxd(" ",#val,cr,lf)
next cnt

var = 1 ' dealing with first variable
gosub outputP3

main:
  do
    Serin pNextionIn,nextion_baud_rate,ActionCode,ActionVal
'    Serin C.1,nextion_baud_rate,ActionCode,ActionVal
    select Actioncode
      case "!"        ' button release
        select ActionVal
          case "0"    ' minus
                   val = val min 1 - 1     ' floor value of 0--don't underflow
                   Serout pNextionOut, nextion_baud_rate, ("t1.txt=",$22,#val,$22,$FF,$FF,$FF)
                   @bptr = val
          case "1"    ' plus
                   val = val max 254 + 1   ' max value of 255--don't overflow
                   Serout pNextionOut, nextion_baud_rate, ("t1.txt=",$22,#val,$22,$FF,$FF,$FF)
                   @bptr = val
          case "2"    ' prior variable
                   if val <> oldVal then
                     gosub updateVal
                   endif
                   var = var - 1 min 1
                   gosub outputP3
          case "3"    ' next variable
                   if val <> oldVal then
                     gosub updateVal
                   endif
                   var = var + 1 max nvars
                   gosub outputP3
          case "4"    ' done with this page
                   if val <> oldVal then
                     gosub updateVal
                   endif
        endselect
    endselect
  loop

outputText:
  readtable bptr, ch
  inc bptr
  do until ch = 0
'    sertxd(ch)
    Serout pNextionOut, nextion_baud_rate, (ch)
    readtable bptr,ch
    inc bptr
  loop
  return

outputP3:
  serout pNextionOut,nextion_baud_rate,("t0.txt=",$22) ' $22 is quote
  bptr = ramValOffset + var
  peek bptr, bptr ' address of first character in variable name
  gosub outputText
  Serout pNextionOut, nextion_baud_rate, ($22,$FF,$FF,$FF)
  bptr = var + ramValOffset + nvars ' location of value for this variable
  val = @bptr
  oldVal = val
  sertxd("Var",#var," = ",#val,cr,lf)
  Serout pNextionOut, nextion_baud_rate, ("t1.txt=",$22,#val,$22,$FF,$FF,$FF)
  return        

updateVal:
  sertxd("Var",#var," = ",#val,cr,lf)
  bptr = ramValOffset + nVars + var
  @bptr = val     ' update ram
  write var,val   ' update eeprom in case of power cycle
  return
Thanks to everyone here who contributed to making this easy for me. I understand the struggles of breaking trail, and appreciate those who persevered in their efforts.
 
Last edited:

techElder

Well-known member
ibenson, what happens if you want to change your background image on the Nextion? Do you have a front and a back "layer" to work with?
 

lbenson

Senior Member
Texas--that is my own background image. I don't know enough about the device or the programmer/simulator to know if there is a front and back layer. One of the Andreas Spiess youtube videos shows that you can create a slider object which has foreground and background images. The foreground image overlays the background image dynamically and proportionally as you move the slider.

Early days.
 

cachomachine

Senior Member
You need to have 2 images in your HMi file and send the command page0.pic=1 or page0.pic=0 to alternate between both images
 

johnlong

Senior Member
Hi
Ibenson
your back garden looks lovely the images the unit produces are top notch
very resonable priced as well
regards
john
 

lbenson

Senior Member
Texas,

Here, following the suggestion above from cachomachine, is background image changed based on user action.

heatcoolauto.jpg

When Radio Button"HEAT" is pressed, the winter image appears (left); when Radio Button "COOL" is pressed, the summer image appears; fall image for "AUTO".

They aren't real (grouped) radio buttons, so you have to turn off the other buttons. "Touch Release" code for the COOL button is:
Code:
r0.val=0
r1.val=0
r3.val=0
page1.pic=2
 

Attachments

Last edited:

techElder

Well-known member
That's neat.

Part of my question involves editing. If you want to now change the winter picture to a different one, does that somehow affect the visibility of the buttons that you have already placed? Or do you have to replace the buttons after you change the picture?
 

lbenson

Senior Member
I added a third background image for "AUTO". The buttons and other objects are unchanged by the replacement of the background image.

Note that this particular change is made without the involvement of the picaxe, though it could be done with a message to the picaxe and a command back:

page1.pic=2$FF$FF$FF

Or ... if by editing you mean coding up the screens in the Nextion editor, there also a change in the background image has no effect on the other objects.
 

techElder

Well-known member
Almost there, but not quite. Hate to be the pedantic type.

Adding a picture is different than changing a picture that is already there.

For instance, if you had a picture of a house with buttons at each window, and you uploaded the front view instead of the side view. What happens when you change the front view picture to the correct side view picture?
 

lbenson

Senior Member
If one is an engineer, either software or hardware, professional or hobbyist, being of the "pedantic type" is pretty much required.

The buttons are not part of the background image, they are separate objects, like objects in Visual Basic Windows applications. The images are not on your picaxe or other MCU, but are added to the simulator/project builder when you build your screens on your PC and are downloaded to the Nextion (preferably "right-sized" before they are added to the project). Button objects could be placed so that they cover the windows of the house, and could even have their own background images clipped from the original picture so that it all looked seamless (if you were careful, pedantic, etc.). There is not at present an option to make an object background transparent.

If you change the background image, the buttons will still be in the same place (x,y) in front of the new image. If you wanted buttons over the windows, the easiest way as I see it now would be to build a separate page, identical except for the new background image and buttons placed over the windows. On the other hand, the x and y positions of the button could be changed by the picaxe or MCU (or by code running on the Nextion) so that they were moved into position over the new image (if they were the right size).
 
Top