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
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:
- Cheap Controls Tutorials - #115 Nextion Display DataRecord elements
- Symbols ▼ and ▲ - W3Schools Tutorial (UTF-8 Geometric Shapes)
- 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
Supplies
- Nextion Intelligent 7" Touch Screen (e.g. NX8048P070-011C)
- USB to TTL CP2102 UART Module 5Pin Serial Converter
- USB extender cable (3m)
- 20mm clear heat Shrink tube (Optional)
- Nextion Editor (Download)
- Nextion Editor Guide
- Nextion Instruction set
- 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.
Nextion Editor - Load the Rushtp #3 Photo Frame Project Files
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. Note: This file has been saved as a .zip file.
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. |
Nextion Editor - Shorthand Conventions I’ll Be Using…
The Nextion Editor has a number of display areas that contain objects, actions, files or code.
- File
- Tools
- Toolbox
- Display
- Program.s
- Page
- Attribute
- Event
- Pictures
- 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)
|
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.
Nextion Editor – Creating a New Font
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 |
Nextion Editor – “Clear the Decks”
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!
|
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!
Nextion Editor - Dragging and Tracking
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.
|
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…
|
|
Then Copy and Paste again to create t3(Text) and t4(Text). Then edit the attributes sta, txt, x, y, etc…
|
|
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”).
|
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.
|
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…
|
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).
Nextion Editor – Creating a DataRecord
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.
|
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.
|
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:
- 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. |
| |||||||
| 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). |
|
|
| |||||||||||||||||||||||||||||||||||||
| 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... |
| |||||
Nextion Editor - Coding a Counting Down
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 } |
OK!
Nextion Editor - Exploring Data Recording
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.
|
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.
|
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.
|
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.
Nextion Editor - Play Back
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
|
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.
|
Your data will be different to this! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Give it a try in Debug.
Nextion Editor - Navigating and Deleting
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.
|
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)
|
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)
|
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.
|
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.
|
| Note: you can drag the data rows up and down to view the hidden entries in the record table' |
Nextion Editor - Edit and Update With Numeric Keyboard
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:
- 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)
|
|
|
|
| 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.” |
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.
Setup the Transitions
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.
Tap on the Screen to Toggle the Controls ON/OFF
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!
Upload to a Nextion Intelligent 7" Touch Screen
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.
|
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. | ||||
| The folder Recordings exists and a new empty 1.data file has been automatically created. | ||||
| 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. |
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
Download Worked Example
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. Note: This file has been saved as a .zip file.
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. |