Rushtp #6 - Nextion Intelligent - Photo Frame Record & Playback Transition Effects

by Rushtp in Circuits > Electronics

438 Views, 1 Favorites, 0 Comments

Rushtp #6 - Nextion Intelligent - Photo Frame Record & Playback Transition Effects

0.0) Image.jpg
0.1) Record.gif
0.2) Random.gif
0.3) Play.gif

Table of Contents


Background

In this project I will show how to create a DataRecord with a file stored on the Nextion Intelligent built in SD card reader. Then I'll show how to record the movement of a ExPicture frame loaded with a photo. Finally, I’ll demonstrate how to play the recording back to recreate the ExPicture frame movement.

In my earlier Nextion Editor projects Rushtp#4 and Rushtp#5 we explored the built-in and some bespoke algebraic transition effects.

Now we will create a freehand transition effect by recording the movement of the photo as it is manually dragged around the screen. The recording will then be played back to simulate the dragging effect.

DataRecord supports up to 12 (columns) per record. DataRecord incorporates 4 methods:

.insert(string newtxt)
.delete(int strid, int qty)
.up(string newtxt, int index)
.clear()


For the purposes of this tutorial only one DataRecord with two columns will be used but you can follow the same process to add more DataRecords for multiple freehand effects.


So let’s get started.

We will be starting from where I left off in my earlier project Rushtp #3 - Nextion Intelligent - Photo Frame ExPicture Files From the SD Card.

Please note: This project can only be created on the Nextion Intelligent Series displays.

I am using the same Nextion Intelligent 7" Touch Screen (NX8048P070-011C) as before.

If you have not completed that project you can download the Nextion HMI file and Photo files for this project by following the instructions in Step 1 below.


Acknowledgments & References:

  1. Cheap Controls Tutorials - #115 Nextion Display DataRecord elements
  2. Symbols ▼ and ▲ - W3Schools Tutorial (UTF-8 Geometric Shapes)
  3. The Nextion Editor Guide - Nextion



Table of Contents:

Supplies:   List of project essentials

Step 1:   Nextion Editor - Load The Rushtp #3 Photo Frame Project Files

Step 2:   Nextion Editor - Shorthand Conventions I’ll be using...

Step 3:   Nextion Editor - Creating A New Font

Step 4:   Nextion Editor - “Clear The Decks”

Step 5:   Nextion Editor - Dragging and Tracking

Step 6:   Nextion Editor - Creating a DataRecord

Step 7:   Nextion Editor - Coding a Counting Down

Step 8:   Nextion Editor - Data Recording

Step 9:   Nextion Editor - Play Back

Step 10: Nextion Editor - Navigating And Deleting

Step 11: Nextion Editor - Edit And Update With Numeric Keyboard

Step 12: Nextion Editor - Setup The Transitions

Step 13: Nextion Editor - Tap On The Screen To Toggle The Controls ON/OFF

Step 14: Nextion Editor - Upload To A Nextion Intelligent 7" Touch Screen

Step 15: Summing Up…

Step 16: Download Worked Example


Table of Contents


Supplies

0Sa. IMG_0723.JPG
0Sb. USB Connections.bmp
0Sc. Wiring.bmp


  1. Nextion Intelligent 7" Touch Screen (e.g. NX8048P070-011C)
  2. USB to TTL CP2102 UART Module 5Pin Serial Converter
  3. USB extender cable (3m)
  4. 20mm clear heat Shrink tube (Optional)
  5. Nextion Editor (Download)
  6. Nextion Editor Guide
  7. Nextion Instruction set
  8. 32GB Micro SD Card (FAT32 format) Search


The Nextion display is connected using a USB to TTL CP2102 UART Module 5Pin Serial Converter.

The TFT File Output option works fine but the Upload option is easier to use (No fiddling around with the SD card).

If the Upload option does not work have a look at Rushtp #2 - Nextion Editor Serial Upload Not Working - Fixes to get it working.


Table of Contents

Nextion Editor - Load the Rushtp #3 Photo Frame Project Files

Guide.jpg
1a. Untitled-1.jpg
1b. Untitled-1.jpg
1c. IMG_0778.JPG


I am starting where I left off in my Rushtp #3 - Nextion Intelligent - Photo frame ExPicture files from the SD Card project.


If you have not completed that project you can download the Nextion HMI file and Photo files for this project using the links below.

Rushtp3.zip

Note: This file has been saved as a .zip file.

  1. Open the .zip file
  2. Then Extract all
  3. Open Rushtp3.HMI in the Nextion Editor
  4. Select File, Virtual SD Card Folder and create a folder called xi Photos
  5. Copy and Paste the extracted photo files into the xi Photos
    (Photo-1.xi, Photo-2.xi, Photo-3.xi, etc…)


Top Tool Bar

 File, Virtual SD Card Folder

	folder		sdcard0
	new		Folder
	folder name	"xi Photos"
	add files	“Photo-1.xi”
			“Photo-2.xi”
			“Photo-3.xi”
			etc...


Open the Rushtp3.HMI file in the Nextion Editor. and SaveAs Rushtp #6 - Nextion Intelligent - Photo Frame Record & Playback Transition Effects.HMI.

This file was developed for the Nextion Intelligent Series 7” display screen. To modify it for other size screen, or to include your own images, you will have to follow the whole Rushtp #3 - Nextion Intelligent - Photo Frame ExPicture Files From the SD Card project making adjustments for your screen size, and photos.



Table of Contents

Nextion Editor - Shorthand Conventions I’ll Be Using…

2a. Untitled-1 (2).jpg
2b. Untitled-1.jpg


The Nextion Editor has a number of display areas that contain objects, actions, files or code.

  1. File
  2. Tools
  3. Toolbox
  4. Display
  5. Program.s
  6. Page
  7. Attribute
  8. Event
  9. Pictures
  10. Fonts

So, when referring to placing an object (e.g. Button, b0) I’ll use the following convention
(…this button is just an example and not one used in this project)

b0(Button)

 Toolbox, Button, Attribute

	objname		b0
	vscope 		local
	font   		1
	txt    		"Set value"
	txt_maxl    	9
	x      		250
	y      		125
	w      		80
	h      		30

 Event, Touch Release Event

 n0.val=5


I am not going to explain ever piece of code we are using.
I leave it up you you to work it out. It is not that difficult, but I will explain what we are trying to achieve as we go along.


Table of Contents

Nextion Editor – Creating a New Font

3a. Untitled-2.jpg
3b. Untitled-9.jpg
3c. Untitled-1.jpg


Stay in Rushtp #6 - Nextion Intelligent - Photo Frame Record & Playback Transition Effects.HMI in the Nextion Editor.

Before we start adding buttons and other objects I want you to create a new font Arial16B. This should be font ID:2.

Top Tool Bar

 Tools, Font Generator, Attribute

 	Height 		16

 	Encoding 	utf-8

 	Font 		Atial

 	Bold 		“ticked”

 	Font Name 	Arial16B 


Generator font

 	File Name 	Arial16B.zi 


Save

   When Progress: 100% 		OK 

   Add the generated font 	Yes 


Table of Contents

Nextion Editor – “Clear the Decks”

4a.jpg
4b.jpg
4c.gif


Assuming you have created Rushtp #6 - Nextion Intelligent - Photo Frame Record & Playback Transition Effects.HMI from me previous projects (or downloaded Rushtp3.HMI in Step 1)…


Let’s tidy the screen up by moving the existing browser object out of the way. Just set fbrowser0(FileBrowser) attribute x to -300. This will hide it out-of-sight to the left of the screen!


fbrowser0(FileBrowser)
Toolbox, , FileBrowser, Attribute
	objname		fbrowser0
	vscope 		local
	...
	x      		-300
	y      		68
	w      		240
	h      		240
Event, Touch Release Event
  fCount.val=fbrowser0.qty



Run the file in Debug to check the Photos, Serial OFF/ON and the Random OFF/ON buttons work.

The file count should reflect the number of .xi files you loaded in Step 1. (Virtual SD Card Folder… sdcard0/xi Photos)


 Good!



Table of Contents

Nextion Editor - Dragging and Tracking

5a.gif
5b Overlapped photo.jpg
5c Hidden photo.jpg
5c.jpg


The Nextion Intelligent 7" (NX8048P070-011C) page size is w800 x h480 pixels with the origin x=0 and y=0 in the top-left corner.

I have set the ExPicture exp0 frame to the same size 800x480 to fill the page with the x and y coordinates set to 0, 0.


Looking at a bigger picture on an Excel scatter chart.

The chart axes are set to x = -800 to +1600 and y = -480 to +960. I have added a background image to demonstrate the location of the Nextion page.


Consider what happens when the ExPicture frame has it’s x and y coordinates set outside the page range. As the origin coordinates are moved outside the visible area into the hidden zone the photo gets cropped.

To completely hide the photo we need explore the hidden zone outside the visible area and use the coordinate ranges:

x = -800 to +1600px

y = -480 to +960px


The visible area being:

x = 0 to 800px

y = 0 to 480px


In practice to move a photo in the ExPicture frame we only have to consider coordinates the top-left 2/3rds of this area. This is because the frame has it’s origin 0,0 at the top-left corner of the visible area.

x = -800 to +800px

y = -480 to +480px


Dragging…

The Nextion Editor allows any object to be dragged using the mouse in the Debug window provided the drag attribute is set to yes.

So select exp0(ExPicture) in the Attributes box and set drag to yes and while you are at it change effect to load.


exp0(ExPicture)

 Toolbox, ExPicture, Attribute

	objname		exp0
	vscope 		local
	drag   		yes
	aph    		127
	effect 		load
	x      		0
	y      		5
	w      		800
	h      		480


Run the file in Debug again. This time press the Photos button and then left-click and hold the mouse pointer anywhere on the photo and drag it around.

You will see the picture can be moved into the hidden area around the screen.


Close the Debug window.


Tracking…

Next we will add four text objects from the Toobox to track the dragged picture x & y coordinates. Oh! and a Reset button too.

First create t1(Text). Then Copy and Paste it to create t2(Text). Then edit the attributes sta, txt, x, y, etc


t1(Text)
Toolbox, Text, Attribute
	objname		t1
	vscope 		local
	sta    		transparency
	font   		2
	pco    		65535  (white)
	txt    		"x"
	txt_maxl 	1
	x      		168
	y      		27
	w      		50
	h      		30
t2(text)
Toolbox, Text, Attribute
	objname		t2
	vscope 		local
	sta    		transparency
	font   		2
	pco    		65535  (white)
	txt    		"y"
	txt_maxl 	1
	x      		218
	y      		27
	w      		50
	h      		30


Then Copy and Paste again to create t3(Text) and t4(Text). Then edit the attributes sta, txt, x, y, etc


t3(Text)
Toolbox, Text, Attribute
	objname		t3
	vscope 		local
	sta    		solid color
	style  		border
	borderw 	1
	font   		2
	txt    		"0"
	txt_maxl 	5
	x      		168
	y      		55
	w      		50
	h      		30
t4(text)
Toolbox, Text, Attribute
	objname		t4
	vscope 		local
	sta    		solid color
	style  		border
	borderw 	1
	font   		2
	txt    		"0"
	txt_maxl 	5
	x      		218
	y      		55
	w      		50
	h      		30

OK! Yes, I have set t3 and t4 as text objects not number objects to display the exp0(ExPicture) x & y coordinate values.

I want to add another text object t5 to display the text values of the x and y coordinate separated by a caret or circumflex character “^. This is the format used to insert data into the DataRecord (e.g. “100^75”).


t5(text)
Toolbox, Text, Attribute
	objname		t5
	vscope 		local
	sta    		solid color
	style  		border
	borderc 	63488  (Red)
	borderw 	3
	font   		0
	txt    		"0^0"
	txt_maxl 	10
	x      		168
	y      		92
	w      		100
	h      		30

Now, to get the x and y coordinates as we drag the photo around we need another timer.

Create tm1(Timer) and set it to trigger every 200 milliseconds (0.2 seconds). As it triggers we will read the exp0(ExPicture) coordinates and display their values in t3 and t4. t5 has their text values concatenated while separated by a caret or circumflex character “^”. Note that attribute tm1.em can be used to switch the timer ON and OFF.


tm1(Time)
Toolbox, Timer, Attribute
	objname		tm1
	vscope 		local
	tim   		200	(0.2 seconds)
	en   		1	( 0=OFF, 1=ON)
Timer Event
covx exp0.x,t3.txt,0,0   //Convert value of exp0.x into t3.txt
covx exp0.y,t4.txt,0,0   //Convert value of exp0.y into t4.txt
 t5.txt=t3.txt
 t5.txt+="^"
 t5.txt+=t4.txt


Create a Reset button. This is to reposition exp0 back to it’s original start position x=0 and y=0 after we have dragged the photo around.
Add button b3 from the Toolbox


b3(Button) Reset
Toolbox, Button, Attribute
	objname		b3
	vscope 		local
	font   		2
	txt    		"Reset"
	txt_maxl 	10
	x      		273
	y      		56
	w      		90
	h      		30
Event, Touch Release Event
 x.val=0
 y.val=0
 t3.txt=”0”
 t4.txt=”0”


Run the file in Debug again. Press the Photos button and then left-click and hold the mouse pointer anywhere on the photo and drag it around.

The photo x and y coordinates are displayed every 0.2 seconds. Press the Reset button to move the photo back to the start position.



 So far, So Good!

(If things go wrong please recheck the object Names and the Event coding).



Table of Contents

Nextion Editor – Creating a DataRecord

6a.jpg
6c.jpg
6b.jpg


Before getting started on data recording on the Nextion display lets consider what we want to do...

At present, when the a photo in the exp0(ExPicture) frame is being dragged around, the x and y coordinates are displayed in text objects t3 and t4 on the screen.

The third text object t5 displays their text values concatenated while separated by a caret or circumflex character ^.

Remember the timer variable tm1 is used to trigger the readings every 0.2 seconds as the photo is being dragged. When we created it the timer was enabled (attribute en set to 1). Now, however, we only need the dragging ability to function during recording so let’s set en set to 0.

To record the x and y coordinates values as the timer triggers we can employed the DataRecord object that is available for the Nextion Intelligent displays.


Now, however, we only need the dragging ability to function during recording so let’s set en to 0.

tm1(Time)
Toolbox, Timer, Attribute
	objname		tm1
	vscope 		local
	tim   		200	(0.2 seconds)
	en   		0	( 0=OFF, 1=ON)
Timer Event
covx exp0.x,t3.txt,0,0   //Convert value of exp0.x into t3.txt
covx exp0.y,t4.txt,0,0   //Convert value of exp0.y into t4.txt
 t5.txt=t3.txt
 t5.txt+="^"
 t5.txt+=t4.txt


Also, I want to set the drag attribute in the photo frame exp0(ExPicture) to no to prevent dragging until a recording is activated. More of that later.


exp0(ExPicture)

 Toolbox, ExPicture, Attribute

	objname		exp0
	vscope 		local
	drag   		yes
	aph    		127
	effect 		load
	x      		0
	y      		5
	w      		800
	h      		480



Setting up the DataRecord…

To record the x and y coordinates values as the timer triggers we can employed the DataRecord object that is available for the Nextion Intelligent displays.

Many thanks for his tutorial go to:

  1. Cheap Controls Tutorials - #115 Nextion Display DataRecord elements


We are going to create a two column DataRecord with headers called x and y. An associated data file to hold the records will be created (/Recordings/1.data) in the Nextion Editor Virtual SD Card Folder. Later, when the project is Uploaded to the Nextion touch Screen the data file will be held on the built-in SD reader card.

Please watch the Cheap Controls Tutorial. Then follow my instructions below carefully.



Create a DataRecord from the Toolbox.

data0
head0 head1 head2







Start setting the attributes:

When you get to changing the path you will get a message box telling you the "File configuration data does not match Component configuration data".

Pressing Continue with Remind me next time puts the same message in the DataRecord (See below).

To reset the data file 1.data open the Virtual SD Card Folder under the File tab create a new folder called Recordings. Then delete the file 1.data.

Go back and click on the DataRecord and black background and message will clear. so you can carry on setting the Attributes. At the same time a new data file will be created automatically in the Recordings folder (sd0/Recordings/1.data).

data0(DataRecord)
Toolbox, DataRecord, Attribute
	objname 	data0
	vscope  	global
	sta     	solid color
	style   	border
	borderc 	63488 (Red)
	borderw 	3
	font    	2
	xcen    	Center
	path    	sd0/Recordings/1.data 
	lent 		10
	maxval 		999
	dez 		2
	dir 		x^y
	x      		168
	y      		124
	w      		100
	h      		310



File configuration data does not match Component configuration data. It is recommended to delete this file. The system will recreate the correct data file.
sd0/1.data

Remind me next time

No more reminders today No more reminders in a week

Continue
Open Virtual SD Card Folder

data0
Fie configuration data does not match Component configuration data. It is recommended to delete this file. The system will recreate the correct data file.
sd0/1.data




This rigmarole occurs each time you change an attribute that alters the data file structure. So to speed things up next time select No more reminders today and Continue.

When the attribute are all set go back to the Virtual SD Card Folder and deleted the data file 1.data in the Recordings folder. Then return and click on the DataRecording and clear the File configuration message.

You should have created the two column table like this...


data0
x y
 



Table of Contents

Nextion Editor - Coding a Counting Down

7a.gif


A RECORD button will be used to switch on a recording of the photo coordinates during dragging but first I have created a 3 second count-down timer to give us time to ready ourselves.

Add a new text object t6(Text) and set the attributes as follows…

t6(Text) Count Down
Toolbox, Text, Attribute
	objname 	t6
	vscope  	local
	sta     	solid color
	style   	border
	borderw 	2
	font    	1
	borderc 	65528 (Pale yellow)
	pco     	31 (Blue)
	xcen    	Center
	txt     	"3"
	txt_maxl 	4
	x      		-200 (Hide it)
	y      		150
	w      		100
	h      		100

I have set t6.x=-200 to hide it away to the left of the visible screen.


Add button b4(Button) and copy and paste the code into the Touch Press Event.

Button b4 “RECORD”, below, will be programmed to display this text box and count down from 3 to DRAG in 3 seconds. It will also set exo0.drag and the tm1.en timer ON/OFF (tm1.en=1enabled and tm1.en=0 disabled). Pressing the b4 STOP button will hide it again.

b4(Button) RECORD/STOP - The button txt attribute is initially set to RECORD.


- The event coding set the txt attribute to STOP and the changes the countdown t6.x attribute to 300 to move it back into be visible on the screen.


- After counting down from 3 to DRAG in 3 seconds the code will also set exp0.drag to 1 (yes) and the tm1.en timer trigger to 1 (enabled) allowing dragging and recording to be performed.


- Pressing the b4 STOP button switches dragging the timer tm1.en to 0 (Off), disables dragging and hides the countdown t6 text box again.
Toolbox, Button, Attribute
	objname		b4
	vscope 		local
	sta    		solid color
	style  		3D_Auto
	font   		2
	txt    		"START"
	txt_maxl 	10
	x      		73
	y      		203
	w      		90
	h      		30
Event, Touch Release Event
if(b4.txt=="RECORD")
 {
   b4.pco=31 //Blue
   be.txt="STOP"
   t6.txt="3"
   t6.x=300 //Show Count down
   delay=1000
   t6.txt="2"
   delay=1000
   t6.txt="1"
   delay=1000
   tm1.en=1 //Timer enabled
   exp0.drag=1 //Dragging ON
   t6.txt="DRAG”
 }else
 {
   b4.pco=0
   b4.txt="RECORD"
   tm1.en=0 //Timer disabled
   exp0.drag=0 //Dragging OFF
   t6.x=-200 //Hide Count Down
 }


Run the file in Debug. Press the Photos button and then press the START button. Text box t6 will count-down from 3 to DRAG and then be hidden when STOP is pressed.


 OK!



Table of Contents

Nextion Editor - Exploring Data Recording

8a.gif
8b.jpg


To make a recording and add entries to the DataRecord we have to use the .insert(string newtxt) method. Entries are added sequentially from the start of the data file index 0.

Back in Step 6: Nextion Editor – Creating a DataRecord we created tm1(Timer) and coded the event to capture the x and y coordinates of the photo being dragged in the frame exp0(ExPicture). The results are displayed in t3, t4 and t5 displays the data in the correct format to insert into data0(DataRecord). All we have to do is add code to the tm1(Timer) event.

As data is entered data0.qty keeps a count of the total number of entries. We will use a number box to display it. This is achieved by adding the n1.val=data0.qty to the Timer Event code in tm1.


So first add n1(Number) from the Toolbox.

n1(Number)
Toolbox, Number, Attribute
	objname 	n1
	vscope  	local
	sta     	solid color
	style   	border
	borderc 	63488  (Red)
	borderw 	3
	font    	2
	val     	0
	format  	Decimal
	x      		114
	y      		92
	w      		50
	h      		30



Add additional code to the recording timer to insert records…

Inserting data into data0(DataRecord) is achieved by including data0.insert(t5.txt) in the tm1(Timer) Timer Event code. Where t5.txt holds the concatenated x^y coordinate readings each time the timer triggers during dragging.

As data is added the record count is incremented by 1 and we keep track using the code n1.val=data0.qty.

tm1(Time)
Toolbox, Timer, Attribute
	objname		tm1
	vscope 		local
	tim    		200    (0.2 seconds)
	em     		1  ( 0=OFF, 1=ON)
Timer Event
covx exp0.x,t3.txt,0,0 //Convert value of exp0.x into t3.txt
covx exp0.x,t4.txt,0,0
 t5.txt=t3.txt
 t5.txt+="^"
 t5.txt+=t4.txt
//
 data0.insert(t5.txt)
 n1.val=data0.qty


Retrieving individual data entries…

As data has been recorded the DataRecord displays it in rows in a table.

Now I want to be able to get the record values to be displayed in the n1(Number) and t5(Text). This is the first step for creating the Play Back routine in Step 9.

To do this we need to add code to the data0(DataRecord) Touch Release Event. So just clicking on a data row will display the values in the two text boxes.

 
data0(DataRecord)
Toolbox, DataRecord, Attribute
	objname 	data0
	vscope  	global
	sta     	solid color
	style   	border
	borderc 	63488 (Red)
	borderw 	3
	font    	2
	xcen    	Center
	path    	sd0/Recordings/1.data 
	lent 		10
	maxval 		999
	dez 		2
	dir 		x^y
	x      		168
	y      		124
	w      		100
	h      		310

Event, Touch Press Event
if(data0.qty>0&&data0.val>=0)
 {
  n1.val=data0.val
  t5.txt=data0.txt
 }


 
3   57^86
 
    x y
    0 0
    28 -204
    189 23
    57 86
    -64 -12
    100 1
    26 93
    -52 17
    -102 -47
    -300 -210

Your data will be different to this!


Clearing the data record…

I mentioned earlier in the project that new data is added or appended to the end of the existing records on the data file. We need a way to empty the data file before we start a new recording. This can be achieved using data0.clear().

Add b5(Button) - Clear All and include the Touch Release Event code below. This button will erase the existing data do this before starting a new recording.

b5(Button) Clear All
Toolbox, Button, Attribute
	objname		b5
	vscope 		local
	sta    		solid color
	style  		3D_Auto
	font   		2
	txt    		"Clear All"
	txt_maxl	10
	x      		73
	y      		167
	w      		90
	h      		30
Event, Touch Press Event
 data0.clear() //Clear all data
 n1.val=data0.qty
 t3.txt="0"
 t4.txt="0"
 t5.txt="0^0"


Run the file in Debug.

Press the Clear All thenPhotos buttons and then press the RECORD button (the ROCORD button text will change to STOP). After the count-down gets to DRAG start dragging the photo around. The data0(DataRecord) table will start being loaded and the row-counter n1 will display the total number of entries in the record.

Press the STOP button to finish the recording.

If you re-start the recording the additional records will be added at the end of the existing data - try it.

Press Clear All to empty the data file before starting a new recording.

The photo x and y coordinates are displayed during the recorded every 0.2 seconds.

After the recording has been completed clicking on a data row the row number data0.val and the data row text data0.txt will be displayed in n1(Number) and t5(Text0) boxes. Note: The x and y coordinates will not update on the selection yet. We will sort that out in the next steps.

Clicking and dragging a data table cells vertically will allow the table to be scrolled UP/DOWN.


 That’s got the records.



Table of Contents

Nextion Editor - Play Back

9a.gif
9b.gif
9c.jpg


Play button…

Create a new button b6.
The aim here is to play the data0(DataRecord) back in reverse order so the photo in exp0 x and y coordinates are stepped back to the 0,0 origin.


n1.val=data0.qty-1
When the PLAY button is pressed we need to get the ID of the last record in the table and store it in n1. The -1 is because the record ID starts at 0 so for a record count data0.qty of say 10 the last record ID would be 9 not 10.


for(data0.val=data0.qty;data0.val>=0;data0.val--)
This routine steps through the table ID in the reverse order and sets the x and y coordinates iv the photo displayed in exp0(ExPicture). The selected data row ID is data0.val.


t5.txt=data0.txt
Each record in a text format x^y is displayed in t5.


spstr t5.txt,t3.txt,"^",0   //return string before first delimiter ^ occurs.
This is used to get the text value of the x coordinate.


conv t3.txt,exp0.x,0,0
Converts the text values of x held in t5 to the number value of the exp0.x coordinates



Similarly…

spstr t5.txt,t4.txt,"^",1   //return string after first delimiter ^ occurs.


covx t4.txt,exp0.y,0,0
Converts the text values of y held in t5 to the number value of the exp0.y coordinates


b6(Button) PLAY
Toolbox, Button, Attribute
	objname		b6
	vscope 		local
	sta    		solid color
	style  		3D_Auto
	font   		2
	txt    		"PLAY"
	txt_maxl	10
	x      		73
	y      		238
	w      		90
	h      		30
Event, Touch Press Event
 n1.val=data0.qty-1
 data0.val=n1.val
//
for(data0.val=data0.qty;data0.val>=0;data0.val--)
 {
  n1.val=data0.val
  t5.txt=data0.txt
  delay=200
  //
  spstr t5.txt,t3.txt,"^",0
  spstr t5.txt,t4.txt,"^",1
  //
  covx t3.txt,exp0.x,0,0
  covx t4.txt,exp0.y,0,0
 }


At this point I want to get a photo in exp0(ExPicture) to move to any records I select in the table so we will go back to data0(DataRecord) and add some of the PLAY button code to the Touch Release Event.


 
data0(DataRecord)
Toolbox, DataRecord, Attribute
	objname 	data0
	vscope  	global
	sta     	solid color
	style   	border
	borderc 	63488 (Red)
	borderw 	3
	font    	2
	xcen    	Center
	path    	sd0/Recordings/1.data 
	lent 		10
	maxval 		999
	dez 		2
	dir 		x^y
	x      		168
	y      		124
	w      		100
	h      		310

Event, Touch Press Event
if(data0.qty>0&&data0.val>=0)
 {
  n1.val=data0.val
  t5.txt=data0.txt

  //
  spstr t5.txt,t3.txt,"^",0
  spstr t5.txt,t4.txt,"^",1
  //
  covx t3.txt,exp0.x,0,0
  covx t4.txt,exp0.y,0,0

 }

 
    57 86
 
3   57^86
 
    x y
    0 0
    28 -204
    189 23
    57 86
    -64 -12
    100 1
    26 93
    -52 17
    -102 -47
    -300 -210

Your data will be different to this!


Give it a try in Debug.



Table of Contents

Nextion Editor - Navigating and Deleting

10a.gif
10b.jpg
10c.gif


Before we finish with this project let’s enable some editing features to navigate and clean up or amend the records.


Navigation buttons…

Go to the Top.

Add b7(Button) - Top and include the Touch Release Event code below. This button selects the first (Top) data entry. It will be highlighted in blue.

The click data0,0 code causes Touch Release Event in data0(DataRecord) to trigger and update the n1(Number ) and t5(text) boxes.

b7(Button) Top
Toolbox, Button, Attribute
	objname		b7
	vscope 		local
	font   		2
	Txt    		"Top"
	txt_maxl 	10
	x      		73
	y      		281
	w      		90
	h      		30
Event, Touch Release Event
   n1.val=0
   data0.val=n1.val
   click data0,0


Increment down .

Add b8(Button) - ▼ and include the Touch Release Event code below. This button will move down the data table one record at a time. It will be highlighted in blue each step down.

To get the ▼ character symbol copy and paste it from W3Schools Tutorial (UTF-8 Geometric Shapes)

b8(Button) ▼
Toolbox, Button, Attribute
	objname		b8
	vscope 		local
	font   		2
	Txt    		"▼"
	txt_maxl 	10
	x      		73
	y      		317
	w      		45
	h      		30
Event, Touch Release Event
  n1.val++
  if(n1.val>=data0.qty)
  {
    n1.val=data0.qty-1
  }
  data0.val=n1.val
  click data0,0
  


Increment up ▲.

Add b9(Button) - ▲ and include the Touch Release Event code below. This button will move up the data table one record at a time. It will be highlighted in blue each step down.

To get the ▲ character symbol copy and paste it from W3Schools Tutorial (UTF-8 Geometric Shapes)

b9(Button) ▲
Toolbox, Button, Attribute
	objname		b9
	vscope 		local
	font   		2
	Txt    		"▲"
	txt_maxl 	10
	x      		118
	y      		317
	w      		45
	h      		30
Event, Touch Release Event
  n1.val--
  if(n1.val<0)
  {
    n1.val=0
  }
  data0.val=n1.val
  click data0,0
  


Go to the Bottom.

Add b10(Button) - Bottom and include the Touch Release Event code below. This button selects the last (Bottom) data entry. It will be highlighted in blue.

b10(Button) Bottom
Toolbox, Button, Attribute
	objname		b10
	vscope 		local
	font   		2
	Txt    		"Bottom"
	txt_maxl 	10
	x      		73
	y      		353
	w      		90
	h      		30
Event, Touch Release Event
  n1.val=data0.qty-1
  data0.val=n1.val
  click data0,0
  data0.val=n1.val
  click data0,0
  


Delete button.

data0.delete(data0.val,1)

Add b11(Button) - Delete and include the Touch Release Event code below. This button deletes the selected data row.

b11(Button) Delete
Toolbox, Button, Attribute
	objname		b11
	vscope 		local
	font   		2
	Txt    		"Delete"
	txt_maxl 	10
	x      		73
	y      		396
	w      		90
	h      		30
Event, Touch Release Event
  data0.delete(data0.val,1)
  if(data0.val==-1)
  {
    data0.val=data0.qty-1
  }
  click data0,0
  



Note: you can drag the data rows up and down to view the hidden entries in the record table'



Table of Contents

Nextion Editor - Edit and Update With Numeric Keyboard

11a.gif
11d.jpg


Having got a set of data records and shown how to play them back there just the Update function to address .up(string newtxt, int index).


Again many thanks for his tutorial:

  1. Cheap Controls Tutorials - #115 Nextion Display DataRecord element. Insert, Delete, Update and Clear

This step is going to look a little messy on the screen but is should prove the update method with the minimum of work,

Hold the Ctry key down and left-click the mouse to select these four objects:
         text boxes t1, t2, t3, t4, t5 and the Reset button b3.

Then paste and move them to the clear area on right side of the screen. Their objname’s will change after pasting and should correspond to descriptions below:
         text boxes t9, t10, t7, t8, t11 and the Update button b12.


Set the attributes and events as follows… (Note: t7 and t7 have their vscope set to global)

t9(Text)
Toolbox, Text, Attribute
	objname		t9
	vscope   	local
	sta    		transparency
	key    		none
	font   		2
	pco    		65535  (white)
	txt    		"x"
	txt_maxl 	1
	 x      	433
	 y      	27
	w      		50
	h      		30
t10(text)
Toolbox, Text, Attribute
	objname		t10
	vscope   	local
	sta    		transparency
	key    		none
	font   		2
	pco    		65535  (white)
	txt    		"y"
	txt_maxl 	1
	 x      	484
	 y      	27
	w      		50
	h      		30
t7(Text)
Toolbox, Text, Attribute
	objname		t7
	vscope		global
	sta    		solid color
	style    	border
	borderw    	1
	key		numeric keyboard
	font   		2
	pco      	31  (blue)
	txt    		"0"
	txt_maxl 	5
	 x      	433
	 y      	56
	w      		50
	h      		30
t9(text)
Toolbox, Text, Attribute
	objname		t8
	vscope		global
	sta    		solid color
	style    	border
	borderw    	1
	key		numeric keyboard
	font   		2
	pco      	31  (blue)
	txt    		"0"
	txt_maxl 	5
	 x      	483
	 y      	56
	w      		50
	h      		30
t11(text)
Toolbox, Text, Attribute
	objname		t11
	vscope    	local
	sta    		solid color
	style    	border
	borderw    	31  (blue)
	borderw   	3
	font   		0
	pco      	31  (blue)
	txt    		"0^0"
	txt_maxl 	10
	 x      	434
	 y      	92
	w      		50
	h      		30


But before we continue... I want draw your attention to the attribute key. We will be using it to set up a built-in, on-screen, Numeric Keyboard so we can edit the text (in this case numbers) in our update text objects t3 and t4.


“Built-in-Keyboard Pages

Nextion Editor now has four different built-in-keyboards that can be added to a project. This allows for Text, Scrolling Text, Xfloat and Number component .txt and .val to be changed using a built in keyboard by the device user at runtime. In order to add a built-in-keyboard to your project, the component must first be set to .vscope global, second the .key attribute needs to select your desired keyboard. Selecting one of the keyboards will add the keyboard page to your project. Choices are full qwerty style (keybdA), numeric keyboard (keybdB), speed dial style (keybdC), and Chinese Input (Pinyin) style (keybdAP). The associated keyboard will load an appropriate font if not already included in the project and the keyboard page for the model size and orientation.

Ref: The Nextion Editor Guide – Nextion


To enable the built in numeric keyboard keybdB(Page) set the Text or Number object attributes as follows:
         vscope to global
         Key to numeric keyboard

A new locked page with the keyboard will be loaded and two new fonts installed.


It is important to note: When the Numeric Keyboard returns a value to the launch objects (in our case t7 and t8) the current screen page is refreshed and all objects with vscope set to local will have their values reset to the defaults set in their attributes!

So change the vscope to global.


In our case we need to change vscope in the following objects to global - do this now:

         t3(Text) to global
         t4(Text) to numeric keyboard
         t5(Text) to global
         n1(Number) to numeric keyboard


Update button.

Add this button. it is used to change the selected data entry in the DataRecords.

b12(Button) Update
Toolbox, Button, Attribute
	objname		b12
	vscope 		local
	font   		2
	Txt    		"Update"
	txt_maxl 	10
	x      		538
	y      		57
	w      		90
	h      		30
Event, Touch Release Event
  t11.txt=t7.txt+"^"+t8.txt
  data0.up(t11.txt,n1.val)
  click data0,0
  

Event code:

         - t11.txt=t7.txt+"^"+t8.txt sets t11 to the data in the correct format.
         - data0.up(t11.txt,n1.val) loads new values from t11 and updates the
             all the header boxes above it (t3, t4, etc…)
         - click data0,0 runs the Touch Release Events in data0(DataRecord) to reset
             all the header boxes above it (t3, t4, etc…)



Test it in Debug.

“Update” completes our tour of the 4 DataRecord methods.


The next step will show how to set the playback as a transitions effect when photos are displayed in the photo frame.


Table of Contents

Setup the Transitions

12b.gif
12c.gif


First let’s check we can get the Photo button to click the PLAY button to run the play routine.

Note: I have set the photo frame x coordinate to -480 to hide it to the left before the photo is loaded and the play routine is run.

b0(Button) Photos
Toolbox, Button, Attribute
	objname		b0
	vscope 		local
	font   		2
	Txt    		"Photos"
	txt_maxl 	10
	x      		293
	y      		341
	w      		90
	h      		30
Event, Touch Release Event
  b1.txt="Serial OFF"
  b2.txt="Random OFF"
  FileNr.val++
  n0.val=FileNr.val
  covx FileNr.val,tFileNr.txt,0,0
  if(FileNr.val>=fCount.val)
  {
     FileNr.val=0
  }
   exp0.x=-480 //Hide photo frame to the left
  exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"
   click b6,0 //Run the play routine
  


Test it in Debug.


We can add a new button to toggle the transition effect ON/OFF…

Copy button b1(Serial OFF) and paste it somewhere in a clear area of the screen.

Now edit the attributes as follows:

b13(Button) Transition OFF
Toolbox, Button, Attribute
	objname		b13
	vscope 		local
	font   		2
	Txt    		"Trans OFF"
	txt_maxl 	10
	x      		413
	y      		339
	w      		90
	h      		30
Event, Touch Release Event
   if(b13.txt=="Trans OFF")
  {
     b13.txt="Trans ON"
  }else
  {
     b13.txt="Trans OFF"
  }
  


Test the button text toggles Trans OFF/Trans ON in Debug.


Finally, both the Serial OFF and Random OFF buttons switch tm0(Timer) ON/OFF to automate the photo frame, so we can add the if(b13… code to the tm0(Timer) event…

tm0(Timer)
Toolbox, Button, Attribute
	objname		tm0
	vscope 		local
	tim    		3000
	en     		1
Event, Timer Event
  if(b1.txt=="Serial ON")
  {
    FileNr.val++
    n0.val=FileNr.val
    covx FileNr.val,tFileNr.txt,0,0
    if(FileNr.val>=fCount.val)
    {
      FileNr.val=0
    }
    if(b13.txt=="Trans ON")
    {
        exp0.x=-480 //Hide photo frame to the left
        exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"
        click b6,0 //Run the play routine
    }else
    {
       exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"
    }
  }
  // -----------------------------------------------------------------------
  if(b2.txt=="Random ON")
  {
    randset 1,fCount.val
    FileNr.val=rand
    n0.val=FileNr.val
    covx FileNr.val,tFileNr.txt,0,0
    if(b13.txt=="Trans ON")
    {
        exp0.x=-480 //Hide photo frame to the left
        exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"
        click b6,0 //Run the play routine
    }else
    {
       exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"
    }
  }
  


Check the Serial and Random buttons with the Trans OFF/Trans ON in Debug.



Table of Contents

Tap on the Screen to Toggle the Controls ON/OFF

13a.gif


Now the controls are all working it would be nice to hide them after the digital photo frame is running.

First create a new object t12(Text) by copying and pasting the t10(Text) the “of” object.
Then edit the attributes to display the screen instructions.

Before you set the txt attribute set txt_maxl to 100 (Select multiline… to add long text).

t12(Text
Toolbox, Text, Attribute
	objname 	T2
	vscope  	global
	font    	1
	sta     	transparency
	pco     	65522
	txt     	“Tap on the screen to Toggle controls ON/OFF”
	txt_maxl	100
	x       	75
	y       	35
	w       	700
	h       	30


Now add the following code to exp0(ExPicture).

exp0(ExPicture)
 Toolbox, ExPicture, Attribute
	objname		exp0
	vscope		global
	effect		top fly into
	x      		0
	y      		0
	w      		800
	h      		480
 Event, Touch Release Event
   if(visState.val==0)
   {
     vis b0,0
     vis b1,0
     vis b2,0
     vis n0,0
     vis t0,0
     vis fCount,0
     //-----------------------------------------------------------------
      vis n3,0
      vis h0,0
      vis b4,0
      vis n4,0
      vis h1,0
      vis e0,0
      vis e1,0
      vis e2,0
      vis e3,0
      vis e4,0
      vis e5,0
      vis e6,0
      vis e7,0
      vis e8,0
      vis e9,0
      vis e10,0
      vis e11,0
      vis t1,0
      vis n1,0
      vis bID,0
      vis t2,0
     //-----------------------------------------------------------------

     visState.val=1
   }else
   {
     vis b0,1
     vis b1,1
     vis b2,1
     vis n0,1
     vis t0,1
     vis fCount,1
     //-----------------------------------------------------------------
      vis n3,1
      vis h0,1
      vis b4,1
      vis n4,1
      vis h1,1
      vis e0,1
      vis e1,1
      vis e2,1
      vis e3,1
      vis e4,1
      vis e5,1
      vis e6,1
      vis e7,1
      vis e8,1
      vis e9,1
      vis e10,1
      vis e11,1
      vis t1,1
      vis n1,1
      vis bID,1
      vis t2,
     //-----------------------------------------------------------------

     visState.val=0
   }


Run Debug to ensure tapping the screen toggles the controls ON/OFF and it all works.


NOTE: You may have to tap the screen number of times to toggle if the transition playback is running because the processor can only do one thing at the time and you have to wait until the current routine is finished!


Table of Contents

Upload to a Nextion Intelligent 7" Touch Screen

14a Play.gif
13d.jpg
14c.jpeg
14d.jpeg


Finally, select Upload to update the Nextion Intelligent 7" Touch Screen.


In the Program.s tab above the display screen set baud=921600 //Configure baudrate.

Then I did an Upload with the Baud Rate set to 921600 onto the Nextion Intelligent 7" Touch Screen (e.g. NX8048P070-011C) using my USB to TTL CP2102 UART Module 5Pin Serial Converter.

     …it took about 4 minutes! …so time to pour a cold beer.


PS: If you have not disconnected the touch screen and closed the Nextion Editor the next upload only takes a few seconds to complete.


 
x y
File Lost:
sd0/Recordings
/1.data


If the DataRecord looks like this…

Make sure you a Micro SD Card (FAT32 format) inserted it in the built-in reader on the back of the Nextion Screen.

Also ensure you have created the folder Recordings.


 
x y
 


If it looks like this…

The folder Recordings exists and a new empty 1.data file has been automatically created.


 
x y
0 0
28 -204
189 23
57 86
-64 -12
100 1
26 93
26 93
26 93


You can also to copy the data file 1.data from the Virtual SD Card Folder onto the Nextion built-in SD card.

This will load the Nextion screen with the same data you created in the Nextion editor.

You have to do this each time the datafile is changed in the Nextion Editor.


Table of Contents

Summing Up…


Photo Frame Record & Playback Transition Effects.


 This is the last in my series on evaluating the Intelligent Series touch screen displays for use as a digital photo frame.

 I was particularly interested in the ability to read files stored on the built-in Micro SD card

 This led to exploring various methods of creating a transition effect as photos are loaded.


I am happy with the results.

   Rushtp #3 - Nextion Intelligent - Photo Frame ExPicture Files From the SD Card
   Rushtp #4 - Nextion Intelligent - Photo Frame Transition Effects
   Rushtp #5 - Nextion Intelligent - Photo Frame Algebraic Transition Effects
   Rushtp #6 - Nextion Intelligent - Photo Frame Record & Playback Transition Effects


Here is a summary of the functions, objects and the more Intriguing attributes used during these projects:


File & Tools Toolbox Objects & Events Intriguing Attributes
Visual SD Card Folder
Font Generator
Picturebox (format to .xi}

Events
Debug

Display
Program.s

Pictures
Fonts
Page A Text
123 Number
Button
ExPicture
FileBrowser
Variable
Timer
  vis
  click
  if() else
  for()
  delay
  conv
  spstr
  randset
  rand

DataRecord
  .insert(string newtxt)
  .delete(int strid, int qty)
  .up(string newtxt, int index)
  .clear()
.x
.y
.vscope
.sta
.aph
.effect
.style
.font
.drag
.key (keybdB)
.dir
.qty
.tim
.en
.path
.dez
.order
maxval

etc…


Look out for my other projects at Rushtp # - Instructables.com



Table of Contents

Download Worked Example

Guide.jpg
16a..jpg


You can download the Nextion HMI file and Photo files for this project using the links below.


Note: the Nextion display will not need to be re-programmed to add or change the photos. Just resize (800x480 pixels) and convert to “.xi” file format and put them on the SD Card.


If you have not completed that project you can download the Nextion HMI file and Photo files for this project using the links below.

Rushtp6.zip

Note: This file has been saved as a .zip file.

  1. Open the .zip file
  2. Then Extract all
  3. Open Rushtp6.HMI in the Nextion Editor
  4. Select File, Virtual SD Card Folder and create a folder called xi Photos
  5. Copy and Paste the extracted photo files into the xi Photos
    (Photo-1.xi, Photo-2.xi, Photo-3.xi, etc…)


Top Tool Bar

 File, Virtual SD Card Folder

	folder		sdcard0
	new		Folder
	folder name	"xi Photos"
	add files	“Photo-1.xi”
			“Photo-2.xi”
			“Photo-3.xi”
			etc...


Open the Rushtp6.HMI file in the Nextion Editor and SaveAs Rushtp #6 - Nextion Intelligent - Photo Frame Record & Playback Transition Effects.HMI.

This file was developed for the Nextion Intelligent Series 7” display screen. To modify it for other size screen, or to include your own images, you will have to follow the whole Rushtp #3 - Nextion Intelligent - Photo Frame ExPicture Files From the SD Card project making adjustments for your screen size, and photos.


Table of Contents