Anyone Used Nextion Displays?

lbenson

Senior Member
You'll be better off in the long run to treat the Nextion like any other display that you would use. Use it for a display and not for a processor.
...
Of course, IMHO and YMMV.
I agree, although incrementing and decrementing are trivial enough cases that handling them on the Nextion side would not be at all unreasonable.

I find that the part of my code handling interaction with the Nextion is processed a number of times a second--such that delays from the back and forth to the picaxe are not noticeable to the user. For other circumstances, that would be one of the areas where YMMV, and offloading processing to the Nextion could improve response. I have not thus far found that to be needed.
 

oracacle

Senior Member
My plan is to get the display to do the menial thing like value selection and handle menus. Hopefully that will make response times a bit faster and save code space on the picaxe.
With that in mind I maybe able to move this project from a 28X2 of the current version to a 20X2. Having this sort of interface also mean that less hardware pins are needed, which will hopefully mean that the final product can be smaller as well. If I can it down to the footprint of the display I will be very chuffed.
 

oracacle

Senior Member
I was rudely awoken by some builder making a racket after 3 hours of sleep. the plus side of this is that I have now found a little time to have a look at the data coming from the display.
Its a little scruffy, should work for a nearly full scratch pad - the last 4 address will need to be zero value
The code look for 4 zeros in succession, then assumes the first three addresses is information, then looks for 3 $FF in a row and assumes the next three address have data.
I have test in the simulator for about a dozen sets of data being sent and seem to work fine - the pause at the beginning of the read back routine need to be there to ensure that all data has been sent before reading starts, I'm sure there is a way to detect when serial input has stopped but I haven't looked hard enough yet

Rich (BB code):
#no_data
#no_table
'setfreq m16

symbol dis_in           = c.7
symbol dis_out          = c.6
symbol baud             = T9600
#terminal 9600
init:
      pause 1000
      hsersetup b9600_8, %00000001
      hserout 0, ("page ","1",$FF,$FF,$FF)
      'hserin 0, 4
      hserptr = 0
      'setintflags %00100000,%00100000

main:
      if hserptr <> 0 then gosub readback
      goto main
      
      
readback:
      high b.7
      pause 100
      
      let b0 = 0
      'find data in scratch pad
      do while b2 < 4
            get b0, b1
            if b1 = 0 then
                  inc b2
            else
                  b2 = 0
            end if
            inc b3
            inc b0
      loop
      b3 = b3 - 5                         'last address
      'now find instruction - first 2 
      'address 0-2 will always be instruction/data
      'Test values: $71,$06,$00,$00,$00,$ff,$ff,$ff,$66,$01,$ff,$ff,$ff - only two selections
      for b0 = 0 to 2
            get b0, b1
            sertxd (#b1,44)
      next b0
      'now look for next until address matches b3
      do while b0 < b3
            get b0, b1
            if b1 = $FF then
                  inc b2
            else
                  b2 = 0
            end if
            if b2 = 3 then                      'next start bit?
                  inc b0
                  for b4 = 0 to 2
                        get b0, b1
                        sertxd (#b1,44)
                        inc b0
                  let b2 = 0
                  next b4
            if b1 = $FF then                    'correct address if only 2 byte sent before stop
                  b0 = b0 - 2
            end if
            
            end if
            inc b0
      loop
      
      
      #rem
      for b0 = 0 to b3
            get b0, b1
            sertxd (#b1,44)
      next b0
      #endrem
      for b0 = 0 to b3
            put b0, 0
      next b0
      sertxd (13,10)
      b3 = 0
      b2 = 0
      hserptr = 0
      low b.7
      return
 
Last edited by a moderator:

johnlong

Senior Member
Hi Oracale
Would you clarifiy a point for me are you trying to alter the value of a variable on the Picaxe or are you reading sensors via the nextion (if so I assum you have the enhanced modle)
If just changing wanting to change values the following works
If you want to read sensor values via the nextion you can terminate all reads as such print "h0.val" print"XXXX" using the X's as a termination then you know that a termination has occured
Code:
symbol QT=34
'On the nextion side of things 4 hotspots
                              'Spot 1 print "A+" Spot 2 print "A-"
					'Spot 3 print "B+" spot 4 print "B-"
                              'code_c either as a touch or release



hsersetup   B9600_8, %0 'no need for background recieve here as selecting use %001 where you want the interupt
		do
hserin [60000,leave],0,2 'variable settings and operation selection			 
		if hserflag <>0 then : if hserptr < 2 then: pause 10 : endif :endif: get 0,b4:get 1,b5
		
		b4=b4-65 'converts ascii capitals to ABC to 0 1 2 ect for the ongosub			
			if b4<2 then
			on b4 gosub n0,n1
		endif 			
		gosub QTF
		gosub HP
		loop 		 			
		n0:'"A" 
			select case b5			
		case 43' Ascii + dec value
			b6= b6+1 max 100		
		case 45'Ascii - value
			b6= b6-1 min 0		
		end select		
			hserout 0, ("svt.txt=",QT,#b6) 			
		return
		n1:'"B"
		select case b5			
		case 43
			b7= b7+1 max 100		
		case 45
			b7= b7-1 min 0		
		end select		
			hserout 0, ("svt.txt=",QT,#b6) 			
		return
	QTF:
		hserout 0,(QT,$ff,$ff,$ff) 'command for nextion to exicute 
		return
HP:
		hserflag=0 'clear all flags and values for next read
		hserptr=0
		b4=0
		b5=0
		return			
				
	leave:
	run 1
	end
dont worry so much about the termination the nextion produces just egnore it
regards john
 
Last edited:

oracacle

Senior Member
The idea is to be able to receive multiple pieces of data from menus in a single transmission.
Having the screen deal with selection values when moving from page to page the data needs to be sent as well as the new page. Some pages also have more than one data point to send. So finding the stop bits shows the beginning of the next set of data. I will try and get more iron up in the next couple of days
 

oracacle

Senior Member
In the attached screen to values can be set, both these values are kept in range, increased and decreased by the Nextion. When the accept button is pressed both theses values are sent to the picaxe, the screen move to appropriate menu and send the new page number back to the picaxe meaning that 3 set of data is sent. The picaxe just now just has to put them into the correct variables which is why the page information is needed.
I have been using the get command, chose this it send the event that triggered the transmission 0X71 numeric value, 0X66 page ID, 0X65 touch event, 0X70 is sting in ASCII. This should allow thing to be identified if needs be.
so finding the stop values means that the byte after that is the type identifier followed by the information.
I am going to have to increase te number of zero to 5 as in some cases its possible for a zero value to be sent and miss identify the end of a data set.

so if I set that page to 2 mins 4 sec and press accept I will get back
0X71 0X02 0X00 0X00 0X00 0XFF 0XFF 0XFF 0XFF
0X71 0X04 0X00 0X00 0X00 0XFF 0XFF 0XFF 0XFF
0X66 0X02 0XFF 0XFF 0XFF 0XFF

which is:-
Value: 2
Value: 4
Page: 2

seeing as the order of receiving is known, the picaxe just uses get to move the values into their respective variables for later use and the code space that is something like + code for multiplex keypad:
(code from original project)

Code:
bulb0:
	if bulbsec < 1 then					'check for bulb duration
		let bulbsec = 1					'load defualt if nothing set
	end if
	
	serout screen, baud, (254,1)
	pause 30
	serout screen, baud, (254,128, "Bulb Duration:",254,144,":",254,192,"<Inc Min",254,204,"Inc Sec>",254,148,"<Dec Min",254,160,"Dec Sec>",254,212,"<",254,225,"Accept>")
	gosub updatebulbsec
	gosub updatebulbmin
	gosub bulbacti0

bulb:
	do
		gosub scancol
		on slct gosub incmin, decmin, bulbacti, incsec, decsec
		'debug
		pause 100						'debounce
		if slct = 5 then exit				'exit of accept selected.
	loop
	if bulberror = 1 then					'check for error flag
		let bulbsec = 1					'correct error if found
	end if
	goto timers
'***seconds***	
decsec:
	dec bulbsec
	if bulbsec > 59 and bulbmin > 0 then		'check for underflow, allow 0 second if min > 0
		let bulbsec = 59					'correct underflow
	else if bulbsec = 1 and bulbmin = 0 then		'check for underflow, dont allow 0 second if mins = 0
		let bulbsec = 59					'correct underflow
	end if
	gosub updatebulbsec					'update display
	return
	
incsec:
	inc bulbsec
	if bulbsec > 59 and bulbmin > 0 then		'check for overflow, allow 0 second if min > 0
		let bulbsec = 0					'correct for overflow
	else if bulbsec > 59 and bulbmin = 0 then		'check for overflow, dont allow 0 second if min = 0
		let bulbsec = 1					'correct overflow
	end if
	gosub updatebulbsec					'update display
	return
	
updatebulbsec:
	if bulbsec < 10 then
		serout screen, baud, (254,145,32,#bulbsec)
	else
		serout screen, baud, (254,145,#bulbsec)
	end if
	return
'***minutes***	
decmin:
	dec bulbmin
	if bulbmin > 99 then
		bulbmin = 99
	end if
	if bulbmin = 0 and bulbsec = 0 and bulberror = 0 then
		let bulberror = 1
	else
		let bulberror = 0
	end if
	gosub updatebulbmin					'update display
	return
	
incmin:
	inc bulbmin
	if bulbmin > 99 then
		let bulbmin = 0
	end if
	if bulbmin = 0 and bulbsec = 0 and bulberror = 0 then
		let bulberror = 1
	else
		let bulberror = 0
	end if
	gosub updatebulbmin					'update display
	return
	
updatebulbmin:
	if bulberror = 0 then					'if no error then update normally
		if bulbmin < 10 then
			serout screen, baud, (254,142,32,#bulbmin)
		else
			serout screen, baud, (254,142,#bulbmin)
		end if
	else								'else if error, update dispaly with default seconds - does not modify bulbsec variable until accpeted
		if bulbmin < 10 then
			serout screen, baud, (254,142,32,#bulbmin,254,145," 1")
		else
			serout screen, baud, (254,142,#bulbmin,254,145," 1")
		end if
	end if
	return
to something like the in the my previous post. further to this, each menu will need something similar to original project for every display (granted without having to set the menu up). But having the Nextion deal with as much as possible mean that the code in the my previous post could be re-used for every menu as a sub-procedure with a few little tweaks.

The may well need to be checks when moving onto each page to ensure that the correct value is displayed, but all being square it shouldn't be needed.
I am going to do some more work on things and hopefully gain a deeper insight into dealing with issue that may arise.
 

Attachments

johnlong

Senior Member
Hi Oracle
Still not fully sure what you want nextion to do ann what you want the picaxe to do
The nextion is grapicalUSERinterface machine
Are you trying to use it as a master for the picaxe
Are you concerned about loss of data when moving between pages if so look at post #108 and change where ive
used nvt=nvt to ref (your variable) making sure you have chosen the globle option for the nextion variable
that will alow it to be used across pages and page refreshes
Every time you open up a page in the nextion you are resorting back to the default page you created in
the editor
 
Last edited:

oracacle

Senior Member
I am using the nextion as the full user interface - not just for graphics.
It will deal with increasing and decreasing values and checking for overflows/underflows - something we all have done - that information is then sent to the PICAXE.
this will be done on nearly every page which currently stand at 11 saving the code space of all those if statements

this is in the pre-initialisation of one page
Code:
if(sec_var.val<1)
{
  sec_var.val=1
}
mins.val=mins_var.val
sec.val=sec_var.val
this sets the initial values from a global variable

this is used to increase the seconds and check for overflow
Code:
sec_var.val=sec_var.val+1
if(sec_var.val>59)
{
  if(mins_var.val==0)
  {
    sec_var.val=1
  }else
  {
    sec_var.val=0
  }
}
sec.val=sec_var.val
these next two is where the picaxe comes in:
when accept is pressed all the information is sent the picaxe
Code:
get mins_var.val
get sec_var.val
page Timers
the 2 variables will then be used by the picaxe to set minutes and seconds

each page has this in post-initialisation
Code:
sendme
which sends the page number the picaxe

so to increase the seconds value the picaxe has done nothing but wait for information and because it should know what page its on it will know where to put the information its received. Hopefully plenty of PICAXE code space will be saved, among a couple other advantages.
 

johnlong

Senior Member
Hi Oracle
can you not use the touch release events
in the touched event print "ZZ" as an identifier to tell the picaxe what to do with them open page/ variable change coming
your if statement
on the release event va0.val=nst.txt ect
print nst,txt
I just found if you define what you want to enact apon is easier than interperating their messages
using ascii as an interpruter between the two systems
regards
john
 

oracacle

Senior Member
https://www.youtube.com/watch?v=TeRSp4C7_v0&feature=youtu.be

Code:
#no_data
#no_table
'setfreq m16

symbol config0	= w0						'variable used for configuring comparitor
	symbol reserved0		= b0					'reserved byte for tempory bits
	symbol reserved1		= b1
'symbol		= w1
	symbol sys_flags		= b2
		symbol lite		= bit16
		symbol delay_flag	= bit17
		symbol strobe_flag= bit18
symbol tempword0			= w2
	symbol tempbyte0		= b4
	symbol tempbyte1		= b5
	symbol scratch_val	= b6
	symbol last_scratch	= b7
	symbol loopcount1		= b8
	symbol page_number	= b9
	symbol pointer		= b10
	symbol shutter_delay	= b11
symbol strobe_dur			= w6
	symbol strobe_lsb		= b12
	symbol strobe_msb		= b13

	symbol strobes		= b14
	symbol acti_sens		= b15
	
	symbol acti_trig		= b16
	symbol inverted		= b17
	
	symbol reserved		= b18
	symbol threshhold	= b19


symbol dis_in     	= c.7
symbol dis_out    	= c.6
symbol baud 		= T9600
#terminal 9600
init:
	pause 1000
	hsersetup b9600_8, %00000001
	hserout 0, ("page ","1",$FF,$FF,$FF)
	hserptr = 0
	bptr = 56
main:
	if hserptr <> 0 then gosub readback
	'first data will be page 1 0x66 0x01
	'timer page = 0x66 0x02
	'shutter delay = 0x66 0x03
	'page can will 2 variables when accept pressed followed by page 0x02
	'page number can be considered page number -1 due to first page being diplayed during startup
	goto main
	
selection:
	bptr = 56
	if @bptr = 60 then
		page_number = 60
	end if
	select case page_number
		case 1
			'page 1 will only send light flag
			'both start as zero - light off
			bptr = 56
			if @bptr = 1 then
				high b.6
				lite = 1
			else
				low b.6
				lite = 0
			end if
			sertxd (#lite,44,13,10)	
		case 3
			'page 3 send flag then shutter delay
			bptr = 56
			if @bptr = 1 then
				delay_flag = 1
			else
				delay_flag = 0
			end if
			'data is only 1 byte
			bptr = bptr + 2
			shutter_delay = @bptr
			sertxd (#sys_flags,44,#shutter_delay,13,10)
		case 4
			'page 4 sends strobe duration (word) strobes (byte) flag
			bptr = 56
			strobe_lsb = @bptrinc
			strobe_msb = @bptrinc
			strobes = @bptr			
			sertxd (#strobes,44,#strobe_dur,13,10)
		case 10
			bptr = 56
			acti_sens = @bptr
			bptr = bptr + 2
			acti_trig = bptr
			bptr = bptr + 2
			inverted = bptr
			sertxd (#acti_sens,44,#acti_trig,44,#inverted,13,10)
		case 60
			sertxd ("calib",13,10)
			do while hserptr = 0
				readadc 0, b18
				hserout 0, ("sensor1.val=",#b18,$FF,$FF,$FF)
				let tempword0 = b18 *10 *4 /100
				'value over 100 causes error code and stopping of display update due to b4 and b5 not meeting requirements
				if tempword0> 100 then
					tempword0 = 100
				end if
				let b18 = tempword0
				hserout 0, ("bar1.val=",#b18,$FF,$FF,$FF)
				
				readadc 1, b18
				hserout 0, ("sensor2.val=",#b18,$FF,$FF,$FF)
				let tempword0 = b18 *10 *4 /100
				if tempword0 > 100 then
					tempword0 = 100
				end if
				let b18 = tempword0
				hserout 0, ("bar2.val=",#b18,$FF,$FF,$FF)
			loop
		case 11
			bptr = 56
			threshhold = @bptr
			sertxd (#threshhold,13,10)	
	endselect
	return

readback:
	high b.7
	pause 100
	
	let scratch_val = 0
	'find data in scratch pad
	do while loopcount1 < 5
		get scratch_val, tempbyte0
		if tempbyte0 = $00 then
			inc loopcount1
		else
			loopcount1 = 0
		end if
		inc scratch_val
	loop
	
	last_scratch = scratch_val - 6					'last address
	'now find instruction - first 2 
	'address 0-2 will always be instruction/data
	'Test values: $71,$06,$00,$00,$00,$ff,$ff,$ff,$66,$01,$ff,$ff,$ff - only two selections
	'0x71 - numeric data lsb first sends long work but only interested in word - ie first 2 data points
	'LSB first
	bptr = 56
	for scratch_val = 0 to 2
		'get scratch_val, tempbyte0
		'sertxd (#tempbyte0,44)
		gosub data_check
	next scratch_val
	'inc scratch_val
	loopcount1 = 0
	'now look for next until address matches last_scratch
	do while scratch_val < last_scratch
		get scratch_val, tempbyte0
		if tempbyte0 = $FF then
			inc loopcount1
		else
			loopcount1 = 0
		end if
		if loopcount1 = 3 then				'next start bit?
			inc scratch_val
			for tempbyte1 = 0 to 2
				'get scratch_val, tempbyte0
				'sertxd (#tempbyte0,44)
				gosub data_check
				'inc scratch_val
			next tempbyte1
			get scratch_val, tempbyte0
			loopcount1 = 0
				if tempbyte0 = $FF then			'correct address if only 2 byte sent before stop
				scratch_val = scratch_val - 1
			end if
		'sertxd (13,10)
		end if
		inc scratch_val
	loop
	bptr = 56
	sertxd ("Page: ",#page_number,13,10,"Data 1: ",#@bptrinc,44,#@bptrinc,13,10,"Data 2: ",#@bptrinc,44,#@bptrinc,13,10,"Data 3: ",#@bptrinc,44,#@bptrinc,13,10)
	#rem
	for scratch_val = 0 to 20
		get scratch_val, tempbyte0
		sertxd (#tempbyte0,44)
	next scratch_val
	#endrem
	for scratch_val = 0 to last_scratch
		put scratch_val, 0
	next scratch_val
	sertxd (13,10)
	last_scratch = 0
	loopcount1 = 0
	hserptr = 0
	gosub selection
	low b.7
	return
	
data_check:
	get scratch_val, tempbyte0
	if tempbyte0 = $66 then
		inc scratch_val
		get scratch_val, tempbyte0
		let page_number = tempbyte0
	else if tempbyte0 = $71 then
		inc scratch_val
		get scratch_val, @bptrinc
		inc scratch_val
		get scratch_val, @bptrinc
	end if
	inc scratch_val
	return
this code puts the information from 6 different menu into their respective variables. the page number is now transmitted when leaving a page instead of opening a page. A after initialisation the only output from the picaxe is in the calibrate screen where it adjusts the bars. All overflow/underflow is dealt with on the nextion. I sure there is some space to be saved in the code, but that will come later

identifying things has been one of the easier thing to do - while the code currently only looks for either a page or a numerical value at the moment, there is no reason why is can't deal with other stuff as well
 

stan74

Senior Member
I bought a nextion and loaded the demo onto sim ok and it worked. That's as far as I got. I never got anywhere with the win dev and couldn't send print commands from picaxe or other systems so just got a driver and use it as serial glcd in another system. Much faster but serial is serial. Least I'm in command of it not a complicated interface. Glad people have got it working.
 

johnlong

Senior Member
Hi Oricale
If you look on you tube royal newberry does a video on
moving values and text between pages
He places in the touch event box of say page0 for a component
n0.val=page1.n0.val
vscope global for each page getting the value from page 1 and displaying it on 0
regerds
john
 

oracacle

Senior Member
Things are starting to come along a bit now.
The next question I have is more about cheating than anything else.
There is s section where I need to run @64mhz and setting the hserout to b9600_64 yield no results, ie the screen do not update. Is there anyway to update the display at those speeds.
I was thinking that maybe setting hserout to b1200_64 might do the trick but it doesn't work.
If there is not way of making it work I do have a work around.
 

MartinM57

Moderator
(FYI and OT...I'm running my Nextion with a twelve page app at 115200 for receive and transmit (not from/to a PICAXE) and it all works very snappily :))
 

lbenson

Senior Member
There is a section where I need to run @64mhz and setting the hserout to b9600_64 yield no results
Just to check your wiring and hsersetup second parameter, does it work at 4mHz and b9600_4?

If so, in your 64mHz section, can you drop back to 4mHz (or the highest speed that you find works) just for the purpose of updating the Nextion?
 

MartinM57

Moderator
As "Patrick Martin" says, if you are asking (aka polling) the Nextion by doing a "get tch2" from the MCU (is it a PICAXE?) to get the x co-ordinate of the last touch position, then you will get a 0x71 headed reply with a four byte little endian value representing x

If you want to poll for the y co-ordinate of the last touch then it's a "get tch3" command and you will get a 0x71 headed reply with a four byte little endian value representing y

0x67 messages from the Nextion are the Nextion sending out the last touch event asynchronously i.e they will just arrive at the MCU when the screen is touched/released. They always come in pairs in my experience, with a 1 as the 5th data byte for the "press" and a 0 as the "release". However, just to be different the x and y co-ordinates of a 0x67 message are two byte little endian :)

Both these can be easily seen in the Nextion simulator:
- blank screen, no nextion code in it at all, click on screen then enter "get tch2" or "get tch3" in the "Instruction Input Area" and see the returned 0x71 message
- bank screen, "sendxy=1" in its Preinitialize event, click on screen and see the returned 0x67 messages
 

stan74

Senior Member
I got it working. I had to wait for recieved 0x71. I haven't used the simulator. I don't want to use nextion logic or code.
I used tch0 for x and tch1 for y. You can drag the pen to change x y.
Not picaxe code-
GLCDSendOpInstruction_Nextion( "get", "tch1" ) ;y
do
HSerReceive (myDummyByteIn)
loop until myDummyByteIn=0x71

HSerReceive (r2)
HSerReceive (r3)
HSerReceive (r4)
HSerReceive (r5)
HSerReceive (myDummyByteIn) ;0xff
HSerReceive (myDummyByteIn) ;0xff
HSerReceive (myDummyByteIn) ;0xff
ypress=r2+256*r3 : ypress=ypress+65536*r4 : ypress=ypress+16777216*r5
 

stan74

Senior Member
The nextion system is a learning curve. Controlling the display with a mcu is more learning. Will use the simulator asap.
Getting the touch data is not clear.
The code I posted is blocking ie if no 0x71 recieved it loops. Should have been-
dim touchdata(8)
GLCDSendOpInstruction_Nextion( "get", "tch0" ) ;x
repeat 4
HSerReceive (touchdata(1))
if touchdata(1) = 0x71 then
for temp = 2 to 8
HSerReceive (touchdata(temp))
next temp
if touchdata(6) = 255 & touchdata(7) =255 & touchdata(8) = 255 then
[byte]myWordX = touchdata(2) : myWordX_H = touchdata(3)
end if
exit repeat
end if
end Repeat
This has 4 tries for receiving 0x71 x data, then if the last 3 bytes are 255 it passes x touch co-ords.
Same for y touch.
 

oracacle

Senior Member
I have only been working with my project on and off over time, life and other things have been getting the way a bit.
however you don't have to wait around for things if your using hardware serial. you could use an interrupt on serial receive or a simple state of
Code:
if hserptr <> then gosub do_stuff
you can also receive everything and start reading the information before transmission has stopped. The following code is called from the above.

Code:
readback:
	high b.7
	pause 100

	let scratch_val = 0
	last_scratch = hserptr
	bptr = 56
		gosub data_check
	loopcount1 = 0
	do while scratch_val < hserptr
		get scratch_val, tempbyte0
		if tempbyte0 = $FF then
			inc loopcount1
		else
			loopcount1 = 0
		end if
		if loopcount1 = 3 then				'next start bit?
			inc scratch_val
			for tempbyte1 = 0 to 2
				gosub data_check
			next tempbyte1
			get scratch_val, tempbyte0
			loopcount1 = 0
				if tempbyte0 = $FF then			'correct address if only 2 byte sent before stop
				scratch_val = scratch_val - 1
			end if
		end if
		inc scratch_val
	loop
	bptr = 56
	sertxd ("Page: ",#page_number,13,10,"Data 1: ",#@bptrinc,44,#@bptrinc,13,10,"Data 2: ",#@bptrinc,44,#@bptrinc,13,10,"Data 3: ",#@bptrinc,44,#@bptrinc,13,10,"Data 4: ",#@bptrinc,44,#@bptrinc,13,10)
	last_scratch = 0
	loopcount1 = 0
	hserptr = 0
	gosub selection
	low b.7
	return
	
data_check:
	get scratch_val, tempbyte0
	if tempbyte0 = $66 then			'page number
		inc scratch_val
		get scratch_val, tempbyte0
		let page_number = tempbyte0
	else if tempbyte0 = $71 then		'other data
		inc scratch_val
		get scratch_val, @bptrinc
		inc scratch_val
		get scratch_val, @bptrinc
	else if tempbyte0 = $65 then		'button event - followed by page, item and event type
		inc scratch_val
		get scratch_val, page_number	'page number
		inc scratch_val
		get scratch_val, @bptrinc	'item number
		inc scratch_val
		get scratch_val, @bptrinc	'event type- release is 0 press is 1
	else if tempbyte0 = $02 then  		'invalid object
	end if
	inc scratch_val
	return

this code currently only reads back 4 pieces of information through sertxd. the data_check procedure can be updated to check for whatever you need, this only reflects what I needed at the time of writing.
The whole programme uses variable above the normal system variables as a receive buffer, once the above has completed a case event will find what page sent the information and put the received information into the correct variables. As a side note I found it easier to always send the page that the Nextion is on as my setup actually quite heavily uses the displays code and abilities to move through menus, do basic maths and selections. So instead of the picaxe waiting for an input and then doing a simple x+1 the nextion does. yes this mean the picaxe can either be doing something else, or is waiting for the nextion. one of the big upside for me is that this save a suprising amount of code space. This is not just due to having to do all the maths, but it does not have to draw the menus either. have in some cases have button appear and disappear depending on what has been displayed. sliders to select values and in one case a press and hold so that you don't have to constantly tap to move large amounts.

Due to what can be done in the display itself I would strongly advise anyone to use its abilities, there is so much that can be achieved very easily.
 

stan74

Senior Member
They are good in that complicated plot and line and even a guage with sin cos is done for you. using picaxe this is handy but any pic (328p is now a pic) can benefit from nice graphics and easy touch events.
There's 4gig of memory for storing your own images.
There's disappointments for me in that there's no moveable images, so games are out.
I use 115200 baud and a basic to asm compier and tried printing and erasing a char in forground background colour and it's slow so ploting a multicoloured sprite would be too slow. Shame since it uses an arm.
It's a while since I used picaxe basic but if I find info anyone wants I'll post.
ps I got it down to a sub,saved 20 bytes and can use get, tch 0,1,2,3. maybe useful
dim touchdata(8) , temp , xy_touchdata_ok as byte
dim xpress , ypress as word

wait 1 s
GLCDCLS TFT_Blue
;---------
do
;-----
GLCDSendOpInstruction_Nextion( "get", "tch2" ) ;x
get_touch_xy
if xy_touchdata_ok = 1 Then
[byte]xpress = touchdata(2) : xpress_H = touchdata(3)
end if
;-----
GLCDSendOpInstruction_Nextion( "get", "tch3" ) ;y
get_touch_xy
if xy_touchdata_ok = 1 Then
[byte]ypress = touchdata(2) : ypress_H = touchdata(3)
end if
;-----
GLCDPrint_Nextion (0,0,str(xpress)+" ", TFT_white )
GLCDPrint_Nextion (120,0,str(ypress)+" ", TFT_white )

loop
;---------------
sub get_touch_xy
repeat 4 ;try 4 times
HSerReceive (touchdata(1))
if touchdata(1) = 0x71 then
for temp = 2 to 8 ; it's 0x71 so get next 7 bytes
HSerReceive (touchdata(temp))
next temp
if touchdata(6) = 255 & touchdata(7) =255 & touchdata(8) = 255 then
xy_touchdata_ok=1 ;1st byte=0x71 and bytes 6,7,8=255...data ok
else
xy_touchdata_ok=0 ;error
end if
exit repeat
end if
end Repeat
end sub
 

julianE

Senior Member
Thanks to all the forum members I have a nextion 2.4 working with a 14M2. My unit came with a micro USB adapter for powering the unit or testing, the instructions are a bit vague. There is a warning about using insufficient power supply leading to module failure.

nextion.JPG

I ran the module on 3.3 Volts and it worked fine but the caution is concerning. Eventually I would like to run the project with a single LiPo cell.
Has anyone experienced issues running the Nextion module on voltages below 5V. I'm fairly certain there is a 3.3V regulator onboard but haven't looked at the schematic.

thanks in advance.
 

oracacle

Senior Member
I haven't done any testing at below 5v. I have found that if you fade the display it puts huge amount of noise onto the power +v.
I would suggest that you look into how USB power banks work. You could also get one of those without batteries in (essentially just a case and charging/boost circuit - a quick search on amazon https://www.amazon.co.uk/TAOtTAO-Metal-Battery-Charger-Purple/dp/B076CFCLY3/ref=sr_1_16?ie=UTF8&qid=1547841550&sr=8-16&keywords=USB+power+bank+case). Make sure the LiPo you use is one with a protection circuit built. I don't know what your application is, but you may just be able to modify a power bank that fits into your size requirements, be able to charge over USB and give you the 5v that should be used.
 

julianE

Senior Member
I have found that if you fade the display it puts huge amount of noise onto the power +v.
Thanks for the info, that makes a lot of sense. I have a number of those battery booster boxes and it does make sense to use it with a portable project. It's all self contained, charger, battery saver and regulator. I'll see if I wanna gamble with damaging the display, I know I will not gamble with large Nextion displays that get rather pricey.
 

Julianosborn

New Member
I haven't done any testing at below 5v. I have found that if you fade the display it puts huge amount of noise onto the power +v.
I would suggest that you look into how USB power banks work. You could also get one of those without batteries in (essentially just a case and charging/boost circuit - a quick search on amazon https://www.amazon.co.uk/TAOtTAO-Metal-Battery-Charger-Purple/dp/B076CFCLY3/ref=sr_1_16?ie=UTF8&qid=1547841550&sr=8-16&keywords=USB+power+bank+case). Make sure the LiPo you use is one with a protection circuit built. I don't know what your application is, but you may just be able to modify a power bank that fits into your size requirements, be able to charge over USB and give you the 5v that should be used.
I have purchased one of the following from Amazon,

It works a treat, battery's have to be purchased separate though, if you purchase an led head torch rechargeable the battery's remove very easily, and are half the price of purchasing the battery's on there own.
 

johnlong

Senior Member
hi
Being having a play with it myself have worked out how to alter multiple values of the page with only a + and - keys
To do this I used the timer variable in conjunction with a variable. Each of the hotspot(day temp hum,alarm,ect) for the values to be set or changed is given a value, the value is as assigned is then used with the plus key, when the minus key is selected the value is incresse by 1 ie 1 becomes 2, on reselection of plus key the value is decressed back by 1. While you keep the key depressed it alters sets the picaxe variable automatically adding 1 or subtracting 1 without the constent tip tapping of the key. The present state of the picaxe variable is then displayed on the screen under the selected action
Nextion Timer variable
Code:
if(value.val==1)//min hum
{
  t1.font=5
  print "C+"
}
if(value.val==2)//min hum
{
  t1.font=5
  print "C-"
}
if(value.val==3)//max hum
{
  t1.font=5
  print "D+"
}
if(value.val==4)//max hum
{
  t1.font=5
  print "D-"
}
if(value.val==5)//vpd max
{
  t1.font=5
  print "L+"
}
if(value.val==6)//vpd max
{
  t1.font=5
  print "L-"
}
if(value.val==7)//VPD Min
{
  t1.font=5
  print "M+"
}
if(value.val==8)//vpd min
{
  t1.font=5
  print "M-"
}
if(value.val==9)//day temp
{
  t1.font=5
  print "A+"
}
if(value.val==10)//day temp
{
  t1.font=5
  print "A-"
}
if(value.val==11)//night temp
{
  t1.font=5
  print "B+"
}
if(value.val==12)//night temp
{
  t1.font=5
  print "B-"
}
if(value.val==13)
{
  t1.font=5
  print "K+"//alarm tempreture
}
if(value.val==14)
{
  t1.font=5
  print "K-"
}
the plus and minus keys with there assigned values held with in touch press event. The picaxe does the adding or subtraction and sends it back to the nextion the area populated by vpd in the image
23095

plus key code
Code:
if(value.val==1)
{
  value.val=1
  setting.en=1// turns on the timer
}else if(value.val==2)
{
  value.val=1
  setting.en=1
}else if(value.val==3)
{
  value.val=3
  setting.en=1
}else if(value.val==4)
{
  value.val=3
  setting.en=1
}else if(value.val==5)
{
  value.val=5
  setting.en=1
}else if(value.val==6)
{
THE touch release event is simply en=0 turn off the timer code_c clears the buffer
en is the timer value which is set to en=0 tim=400
THE MINUS KEY
Code:
if(value.val==1)
{
  value.val=2
  setting.en=1
}else if(value.val==2)
{
  value.val=2
  setting.en=1
}else if(value.val==3)
{
  value.val=4
  setting.en=1
}else if(value.val==4)
{
  value.val=4
  setting.en=1
}else if(value.val==5)
{
  value.val=6
  setting.en=1
}else if(value.val==6)
{
  value.val=6
  setting.en=1
}else if(value.val==7)
{
  value.val=8
  setting.en=1
}else if(value.val==8)
{
  value.val=8
  setting.en=1
}else if(value.val==9)
{
  value.val=10
  setting.en=1
}else if(value.val==10)
{
  value.val=10
  setting.en=1
}else if(value.val==11)
{
  value.val=12
  setting.en=1
}else if(value.val==12)
{
  value.val=12
  setting.en=1
}else if(value.val==13)
{
  value.val=14
  setting.en=1
}else if(value.val==14)
{
  value.val=14
  setting.en=1
}
image showiing variables
23096
 
Last edited:

johnlong

Senior Member
Hi
for securty to stop little or large fingers altering things I found an example on youtube by a gentleman called royal newbury
and adapted it for use with the picaxe
23097

The following code is all held in the preinitalize event
Code:
tx0.txt=tx0.txt-4
ref key2.val
if(key2.val==0)
{
  tx1.txt="Passcode"
  tx2.txt="Change"
}else if(key2.val==1)
{
  tx1.txt="Passcode"
  tx2.txt="Entre New"
}else if(key2.val==2)
{
  tx1.txt="Passcode"
  tx2.txt="Entre"
  key2.val=2
}
The variable values are as follows home=1111 (this is the value you change) KEY=1 KEY1=1 KEY2=0
The entre key then generates the following
Code:
cov tx0.txt,key1.val,0
home.val=1111
if(home.val==key1.val)
{
  key2.val=1
  key.val=0
  page page0
}
if(key.val==0)
{
  cov tx0.txt,key.val,0
  key2.val=2
  page page0
}
if(key.val!=key1.val)
{
  key1.val=0
  tx0.txt=tx0.txt-4
}else if(key.val==key1.val)
{
  key1.val=0
  key2.val=2
  print "QU"
}
"QU" is read by the picaxe and the picaxe determins what action to take ihe number keys hold the following 1( tx0.txt=tx0.txt+"1") 2( tx0.txt=tx0.txt+"2") 0=(tx0.txt=tx0.txt+"0") ,ect C= tx0.txt=tx0.txt-1 and the AC= tx0.txt=tx0.txt-4

john
 
Last edited:
Top