View images from SD card on TFT display

Hi, I'm have a lot of trouble trying to load an image from an SD card on a Due with 5" touch screen.

I've started my sketch and have sucessfully got the screen working, touch working and I'm able to read a file from the SD card so everything is working, now I simply want to load an image from the SD card but how?

I've been searching for the last couple days and trying different libraries but getting now where.

I have to say Arduino could have used a better name that Due, its impossible to use google for anything relevant because of this.

I should also mention I’m using the following libraries.

#include <SPI.h>
#include <SD.h>
#include <UTouch.h>
#include <UTFT.h>

You can search google for arduino specific terms by trying the following.

site:arduino.cc due tft sd image

A little more information might help, what have you tried so far? Some example code for example.

Regards,

Graham

If you are interested, I made a modified version of UTFT_tinyFAT which takes rgb565 raw images from SD using SdFatlib.

SdFatlib available here..... https://github.com/greiman/SdFat

SdFatlib is just a newer/faster version of SD included with Arduino IDE.

You will quickly realise drawing large images on a 5" or 7" display is a slow job, any method of speeding it up is appreciated and sdfatlib is a good start! ;)

Regards,

Graham

Hi, thanks, I've tried a lot. I have switched to the SDFat that you pointed to as I saw a version of the UTFT_tinyFat that was suppose to work but doesn't. I always get compiling errors. Do you have a link to your UTFT_tinyFat library?

This was easy on the mega why so difficult on the due, literally its been days of trial and error.

robsworld78: I have switched to the SDFat that you pointed to as I saw a version of the UTFT_tinyFat that was suppose to work but doesn't.

Are you sure that is not my version you already saw? I have no link but can post a zip if you like. Regards, Graham

Yes please post a zip. I've tried quite a few versions not sure if yours was one of them.

Hi Rob,

I haven't abandoned you! I am trying to make an example sketch for you to show off all the functions I have made, only to discover I have a bug in one of the functions... :roll_eyes: I aim to have it fixed later this evening..... I will post when it works properly.

Regards,

Graham

Thank-you very much, this is very frustrating. I'm a little worried about my project, how am I suppose to do all the other things I plan when I can't even load an image, lol. :)

The mega2560 was easy, libraries worked but this due has proven to be rather difficult. I thought I would use the due for my project as I want to make a nice UI and the mega was on the slow side loading my images. I was under the impression the due would load images a lot faster. I don't need instant but would like to at least double the performance. Will this be possible?

Hi Rob,

What size images are you talking about? What model of TFT are you using? What Class of SD card have you got? All those things greatly influence the speed you can expect. I have a CTE 5" CPLD display, a Samsung Class 6 32GB SD card and to draw a 240x240 image is now taking about 125ms and 440x440 image is 420ms. Hope this is quick enough for you??!! ;) :P

Regards,

Graham

This is my sketch so far and it will compile until I start playing with images.

It won’t compile when I uncomment line 13 or any image calls.

#include <UTFT_tinyFAT.h>
#include <UTFT.h>
#include <SPI.h>
#include <UTouch.h>
#include <SdFat.h>

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

UTFT myGLCD(CTE50,25,26,27,28);   // Remember to change the model parameter to suit your display module!
UTouch  myTouch(6,5,32,3,2);
//UTFT_tinyFAT myFiles(&myGLCD);  // start up an instance to read images from the SD card

int x, y; //touch coordinates
int Xsize, Ysize;

// various millis to keep track of
unsigned long prevMillisTouch = 0; // track time between touches
unsigned long prevMillis5sec = 0; // track 5 seconds for refreshing clock and temp
unsigned long feedingMillis = 0; // track how long we've been feeding
unsigned long millisDim = 0; // used for brightness adjustment
unsigned long millisHome = 0; // used for returning home after configured time

// SD chip select pin
const uint8_t chipSelect = 53;

// file system
SdFat sd;

void setup() {
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
    
  myTouch.InitTouch();
  Xsize = myGLCD.getDisplayXSize();
  Ysize = myGLCD.getDisplayYSize();

  if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
 
  Serial.begin(9600);    
  
  Serial.println("card initialized.");

  // display home screen
  screenHome();  

  
}

void loop()
{  
  
  unsigned long currentMillis = millis(); // get current millis

  // check for touch events
  if (myTouch.dataAvailable())  {
    if (currentMillis - prevMillisTouch > 500) // make sure it's been .5 sec between touches
    {
      
      prevMillisTouch=currentMillis; // reset the touch timer
      millisDim=currentMillis; // reset screen dim timer
      millisHome=currentMillis; // reset return home timer
      
      processMyTouch();
    }
  }
}


void screenHome()  // draw main home screen showing overview info
{

  myGLCD.clrScr(); // clear the screen
   
  myGLCD.setColor(255,255,255);
  myGLCD.drawLine(0,360,800,360); // draw line above dock

 // myfiles.loadBitmap(0, 0, 800, 480, "test.raw");
 
 
  // myGLCD.loadBitmap(0, 0, 800, 480, "test.raw");
  
//  myGLCD.drawBitmap(0,0,128,128, "test.raw");

//  loadJpeg(myGLCD, "image15.jpg");
}

void processMyTouch() // this is a huge block dedicated to processing all touch screen events
{
  myTouch.read();
  x=myTouch.getX();
  y=myTouch.getY();
  Serial.print("X=");  
  Serial.print(x);
  Serial.print("  Y=");  
  Serial.print(y);
  Serial.print("\n");

  // initiate char vars for converting numbers to char for display
  char char3[3];
  char char3t[3];
  char char4[4];
  char char5[5];
}

This is what I'm working with, its all the bargin sainsmart.

Due: http://www.amazon.ca/gp/product/B00E37Y28M/ref=oh_details_o00_s00_i01?ie=UTF8&psc=1

Shield: http://www.amazon.ca/gp/product/B00E37Y28M/ref=oh_details_o00_s00_i01?ie=UTF8&psc=1

Screen: http://www.amazon.ca/gp/product/B00INMJHME/ref=oh_details_o01_s00_i00?ie=UTF8&psc=1

The screen I bought with the mega2560 and shield but now I'm using it on the due with due shield.

Currently I'm using an old 1gb kingston SD card, once I getting it working I'll get a high speed card possibly.

Those speeds look ok, my images are mainly icons no bigger than 96x96 but there will be quite a few of them. That's what slowed the mega down, it probably took 250ms per image, this sounds much quicker.

Although I was hoping for a transparent background filling the 800x480 but that sounds like it will be slow.

Rob,
Can you uncomment

UTFT_tinyFAT myFiles(&myGLCD);

and uncomment /edit the line …

myFiles.loadBitmap(0, 0, 800, 480, "test.raw");

Tell me what if any compiler errors you are seeing?

Regards,

G

EDIT: By the way, #include <SPI.h> achieves no useful purpose in IDE 1.5.7 besides increasing sketch size by 116 bytes… performance remains the same.

When I uncomment those lines these are the errors.

Arduino: 1.5.8 (Windows 7), Board: "Arduino Due (Programming Port)" Due_Controller.ino:12:1: error: 'UTFT_tinyFAT' does not name a type Due_Controller.ino: In function 'void screenHome()': Due_Controller.ino:78:3: error: 'myfiles' was not declared in this scope Error compiling.

I removed SPI.h and it still compiles if those lines are commented out.

Don't forget I might not be using your version, I believe this one belonged to jake1981.

First of all try this sketch.

#include <SdFat.h>
#include <UTFT_tinyFAT.h>
#include <UTFT.h>
#include <UTouch.h>

UTFT myGLCD(CTE50, 25, 26, 27, 28); // Remember to change the model parameter to suit your display module!
UTouch  myTouch(6, 5, 32, 3, 2);
UTFT_tinyFAT myFiles(&myGLCD);  // start up an instance to read images from the SD card

// SD chip select pin
const uint8_t chipSelect = 53;

// file system
SdFat sd;

void screenHome()  // draw main home screen showing overview info
{
  myGLCD.clrScr(); // clear the screen
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawLine(0, 360, 800, 360); // draw line above dock
  int mytime = millis();
  myFiles.loadBitmap(0, 0, 800, 480, "test.raw");
  Serial.println(millis() - mytime);
}

void setup() {
  myGLCD.InitLCD();
  myTouch.InitTouch();

  if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
  Serial.begin(9600);
  Serial.println("card initialized.");
  // display home screen
  screenHome();
}

void loop()
{
}

Secondly,

I think you do not have UTFT_tinyFAT, which is why you get the ‘does not name a type’ error.

Find attached my version of UTFT_tinyFAT. Credit goes to Henning of course without whom I could not have made this possible!! But Henning had no interest in supporting SdFATlib.

Regards,

Graham

Thanks, I tried that but it has the exact same errors.

I’m pretty sure I have <UTFT_tinyFAT.h>, its not saying it doesn’t exist. If I remove it from the folder it will tell me that.

I don’t see an attachment? Found it. :slight_smile:

You are aware you need to restart Arduino software every time you change your libraries?

So humour me, delete your UTFT_tinyFAT................. restart Arduino.................compile.................. post your errors....

This is not rocket science and should not be this darn difficult.....

I hope I get some karma points too!! :D

Regards,

Graham

Thank-you very much for your help, I appreciate it big time and you'll get real life karma for help people I'm sure. ;) It works, but.... lol

When I change a library I delete the files and copy the new ones over, then recompile and it recognizes the changes. If its a new library folder I have to restart the program.

So I copied your files over and it compiled, of course after me capitalizing that F, oops. Then uploaded and the image filled the screen very quickly. :) Like 10x faster or more. I'm sure it will be better when its cut up in small pieces.

Problem now though is the color is bad, any ideas why? On the mega it almost looks like my computer but on the due blue is faded yellow, red looks brown, only green looks green but not the green it should be.

P.S. I will restart the program more often when I make library changes, just to be safe. ;)

On closer look its not as clear either and I have some gradient color at the bottom but its drawing lines of different colors. Kinda strange as its the same image for the mega off the same card, I used ImageConverter 565 to create the image. It fits the screen like it should.