Start a new topic

"File Selection Dialog"

I thought I'd share my "file selection dialog" implementation via video - see - here it is running attached to an Arduino with a SD card. The "dialog" is displaying files from the SD card and allowing selection of one of them.  If there's interest, I would be willing to make this a stand-alone demo to assist others with similar requirements but who aren't quite sure how to make it work.

Let me know.

1 person likes this idea

I would consider this for the Nextion Gallery

You should create a still picture or two along with an mp4 video format and description.

(Many do not have access to Google's youtube - Nextion is global.)

The video I did is 16MB and rejected by the forum as too big. 

even a video can be reduced in size by choosing a different format, codec or just it's size ... :-)

    - Xvid AVI, DivX AVI, H256 mp4 ...

And in worst case you even can use WinZIP or WinRAR and post the compressed archive ... :-)


What is the forum file size limit?  The video is 2 minutes long, already reduced in size to 640x360 and MP4 H.264 codec. I don't think there's much saving to be had by fiddling with formats/codecs.

there are many ways you still can save size ... :-)

even such simple than save without audio track will save a lot ...

and there is no need for 640x360, 320x240 will do it similar ...


for the limit .... mhmhmhmhmh 


Thanks for the limit info.  I did a nice 2 minute video with an explanatory audio saying how it worked, how to use it, etc., so dumping the audio track would be kind of pointless. I'm just going to skip the video and put up the HMI file and a pic.  Should be up soon.

Here is the source code and the HMI file for the "dialog" selection menu system that I wrote. I have made it into a stand-alone item with no dependencies other than the Nextion library. I run on an Arduino Micro - you may very well need to modify the Serial output debug stuff for it to work for you.  The attached video just runs through the dialog in action, showing the return/send values from the Arduino in the serial monitor on my laptop.


You're not going to have much luck just compiling the HMI and putting it on your Nextion - because this system relies on two-way interaction between the Nextion and the microcontroller.  The Nextion "requests" new menu lines as you scroll up and down, and the MC provides those lines. When you select a line, it's the MC that actually knows what you have really selected.

The code is reasonably well commented, and hopefully easy to understand.  I used Nextion Editor V0.46 for this work.

There are a few bugs on startup, related to the inability of my code to retrieve variables from the Nextion. Perhaps a timing issue - I do not know. It's documented in the comments - and you will note that I have written the code so that these issues do not matter - the system works perfectly even with the failed reads.  I'd sure like to know what I'm doing wrong, though :P

Released to the public domain. Pay it forward.


Updated because I found a bug - not a bug that would actually cause a problem, but something that wasn't quite right.  I also took the opportunity to remove the "ref" commands from the nextion-side of the scroll/refresh, because I realised that components refresh automatically when changed.  Should be ever so slightly quicker now, too.  Final change was to rename a variable in the Arduino code because it was a system variable ("update") and seemed prudent to fix that.

Tested, seems OK.


Here's the menu code running on my mechanical television allowing selection of a file from the SD card and subsequently playing on the televisor "display".


Just a though, and it won't take you long to find if it works or not.

In place of the delay(1000), try a Serial clear-down on the Nextion Serial buffer with...

while (Serial.available());

Where Serial is replaced with Serial1 or whatever Nextion is connected to.

I'm thinking that when you power up the Nextion, there is some initialising data sent by default, goes something like...

00 00 00 ff ff ff 88 ff ff ff 

This will will arrive back in the Arduino buffer, and needs clearing before you can read the callbacks properly.  


I pretty much completed my original project UI which was the original reason for developing this "scrolling text" selection system.  I thought I'd share a video (see attached) as the end result is pretty cool, at least in my opinion. The Nextion has provided a great little UI for my project and despite its little quirks I have become rather fond of it.  I have certainly learned a lot about the "hidden internals" and how to make it sing.


Just thought I'd mention a bit about the fonts used;  there's a fantastic monospaced free font called "Ubuntu" which translates with the font tool very well indeed. In the "info" screen you see in this video, I also used "x-centering" on each line, so even though monospaced fonts are used, the staggering of the character positions on a line-by-line quite nicely obscures the visually jarring effect of monospacing.

Discussion please

 - visual jarring effect of monospacing

I am not certain how many programmers would program without fixed width monospacing

Certainly not me!  I'd spend days hunting a nice font before writing a line of code.

Monaco is a nice one!

Login or Signup to post a comment