Go Down

Topic: View images from SD card on TFT display (Read 66240 times) previous topic - next topic

robsworld78

Oct 20, 2014, 03:39 am Last Edit: Oct 20, 2014, 08:49 am by robsworld78 Reason: 1
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.

robsworld78

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

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

ghlawrence2000

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

Quote
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
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

ghlawrence2000

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
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

robsworld78

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.

ghlawrence2000

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
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

robsworld78

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

ghlawrence2000

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...  :smiley-roll-blue:
I aim to have it fixed later this evening..... I will post when it works properly.

Regards,

Graham
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

robsworld78

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?

ghlawrence2000

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
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

robsworld78

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.

Code: [Select]

#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];
}

robsworld78

#11
Oct 21, 2014, 12:52 am Last Edit: Oct 21, 2014, 12:54 am by robsworld78
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.

ghlawrence2000

#12
Oct 21, 2014, 01:15 am Last Edit: Oct 21, 2014, 01:22 am by ghlawrence2000 Reason: additional thought :p
Rob,
Can you uncomment
Code: [Select]
UTFT_tinyFAT myFiles(&myGLCD);


and uncomment /edit the line .....
Code: [Select]
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.
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

robsworld78

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.

robsworld78

#14
Oct 21, 2014, 01:44 am Last Edit: Oct 21, 2014, 01:52 am by robsworld78
Don't forget I might not be using your version, I believe this one belonged to jake1981.

Go Up