I got the application working in the Arduino IDE with the QTPy based on the SAMD21 CPU. Then, I got to handle the directory listing and file selection. That's when things got much more painful.
If the number of files on the SD card was small enough it wouldn't be a real problem but the use-case here is where there are dozens of files. For example. I've got 165 programs that could be downloaded to my MultiComp UK101 board.
The directory contents need to be stored into a list and C/C++ just isn't all that great at handling lists because everything list related in C++ is DIY. And it just gets more painful if the lists start to get longer. because there is only 32KB of SRAM in the SAMD. I really wanted to switch over to MicroPython or CircuitPython to take advantage of easier list processing. But the SAMD just doesn't have enough internal SRAM to run either Python variant.
RP2040 to the Rescue
Fortunately, there's an RP2040 version of the QT Py. The RP2040 is the same CPU used in the Raspberry Pi Pico and it's more than capable of handling this task. There's a $5.40 version of the card by Seeed Studio. The RP2040 CPU chip itself is more widely available than the SAMD used on the original QT Py.
So I am making the switch to the XIAO RP2040 by Seeed Studio and CircuitPython. The Adafruit RP2040 card is more expensive (at $9.95) and frequently out of stock (it is at the moment). So I bought 5x of the Seeed Studio XIAO RP2040 cards to play with.
If someone wants to try the code but doesn't want to replicate the MyMenu card they could use a Raspberry Pi Pico card. There's enough more than enough Digital I/O pins on the card to replicate the switches. In fact, our PiPicoMite01 or PiPicoMite02 would do the job quite nicely.
MyMenu Example code
I re-wrote the MyMenu example code to run on CircuitPython. The example code reads the 5 pushbuttons and puts a pattern on the 3 LEDs as well as printing which button was pressed to the OLED. It works well.
The framebuff has a 5x8 character set allows 21 columns and 8 rows to characters to be displayed on the OLED.
SD Card Code
The SD card code was particularly easy to get working since the example code just worked with no issues. Adding the path and file name as pairs to a list was also easy.
Here's the result of running the code:
Files on filesystem: ==================== System Volume Information/ Size: 0 by WPSettings.dat Size: 12 by IndexerVolumeGuid Size: 76 by SuperStarTrek.bas Size: 20.0 KB scramble.bas Size: 19.2 KB CivilWar.bas Size: 13.5 KB dirFileNames [('/sd', 'System Volume Information'), ('/sd/System Volume Information', 'WPSettings.dat'), ('/sd/System Volume Information', 'IndexerVolumeGuid'), ('/sd', 'SuperStarTrek.bas'), ('/sd', 'scramble.bas'), ('/sd', 'CivilWar.bas')] ('/sd', 'System Volume Information') ('/sd/System Volume Information', 'WPSettings.dat') ('/sd/System Volume Information', 'IndexerVolumeGuid') ('/sd', 'SuperStarTrek.bas') ('/sd', 'scramble.bas') ('/sd', 'CivilWar.bas')
The first dirFileNames is as a list of pairs of (path, fileName). The next is that list line-by-line.
Created separate folders and made a list of the paths.
['/sd', '/sd/a_b', '/sd/c_f', '/sd/g_l', '/sd/m_q', '/sd/r_s', '/sd/t_z']
Moved files grouped into each folder. Organized so that there's around 30 files in each folder. This should make stepping through the files easier on the OLED which only has 8 lines.
Folder, File selection working
I got the folder and file selection working with the MyMenu pushbuttons from the REPL.
Added a high-level wrapper to call the file selector, File send function (not written yet), and COM port config (not written yet).
Checked in the code (ZIP file here).