TFT Bitmap Logo

This example for the Arduino TFT screen reads a bitmap file from a SD card and displays it on screen in a random location.

For this example to work, you need to save an image named "logo.bmp" to the root of the SD card. The SD card needs to be FAT16 and FAT32 formatted. See the SD library documentation for more information on working with SD cards.

Hardware Required

Circuit

Insert the SD card with the "logo.bmp" file into the SD card slot on the back of your screen.

Connect power and ground to the breadboard.

Connect the screen to the breadboard. The headers on the side of the screen with the small blue tab and arrow should be the ones that attach to the board. Pay attention to the orientation of the screen, in these images, it is upside down.

Connect the BL and +5V pins to power, and GND to ground. Connect CS-LD to pin 10, DC to pin 9, RESET to pin 8, MOSI to pin 11, and SCK to pin 13. If you're using a Leonardo, you'll be using different pins. see the getting started page for more details.

Click the image for a larger version

Code

To use the screen you must first include the SPI and TFT libraries. You also need to include the SD library to read the image from the card.

If the image information is valid, pick a random spot on the screen to display the image. To make sure all the image is drawn onscreen, take the dimensions of the image and subtract that from the screen's dimensions.

This example reads an image file from a micro-SD card
and draws it on the screen, at random locations.

In this sketch, the Arduino logo is read from a micro-SD card.
There is a .bmp file included with this sketch.
- open the sketch folder (Ctrl-K or Cmd-K)
- copy the "arduino.bmp" file to a micro-SD
- put the SD into the SD slot of the Arduino TFT module.

// try to access the SD card. If that fails (e.g.// no card present), the setup process will stop.Serial.print(F("Initializing SD card..."));if(!SD.begin(sd_cs)){Serial.println(F("failed!"));return;}Serial.println(F("OK!"));

// now that the SD card can be access, try to load the// image file.
logo = TFTscreen.loadImage("arduino.bmp");if(!logo.isValid()){Serial.println(F("error while loading arduino.bmp"));}}

voidloop(){// don't do anything if the image wasn't loaded correctly.if(logo.isValid()==false){return;}

Serial.println(F("drawing image"));

// get a random location where to draw the image.// To avoid the image to be draw outside the screen,// take into account the image size.int x =random(TFTscreen.width()- logo.width());int y =random(TFTscreen.height()- logo.height());