Loading a bit map from an SD card to a TFT display

I am using a UNO in conjunction with a 3.5 inch display. This works well except when I try to load a bit map image from an SD card. The image uses the arduino.bmp from the TFTbitmapLogo Arduino example file.

I get an error message at the line myGLCD.drawBitmap(0, 0, 32, 32, “arduino.bmp”)

Maybe I need to convert the .bmp file to another form for this to work but am a bit lost.

Has anybody any ideas how I can load this image?

/*--------------------------------------------------------------
  Program: TFTimageLoad
  Uses Color TFT LCD 480x320 and UNO
  Note that A3 is the chip select for the TFT using a UNO
  --------------------------------------------------------------*/
#include <UTFTGLUE.h>              //use GLUE class and constructor
UTFTGLUE myGLCD(0, A2, A1, A3, A4, A0); //all dummy args
#include <SPI.h>
#include <SD.h>
#include <avr/pgmspace.h>
#define sd_cs  10

// Declare which fonts we will be using
extern uint8_t SmallFont[];

void setup() {
  myGLCD.InitLCD();
  myGLCD.clrScr();

  Serial.begin(9600);
  while (!Serial) {
    // wait for serial port to connect. Needed for native USB port only
  }
  // 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!"));


  myGLCD.setColor (255, 255, 255);
  myGLCD.drawBitmap(0, 0, 32, 32, "arduino.bmp");

  delay(1000);
} //end setup


void loop() {

} //end of void loop

//-------------------------END PROGRAM

.BMP is a common graphics format that can be rendered on your PC.

Note that the PC can render many styles of .BMP e.g. 24-bit colour, 16-bit colour, 8-bit palette (256 colours), 4-bit palette, 1-bit palette, ...

Most microcontroller programs only support 24-bit colour e.g. Adafruit examples. I support many different formats in the MCUFRIEND_kbv examples.

drawBitmap(), drawXBitmap(), drawGrayscaleBitnap, drawRGBBritmap() are different methods from the Adafruit_GFX class. These are for monochrome, grayscale and RGB bitmaps and completely different to the .BMP that you find on your PC.

I provide an example to show (most of) these methods.

I suggest that you run all the relevant examples. That is what they are there for !!

I provide UTFTGLUE class to ease porting of legacy UTFT programs. Although UTFT has two drawBitmap() methods, UTFTGLUE only supports the simpler one. And in true UTFT style its drawBitmap() method does not follow any known convention. I suggest that you do not use UTFTGLUE in any new projects.

Since you are storing images on SD card, I suggest that you use the world-recognised .BMP format. All Paint and Art programs on the PC should be able to store in this format. And the relevant decoding information is part of the .BMP format e.g. dimensions, colour-depth, ...

I provide several examples with the MCUFRIEND_kbv library. I would appreciate feedback. Then I could make them easier to understand.

David.

Thanks David,

I have had a look at a number of examples in MCUFRIEND_kbv library. The one most relevant for my task appears to be ShowBMP_kbv_Uno. This is very comprehensive and I am in the middle of working through it.

There are so many options in that example with many "bells and whistles" that make it hard to take in but I am working on it. It's a pity that there isn't an ultra simple "Noddy" type example for relatively inexperienced people like myself that could be used as a starting point.

I need to devote some time to this and I do appreciate the expertise of people like yourself that post such a wealth of information.

I will keep you posted on my progress.

No problem. Just look at the equivalent example from the Adafruit_TFTLCD library.

From memory, it just displays one .BMP from SD

It is much simpler to read.

I would appreciate some feedback.
Examples can either be very simple or comprehensive.

My “graphictest_kbv” tests every MCUFRIEND_kbv method and most of the Adafruit_GFX methods.
This means that it is big and unwieldy. On the other hand, if someone posts a video I can see exactly where any problem lies. ( people are always finding new and undocumented controllers )

David.

The Adafruit_TFTLCD library doesn't support my 9486 display. Examples compile OK but alas no bitmaps are displayed. These examples are just as complex as ShowBMP_kbv_Uno so they haven't helped. I realise that it is very hard to produce simplified examples as there are so many variations in user hardware that need to be accommodated.

With ShowBMP_kbv_Uno which works OK displaying bitmaps, is there a way to centralise a bitmap image or make it fit the display to make it look more presentable?

Using a UNO means that the software necessary for TFT and SD combinations chew up most of the UNO memory thus little is left to do other tasks.

Well, I will continue on trying to understand the software despite my brain hurting.

Thanks again David.