Rushtp #3 - Nextion Intelligent - Photo Frame ExPicture Files From the SD Card

by Rushtp in Circuits > Gadgets

269 Views, 1 Favorites, 0 Comments

Rushtp #3 - Nextion Intelligent - Photo Frame ExPicture Files From the SD Card

0c. video.gif
0a. IMG_0778.JPG
Photo-1.jpg

Background

The Nextion Intelligent Series displays have the ability to read files stored on the built-in micro SD card. Up till now the SD card reader could only be used to load the firmware TFT file.

So can it be used to make a digital photo frame? Well, Yes! Using a new “ExPixture” object in the Nextion Editor Toolbox... and this is how it can be done using a 7” display screen…

Supplies

0d. 51QEelwMRaL._AC_SX679_.jpg
0e. 71snV7W18vL._SX522 - Copy.jpg
0f. USB Extender Cable_.jpg
0g. IMG_0723.JPG
  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. Nextion 7” Display DIY Enclosure (Optional)
  5. 20mm clear heat Shrink tube (Optional)
  6. Nextion Editor (Download)
  7. Nextion Editor Guide
  8. Nextion Instruction set
  9. Adobe Photoshop Elements (NOT Adobe Premiere Elements!)
  10. 32GB Micro SD Card (FAT32 format) Search

Nextion Display Set Up

1a. Wiring.bmp
1b. USB Connections.bmp
1c. 71snV7W18vL._SX522.jpg
1d nextion-pins.bmp

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 – About the Photo Files

2a. Photos.jpg
2b. Virtual SD Card Folder.jpg
2c. Converted Photos.jpg
2d. Untitled-1.jpg

The photo images have to be resized to match the “ExPixture” object dimensions in the Nextion Editor.

To program the Intelligent Displays the newer version of the Nextion Editor has a Virtual SD Card Folder.

Although the Nextion Intelligent Series can read files from it’s built-in SD Card reader they have to be in a “.xi” file format.

In this project only one screen page will be used, “page0” and we will add a background image. It will not be displayed on the finished Photo Frame but is make it easier to see the objects we will use in programming the display.

Nextion Editor – Create a New Project

3a. 1.jpg
3b. 2.jpg
3c. 3.jpg
3d. a4.jpg

Create a new project file “Nextion Intelligent - Photo frame ExPicture files from the SD Card.HMI

Select the NX8048P070_011 model and the display direction 0 Horizontal.

Note the page0(page) dimensions – 800 x 480 pixels. The background image has to be resized to these dimensions.

Save the project file. We will come back to it in Step 5.

Photoshop Elements – Resizing the Page0 Background File

4a. Untitled-1.jpg
4b. Untitled-2.jpg
4c. Photoshop New 800x480.jpg
4d. Drag it.jpg
4e. Untitled-2.jpg
4f. Background Image.jpg
4g. Untitled-1.jpg

Before we start, the screen page background will not be stored on the SD Card it will be held in the display memory.

Create a New, Blank File Photoshop Elements the same size as in page0 - Step 3 in the Nextion Editor - 800 x 480 Pixels.

Open an image file for the page0 background and drag it into the new Blank File tab.

Then select View, Fit on Screen and drag the corners until the background image just covers the Blank file outline. Now using SaveAs save it as Background (800x480).jpg.

Nextion Editor – Setting Up the Photo Frame Background

5a. Untitled-1.jpg
5b. Untitled-1.jpg
5c. Untitled-2.jpg

In the Nextion Editor Open the project file “Nextion Intelligent - Photo frame ExPicture files from the SD Card.HMI”.

In the Picture section select “+Add and load the Background (800x480).jpg file.

In the Attribute, page0(Page) section change the “sta” to image and set “pic” to 0.

This sets the page background image.

Nextion Editor – Create the ExPicture Object to Display the Photo Frame Files

6a..jpg

In the Toolbox create an ExPicture object set the origin to 0x0 and resize it to 800x480.

Note that the ExPicture object now fills the page0 background exactly. That is why the background image will not show when the Photo Frame is running – the photo files will cover it.

File, Save the project (“Nextion Intelligent - Photo frame ExPicture files from the SD Card.HMI”).

Photoshop Elements – Preparing the Photo Frame Files

7a. Photo files.jpg
7b. Original photos.jpg
7c. photos.jpg
7b Blank.jpg

To make the process easier to handle create a new folders on your PC.

  1. Original photos
  2. Resized photos
  3. Xi Photos

In Photoshop Elements and drag the original files in (in my case there are only 11 files).

Create a blank file 800x480 pixels - File, New, Blank File, Width = 800, Height = 480

Copy the original photos you want to add to the photo frame into a folder called “Original photos”.

Photoshop Elements – Resizing the Photo Frame Files

8a. Untitled-2.jpg
8b. Untitled-2.jpg
8c. Untitled-2.jpg
8d..Untitled-2.jpg
8e. Untitled-2.jpg
8f. Untitled-2.jpg

In the same way we did in Step 4 the photo files need to be resized them to 800x480 pixels.

Select the first image loaded (it is in the Tab left of the Blank background Tab) and drag it into the Blank background Tab. If the dragged image is too big to fit in the Blank background select View, Fit on Screen and drag the corner handles to resize. You may have to select Fit on Screen a couple mote time to see more clearly.

File, Save as “Photo-1.jpg” in the “Resized photos” folder.

Delete the original photo Tab (click on the “X”).

Delete the Photo-1 layer 2 to leave the Blank background.

Repeat the process with each of the remaining original photo Tabs.

Remember to save the files in sequence "Photo-2.jpg, Photo-3.jpg, Photo-4.jpg,….”

Nextion Editor – Converting the Photo Frame Files to “.xi” Format

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

Open the project file “Nextion Intelligent - Photo frame ExPicture files from the SD Card.HMI” in the Nextion Editor.

Next select Tools, Open PictureBox and Add all the resized and renamed photos and Open.

Now press Start to convert and put the converted “.xi” files in the “xi Photos” folder.

Nextion Editor – Copy the “xi Photos” Folder Into the Virtual Sd Card Folder and a Micro SD Card

10a. Untitled-7.jpg
10b. Untitled-8.jpg
10c. Untitled-1.jpg

Select File, Virtual SD Card Folder and drag the “xi Photos” folder into it.

Check all the converted photo files are there.

Windows PC – Copy the “xi Photos” Folder Onto a Micro SD Card

11a. IMG_0768.JPG
11b. IMG_0795.jpg
11c. Untitled-1.jpg
11d. Untitled-2.jpg
11e. IMG_0775.JPG

Format the 32GB Micro SD Card file system to FAT32.

Copy the “xi Photos” folder into it and check converted photo files are there.

Install the SD Card in the reader on the Nextion Intelligent 7" Touch Screen (e.g. NX8048P070-011C)

Nextion Editor – Add and Format 4 Toolbox Objects

12a. Untitled-1.jpg
12b. Untitled-2.jpg
12c. Untitled-1 (2).jpg
12d. Untitled-9.jpg

In the Toolbox click on:-

  1. 1x Button - drag it into position, change the txt Attribute to “Photos” and resize w80 x h30
  2. 1x Number - drag it into position and resize w40 x h30
  3. 2x Variable – Change va0 objname to “FileNr”, va1 objname to “tFileNr” and it’s sta to String

The tool bar just above the Toolbox can be used to align and space objects on the screen page.

Variables appear below the screen page and are invisible when the display is running.

Now click on the Compile button on the top tool bar.

If you get error messages “…invalid Font ID” go to Step 13 to generate some text fonts.

Nextion Editor – Adding Fonts…

13a. Untitled-2.jpg
13b. Untitled-9.jpg
13c..jpg

Select Font Generator from the Tools tab

  1. Height 16
  2. Encoding utf-8
  3. Font Arial
  4. Name “Arial16
  5. Generate font – and Add the generated font

Repeat for “Arial32b(Bold)

Now click on the Compile button again and the errors should clear.

Nextion Editor – Now We Can Start Programming the Photo Frame

14a. Untitled-1.jpg
14b. Untitled-2.jpg

Click on the Photos button and copy and paste the following code into the Touch Release Event code area.

Note: do NOT add extra spaces in the code (e.g. “If<space>(FileNr…” will case a Compile error!). There is a space after the convert statement “conv”.

Touch Press Event(0)Touch Release Event(8)

FileNr.val++

n0.val=FileNr.val

covx FileNr.val,tFileNr.txt,0,0

if(FileNr.val>=11)

{

 FileNr.val=0

}

exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"

 

 

- Increment by 1 when Photos button is clicked

- Copy FileNr to n0 on the screen

- tFileNr =Convert a number to a string (text)

- 11 is the number of photo files on SD Card

 

- Reset the photo file number to 0

 

- Display in sequence Photo-1, -2,-3, -4, … etc.

By converting FileNr into text (tFileNr) it can be used to change the photo file name selected for display.

Nextion Editor – Run the Code in Debug

15a. Untitled-1.jpg
14b. Picture1.gif

Run Debug and press the Photos button repeatedly.

If all goes well you should be able to skip through the Photo files stores in the Virtual SD Card Folder.

Nextion Editor – Upload Into the Nextion Display

16a.Untitled-1.jpg
16b. IMG_0796.JPG
16c. Nextion Video.gif

WARNING! – The first time you use the Upload option process can take a long time to complete. In my case it was 23 minutes! …so go and make a cup of tea while you wait.

However, subsequent uploads only take a few seconds as it appears that only changes are uploaded.

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.

First Review

Well, that proves a Photo Frame can be programmed to use the built in SD card.

But, there are a number of improvements we need to make:

  1. Automatically count the files stored on the SD Card
  2. Auto run the photo files in Serial and Random
  3. Hide the Photos button and the file count n0 while the frame is running
  4. Add special effects as each photo is loaded (This will be covered in a future project)

Nextion Editor – Automatically Count the Files Stored on the SD Card

17a. Untitled-1.jpg
17b. Untitled-2.jpg
17c. Untitled-6.jpg
17d. Untitled-2.jpg
17e. Untitled-1.jpg

From the Toolbox add a FileBrowser and press OK to add two pictures to Picture list.

Position and size fBrowser0 above the existing Photos button.

Set the dir attribute to “sd0/xi Photos/ “.

 

To get the file count from the SD Card “xi Photos

folder put this code into the fBrowser

object Touch Release Event code area.

 

Note that the file count will only be retrieved when

the fBrowser object is Clicked.

TouchPress Event(0) TouchRelease Event(8)

 

 

fCount.val=fbrowser0.qty

 

 

Add a new Text object and set the background to transparency and set the size to w40 h30 pixels.

Set the font to 1 and the pco colour to white (Font 1 is the Arial32b we created earlier in Step 13).

Add a Number object and name it fCount and set the size to w40 h30 pixels.

Use the align tools to position the new objects in line with the Photos and n0 objects.

 

 

Click on the Photos button and replace the “11

with “fCount” in the Touch Release Event code

area.

//” is used to start a comment in the code and

the rest of code in that line is ignored when the

program runs.

Touch Press Event(0) Touch Release Event(8)

FileNr.val++

n0.val=FileNr.val

covx FileNr.val,tFileNr.txt,0,0

//if(FileNr.val>=11)

if (FileNr.val>=fCount)

{

 FileNr.val=0

}

exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"

Click on the Compile button and ensure there are no errors in the Output area.

If there are errors double click on the red error text and the cursor will jump to the defective code.

e.g. Error:Invalid Variables:fCount.val( Double click to jump to code)
       Error:Compile failed! 1 Errors, 0 Warnings

Nextion Editor – File Count

19a. Untitled-1.jpg

Select Debug and check it out. Initially the file count is 0, but click anywhere on the browser and it will display the file count in the “sd0/xi Photos/” folder. In my case the file count is 12 because I added another resized and converted photo (Photo-12.xi).

Now we need to set up the programming to “Click” and hide the browser object.


Nextion Editor – Hide the File Browser With Click and Vis (Click and Hide)

20a..jpg
20b..jpg

In the Attributes area select Page0(page).

Then select the Postinitialize Eventtab and add the following code:

preinitialize Event Postinitialize Event Touch Press Event Touch Release Event Page Exit Event

vis fbrowser0,0

click fbrowser0,0

 

 

vis<object>,0 to Hide.

vis<object>,0 to action.

click fbrowser0,0

Use Debug  and confirm it The file browser object fbrowser0 is hidden.

Nextion Editor – Automate the Slide Show (The ON/OFF Buttons)

21a. Untitled-3.jpg
21b. Untitled-1.jpg
21c. Untitled-2.jpg
21d. Untitled-1.jpg

Close the Debug screen.

Now add two more buttons (b1 and b2). Then position and resize them to w90 and h30. Align them below the Photos button. Use the Align tools to refine the three button positions.

To improve the button layout resize the “Photos” button too.

Note: Holding the “ctrl” key allows all three buttons to be selected for fine tuning the alignment – remember to de-select by clicking outside the display area.

Change the txt attribute on the new buttons to “Serial OFF” and “Random OFF”.

In the button Touch Release Events add the following code:

 

 

Button b1

TouchPress Event TouchRelease Event

b2.txt="Random OFF"

if(b1.txt=="Serial OFF")

{

  b1.txt="Serial ON"

}else

{

  b1.txt="Serial OFF"

}

 

 

Button b2

TouchPress Event TouchRelease Event

b1.txt="Serial OFF"

if(b2.txt=="Random OFF")

{

  b2.txt="Random ON"

}else

{

  b2.txt="Random OFF"

}

 

 

Button b0 (Photos)

add the following

two lines to the

existing code:

b1.txt="Serial OFF"

b2.txt="Random OFF"

Touch Press Event(0) Touch Release Event(8)

b1.txt="Serial OFF"

b2.txt="Random OFF"

FileNr.val++

n0.val=FileNr.val

covx FileNr.val,tFileNr.txt,0,0

//if(FileNr.val>=11)

if (FileNr.val>=fCount)

{

 FileNr.val=0

}

exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"

Test the buttons out in Debug.

All that happens is that the buttons toggle their text …ON / …OFF.

Nextion Editor – Automate the Slide Show (The Magic)

22a .Untitled-1.jpg
22b. Untitled-1.jpg

Add two new objects from the Toolbox – Timer tm0 and Variable renamed to visState.

Set the timer attribute tim to 3000 millisecond (this is the photo display time).

To the Timer Event add the following code:

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

  }

  exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"

}

//----------------------------------------------------------

if(b2.txt=="Random ON")

{

  randset 1,fCount.val

  FileNr.val=rand

  covx FileNr.val,tFileNr.txt,0,0

  exp0.path="sd0/xi Photos/Photo-"+tFileNr.txt+".xi"

}


- Check if Serial is ON


- Increment the file number by 1

- Pass the file number to n0 on the screen

- Convert the file number to text in tFileNr

- If the file number exceeds the number on the SD Card


- Set the file number to 0


- Display the file


//----------------------------------------------------------

- Check if Random is ON


- Set the Random range (1 to 12 in my case)

- Get a random file number

- Pass the file number to n0 on the screen

- Convert the file number to text in tFileNr

- Display the file


Select the ExPicture object exp0 in the Attributes list.

To toggle the screen objects between visible and hidden when the ExPicture (exp0) is touched add the following code to the Touch Release Event area:

TouchPress Event TouchRelease Event

if(visState.val==0)

{

  vis b0,0

  vis b1,0

  vis b2,0

  vis n0,0

  vis t0,0

  vis fCount,0

  visState.val=1

}else

{

  vis b0,1

  vis b1,1

  vis b2,1

  vis n0,1

  vis t0,1

  vis fCount,1

  visState.val=0

}

- Check if the visibility state is 0 (ON) or 1 (OFF)


- vis <object ID>,0 to Hide






- Reset the visibility state for next time the picture is touched



- vis <object ID>,1 to Show





- Reset the visibility state for next time the picture is touched

Nextion Editor – Finished and Final Review

23a. Debug Video.gif
23b. Untitled-1.jpg
23c. IMG_0805.JPG
23d. (1).gif

First try it out in Debug to ensure it all works.

Then upload it took 23 minutes again! …so time for lunch.

And Finally The photo Frame Works.

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

So can it be used to make a digital photo frame?     ...Yes it can!

In the next project I will show how to add special effects as each photo is loaded.