Running on an error with a piece of code / TFT / SD / Nano / slide Show

Hi there,
I´m a bloody beginner to Arduino, Coding and all things around these themes.
I tried to get a code working, which was posted long time ago.
My Plan:
I would like to take an Arduino Nano (link will follow), a TFT-Display with SD Card reader, put it all together, just to run a “slide show” of various BMP pictures.

My hardware:
Nano (Nano)
Display (Display)

I tested my display and the nano with other Sketches, everything works fine.

The Sketch, which I think, might be useful and sufficient, is one out of an other topic, which is already closed:

In #20 of above topic, David Prentice released a Sketch, which I used for my “slide show”, and it nearly runs perfect like I need it.

This one works fine, but after the nineteenth BMP-file I will see a “load.image error”
It doesn´t matter if I have 4 or 9 or 11 BMP-files (128x160px, 24bit, SD 128MB, formatted in FAT32). Every time the script is running, after the 19th BMP this error occurs.

I´m just an beginner, and I don´t know how to fix this… I would be extremely happy, if someone would help me here.

Thank You so much, and enjoy the weekend…

The Sketch is:

#include <SPI.h>
#include <SD.h>
#include <TFT.h>

#define TFT_CS 10
#define TFT_DC  9
#define TFT_RST 8

#define SD_CS   4

#include <TFT.h>

File root;
int pathlen;
char namebuf[32] = "/";   //BMP files in root directory
#define NAMEMATCH ""      // "" matches any name

void setup(void)
    bool good = SD.begin(SD_CS);
    if (good) {
        root =;
        pathlen = strlen(namebuf);
    if (!good) {
        Serial.println(F("cannot start SD"));
        while (1) yield();

void loop()
    char *nm = namebuf + pathlen;
    File f = root.openNextFile();
    uint8_t ret;
    uint32_t start;
    PImage myPicture;
    if (f) {
        strcpy(nm, (char *);
        if (strstr(nm, ".bmp") != NULL && strstr(nm, NAMEMATCH) != NULL) {
            myPicture = tft.loadImage(namebuf);
            tft.image(myPicture, 0, 0);
    else root.rewindDirectory();

Yes, the TFT.h program crashes after about 18 or 19 images.

Quite honestly the TFT.h library that comes with the IDE is complete crap.
It comes with obsolete versions of Adafruit_GFX and Adafruit_ST7735 and slaps some Processing's PImage stuff on top.

Most importantly:

  // TODO close the file in ~PImage and PImage(const PImage&)

which is probably why everything crashes after a while.

Please edit the sketch loop() function in #0 e.g.

        if (strstr(nm, ".bmp") != NULL && strstr(nm, NAMEMATCH) != NULL) {
            myPicture = tft.loadImage(namebuf);
            tft.image(myPicture, 0, 0);
            myPicture.close();  //.kbv close the file after we have drawn it.

Yes, it is quite handy to have loadImage() and image() methods but it still means that TFT.h is an almighty hack.
I would be much happier with a "User function" and a regular Adafruit_ST7735.h library.


Oh WOW!!

Thank You sooo much, David!

Now it works really fine. It is running since hours and there are no more problems.

Thank You!!!!!

Greetings from Germany


This topic was automatically closed after 37 days. New replies are no longer allowed.