Pages: [1]   Go Down
Author Topic: Loading Image into an 7" TFT LCD from SD Card  (Read 2740 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! I have this persisting problem and I'm running out of ideas.

This is the issue: I want to load an image to my 7 inch TFT LCD screen (sdd1963 based) from an SD Card and I'm not able to do it. I'm using the cold tears CTE Shield for Due. This is the code I'm using:
Code:
#include <SdFat.h>
#include <UTFT.h>
#include <SdFatUtil.h>
#include <Importer.h>
#include "SPI.h"

#define BVS_13 10
#define BVS_15 12
#define BVS_19 14
#define BVS_22 18
#define BVS_28 22
#define BVS_34 28
#define BVS_43 38
#define BVS_52 53
#define BVS_74 78
#define BVS_112 122

UTFT myGLCD(CTE70);

const uint8_t chipSelect = 53; // SD CSpin
#define FLASH_CS_PIN 52  //Flash CSpin
#define SPI_RATE 4

#define BUF_SIZE 256
static char name[14];
static char flash_memory_type;
uint8_t buf[BUF_SIZE];

unsigned long Location;
unsigned long address;
char IMAGE_FILENAME[] = "0.CTE";
unsigned int MAX_sector;

// file system
SdFat sd;

// test file
SdFile file;


ArduinoOutStream cout(Serial);

#define error(s) sd.errorHalt_P(PSTR(s))
void setup() {
  delay(1000);
  Serial.begin(38400);
  SPI_Flash_init(FLASH_CS_PIN,SPI_RATE);
  myGLCD.SPI_Flash_init(FLASH_CS_PIN,SPI_RATE);
  myGLCD.InitLCD();
  myGLCD.show_color_bar();
  delay(1000);
  myGLCD.clrScr();
}

void loop() {
 
  myGLCD.clrScr();
  myGLCD.Swtich_LCD_TB_Bit(0);
  myGLCD.setColor(255, 255, 0);   
  myGLCD.setBackColor(0, 0, 0);   
  myGLCD.Set_character_spacing(1);
  myGLCD.Put_Text("Image importer via SD card",5,5,BVS_28);
  char charBuf[1]; charBuf[0]=169;charBuf[1]=0;
  myGLCD.setColor(255, 0, 255);   
  myGLCD.Put_Text(charBuf,5,40,BVS_28);
  myGLCD.Put_Text(" Coldtears electronics",30,40,BVS_28);
  myGLCD.setColor(255, 255, 255);
 
 
  if (!sd.begin(chipSelect, SPI_HALF_SPEED))
  { 
    myGLCD.Put_Text("SD Access Error",5,80,BVS_19);
  sd.initErrorHalt();
  }
  else {
    myGLCD.Put_Text("SD Access OK",5,80,BVS_19);
  }
  delay(1000);  if (READ_ID()==0) {myGLCD.Put_Text("Flash memory Error",5,100,BVS_19); while(1){} }
  else if (READ_ID()==1) {myGLCD.Put_Text("Flash: 32Mbit,   Max Img location 799",2,100,BVS_19); flash_memory_type=1; MAX_sector=1023;}
  else if (READ_ID()==2) {myGLCD.Put_Text("Flash: 64Mbit,   Max Img location 1823",2,100,BVS_19); flash_memory_type=2; MAX_sector=2047;}
  delay(1000);

  if (!file.open(IMAGE_FILENAME, O_RDWR)) {
    myGLCD.Put_Text("file open failed",5,120,BVS_19);
    error("open failed");
  }
  else{
  myGLCD.Put_Text("file open OK",5,120,BVS_19);
  }
  delay(1000);
  char temp_buf[10];
  file.read(temp_buf, sizeof(temp_buf));
  file.rewind();
  unsigned int ass=temp_buf[6]*256+temp_buf[7];
  Location=ass;                //DO NOT edit this, or else it may overwrite Font data
  address=(Location+224)*4096; //DO NOT edit this, or else it may overwrite Font data
  unsigned long filesize = file.fileSize();
  unsigned long no_of_sectors = filesize/4096;
  if (filesize%4096>0) no_of_sectors=no_of_sectors+1;
  unsigned long no_of_page = filesize/256;
  if (no_of_page%256>0) no_of_page=no_of_page+1;
 

  if (Location+224+no_of_sectors>MAX_sector)
  { myGLCD.Put_Text("Not enough space",5,120,BVS_19); while(1){}}
   
  file.getFilename(name);
  myGLCD.Put_Text((String)filesize+"bytes, Filename:",1,120,BVS_19);
  myGLCD.Put_Text(name,200,120,BVS_19);
  myGLCD.Put_Text("Img location: " + (String)(Location) + "-" + (String)(Location+no_of_sectors-1),120,80,BVS_19);
 
  delay(1000);
  unsigned char countdown=10;
  myGLCD.setColor(255, 100, 100);
  myGLCD.Put_Text("unplug power NOW to cancel..",1,140,BVS_22);
  myGLCD.Put_Text(String(countdown)+"       ",280,140,BVS_22);  delay(1000);
  while(countdown>0)
  {
  if (countdown%2==1)   myGLCD.Put_Text("unplug power NOW to cancel..",1,140,BVS_22);
  else myGLCD.Put_Text("                                                                                          ",1,140,BVS_22);
  myGLCD.Put_Text(String(countdown)+"       ",280,140,BVS_22);
  countdown--;
  delay(1000);
  }
   myGLCD.setColor(255, 255, 255);
  unsigned long temp_add = address;
  unsigned long m;
  String total_sectors = " / "+ (String)(no_of_sectors-1);
  for (m=0; m<no_of_sectors;m++)
  {
   WRITE_ENABLE();
   if (flash_memory_type==1) WRITE_STATUS_REGISTER(48);
   else if (flash_memory_type==2) WRITE_STATUS_REGISTER(44);
   delay(30);WRITE_ENABLE();
   SECTOR_ERASE(temp_add);
   temp_add=temp_add+0x001000;delay(300);
   myGLCD.Put_Text("Erasing Sector: ",1,165,BVS_19);
   String displaya = String(m) + total_sectors;
   myGLCD.Put_Text(displaya,150,165,BVS_19);
  }

  temp_add = address;
  volatile unsigned int counter=0;
  String total_page = " / "+ (String)no_of_page;
  for(unsigned long  z=0;z<no_of_page;z++)
  {
        unsigned int bytes_read=file.read(buf, sizeof(buf));
        if (bytes_read!=256)
         {
            for(unsigned int z=bytes_read;z<256;z++) buf[z]=0xFF;
         }   
         WRITE_ENABLE();
PAGE_PROGRAME(temp_add,buf);
         temp_add=temp_add+256;delay(20);   
         counter++;
         myGLCD.Put_Text("Writing Page: ",1,185,BVS_19);
         myGLCD.Put_Text((String)counter + total_page  ,150,185,BVS_19);
  }

   myGLCD.Put_Text("Write File OK, Display image soon....",1,205,BVS_22);
   delay(1000);
   WRITE_ENABLE(); WRITE_STATUS_REGISTER(252);  delay(100);
   countdown=5;
   while(countdown>0)
  {
    myGLCD.Put_Text(String(countdown)+"    ",300,205,BVS_22);
    countdown--;
    delay(1000);
  }
 myGLCD.Load_image(0,0,(Location));
 delay(2000);
 file.close();
 Location=Location+no_of_sectors;
 address=(Location+224)*4096;
 while(1){}                                                  //disable this for batch files import
 //IMAGE_FILENAME[0]=IMAGE_FILENAME[0]++; //myGLCD.clrScr();   //enable this for batch files import
}
It doesn't throw any errors on the scketch, but I'm not able to see on the screen what the program runs, and of course I'm not able to load  my image into my LCD Screen..!!

Any Ideas?? Thanks in advance.
« Last Edit: March 15, 2013, 02:16:44 pm by DanyHdez » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Location=ass;
Thanks for the laugh.

Yours is a prime candidate for the "bisecting the problem with Serial.print()" approach.  Find out what is working, and what isn't, using judiciously scattered logging.  If you feel lucky, start in the middle and work your way forward or back.

-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry about that hehe!!

I've been doing that. I'm trying to find what is working and what isn't but nothing yet! Some parts of the code are just not doing what they should do!! Anyways.. I'll keep trying!

Thanks for the advice!
« Last Edit: March 15, 2013, 03:57:38 pm by DanyHdez » Logged

Alamos, Sonora, Mexico
Offline Offline
Full Member
***
Karma: 5
Posts: 134
learning never stops.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Moderators... Please remove this Thread for Daniel and I.  We were working together on it (we both own 5" and 7" LCDs).  Unfortunatel, I purchased the wrong LCDs for both of us..... inadvertently I purchased the version without the Font IC, which also has the Flash for the internal image storage.

It will cause confusion if this remains....as it is simply a purchasing error on our part.
Logged

Quiero una vida simple en Mexico...nada mas.

UK
Offline Offline
Sr. Member
****
Karma: 7
Posts: 436
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Moderators... Please remove this Thread for Daniel and I.  We were working together on it (we both own 5" and 7" LCDs).  Unfortunatel, I purchased the wrong LCDs for both of us..... inadvertently I purchased the version without the Font IC, which also has the Flash for the internal image storage.

It will cause confusion if this remains....as it is simply a purchasing error on our part.

I have bought one of each.  The only difference is the font IC which is a w25Q64BVSSIG. If you search ebay you can get 5 for£5.29 / $8 inc postage.  They are incredible easy to solder into place.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.I have got an Arduino DUE with CTE 7''   LCD shield ver. 1.04. Everything is work ok, except function Load Image.
I loaded the sketch Image Importer to the DUE, and see the  screen :
SD Access OK
Flash 64 Mbit, Max img Location 1823
file open failed

the jumper Jp8 is soldered, Jp 6-7 are open.
Also i have checked, the SD card works good, i loaded some examples from Sdfat library  directory, seems like everything is ok.
But when i comment this lines:

 if (!file.open(IMAGE_FILENAME, O_RDWR)) {
    myGLCD.Put_Text("file open failed",5,120,BVS_19);
    error("open failed");
  }
  else{
  myGLCD.Put_Text("file open OK",5,120,BVS_19);
  }
It says: Not enough space
I don't know were is mistakes.
Any ideas?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, im alexis and i have a big problem with my LCD 5" with due arduino and CTE shield.

Everythings is ok with the example from Henning Karlsen, but when i started to program from myself i realized that i need a bigger fonts to make my project so, i saw that in CTE example there are 10 different sizes and icons.... but when i tried to run this code it doesnt work!! it just shows the first colors bars and then show strangers things.... i need helps!!.. the jumper#8 is soldered and jumper#6 and 7 are openned...

Can someone explain me how i can run the code with differentes fonts and icons please!!

Thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you show the photo? Seems like i got it tonight. The trouble is in CTE.H lib. Tried to use only UTFT lib. In my case i see squares, lines and etc with place to place normal text. Are you?
Logged

Pages: [1]   Go Up
Jump to: