Importing Images on 7" lcd using arduino mega

Hi! i am new to programming and would appreciate it if anyone could help.

This is the issue: I want to load different images 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 Mega. This is the code I'm using:

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

However, i keep on getting an error during compilation as follow:
Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Image_importer.ino: In function 'void setup()':
Image_importer:65: error: 'class UTFT' has no member named 'SPI_Flash_init'
Image_importer:69: error: 'class UTFT' has no member named 'show_color_bar'
Image_importer.ino: In function 'void loop()':
Image_importer:80: error: 'class UTFT' has no member named 'Set_character_spacing'
Image_importer:81: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:84: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:85: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:91: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:95: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:97: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:98: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:99: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:103: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:107: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:124: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:127: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:128: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:129: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:134: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:135: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:138: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:139: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:140: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:156: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:158: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:175: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:176: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:179: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:185: error: 'class UTFT' has no member named 'Put_Text'
Image_importer:189: error: 'class UTFT' has no member named 'Load_image'
Multiple libraries were found for "UTFT.h"

Used: E:\Arduino\arduino-1.6.5-r2\libraries\UTFT

Not used: E:\Arduino\arduino-1.6.5-r2\libraries\UTFT_MEGA

Not used: E:\Arduino\arduino-1.6.5-r2\libraries\UTouch

'class UTFT' has no member named 'SPI_Flash_init'

Would any1 be kind enough to help as i am running short on time.

Thanks in advance.

Just to add to the above post, the UTFT.h, im using is :

  UTFT.h - Arduino/chipKit library support for Color TFT LCD Boards
  Copyright (C)2010-2012 Henning Karlsen. All right reserved
  
  modified by coldtears electronics to suite CTE TFT Modules 
    
  This library is the continuation of my ITDB02_Graph, ITDB02_Graph16
  and RGB_GLCD libraries for Arduino and chipKit. As the number of 
  supported display modules and controllers started to increase I felt 
  it was time to make a single, universal library as it will be much 
  easier to maintain in the future.

  Basic functionality of this library was origianlly based on the 
  demo-code provided by ITead studio (for the ITDB02 modules) and 
  NKC Electronics (for the RGB GLCD module/shield).

  This library supports a number of 8bit, 16bit and serial graphic 
  displays, and will work with both Arduino and chipKit boards. For a 
  full list of tested display modules and controllers, see the 
  document UTFT_Supported_display_modules_&_controllers.pdf.

  When using 8bit and 16bit display modules there are some 
  requirements you must adhere to. These requirements can be found 
  in the document UTFT_Requirements.pdf.
  There are no special requirements when using serial displays.

  You can always find the latest version of the library at 
  http://electronics.henningkarlsen.com/

  If you make any modifications or improvements to the code, I would 
  appreciate that you share the code with me so that I might include 
  it in the next release. I can be contacted through 
  http://electronics.henningkarlsen.com/contact.php.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef UTFT_h
#define UTFT_h

#define LEFT 0
#define RIGHT 9999
#define CENTER 9998

#define PORTRAIT 0
#define LANDSCAPE 1


#define HX8347A			0
#define ILI9327			1
#define SSD1289			2
#define ILI9325C		3
#define ILI9325D_8		4
#define ILI9325D_16		5
#define HX8340B_8		6
#define HX8340B_S		7
#define HX8352A			8
#define ST7735			9
#define PCF8833			10
#define S1D19122		11
#define SSD1963_480		12
#define SSD1963_800		13
#define S6D1121_8		14
#define S6D1121_16		15
#define R61581_16		16
#define SSD1289_CTE			17
#define SSD1963_800_CTE5	18
#define ILI9327_2		19
#define SSD1963_800_CTE7	20
#define ILI9481	21

#define ITDB32			0	// HX8347-A (16bit)
#define ITDB32WC		1	// ILI9327  (16bit)
#define TFT01_32W		1	// ILI9327	(16bit)
#define ITDB32S			2	// SSD1289  (16bit)
#define TFT01_32		2	// SSD1289  (16bit)
#define ITDB24			3	// ILI9325C (8bit)
#define ITDB24D			4	// ILI9325D (8bit)
#define ITDB24DWOT		4	// ILI9325D (8bit)
#define ITDB28			4	// ILI9325D (8bit)
#define TFT01_24_8		4	// ILI9325D (8bit)
#define TFT01_24_16		5	// ILI9325D (16bit)
#define ITDB22			6	// HX8340-B (8bit)
#define ITDB22SP		7	// HX8340-B (Serial)
#define ITDB32WD		8	// HX8352-A (16bit)
#define TFT01_32WD		8	// HX8352A	(16bit)
#define ITDB18SP		9	// ST7735   (Serial)
#define LPH9135			10	// PCF8833	(Serial)
#define ITDB25H			11	// S1D19122	(16bit)
#define ITDB43			12	// SSD1963	(16bit) 480x272
#define ITDB50			13	// SSD1963	(16bit) 800x480
#define ITDB24E_8		14	// S6D1121	(8bit)
#define ITDB24E_16		15	// S6D1121	(16bit)
#define CTE35			16  // R61581 3.5" 480x320
#define CTE32			17  // SSD1289_CTE 3.2" 320*240
#define CTE50			18  // SSD1963 5.0" 800x480
#define CTE70			20  // SSD1963 7.0" 800x480
#define CTE28			5   // ILI9328/ILI9325 2.8"/2.4" 320x240
#define CTE32_480X320   21  // ILI9481 3.2" 480x320


#define SERIAL_4PIN		4
#define SERIAL_5PIN		5


#if defined(__AVR__)
	#if defined(ARDUINO) && ARDUINO >= 100
		#include "Arduino.h"
	#else
		#include "WProgram.h"
	#endif
	#include "HW_AVR_defines.h"
#else
	#include "WProgram.h"
	#include "HW_PIC32_defines.h"
#endif

struct _current_font
{
	uint8_t* font;
	uint8_t x_size;
	uint8_t y_size;
	uint8_t offset;
	uint8_t numchars;
};

class UTFT
{
	public:
		UTFT();
		UTFT(byte model, int RS, int WR,int CS, int RST, int SER=0);
		void show_color_bar();
		void SPI_Flash_init(int CSpin);
		void READ_ID();
		void Send_Flash_information_to_UART();
		void Load_image(int X, int Y, int location);
		void Put_Text(String st, int x, int y, int font_number);
		void Put_Text_array(char *st, int x, int y, int font_number);
		void Set_character_spacing(unsigned char space);
		void Swtich_LCD_TB_Bit(int TB_Bit);
		void InitLCD(byte orientation=LANDSCAPE);
		void clrScr();
		void drawPixel(int x, int y);
		void drawLine(int x1, int y1, int x2, int y2);
		void fillScr(byte r, byte g, byte b);
		void drawRect(int x1, int y1, int x2, int y2);
		void drawRoundRect(int x1, int y1, int x2, int y2);
		void fillRect(int x1, int y1, int x2, int y2);
		void fillRoundRect(int x1, int y1, int x2, int y2);
		void drawCircle(int x, int y, int radius);
		void fillCircle(int x, int y, int radius);
		void setColor(byte r, byte g, byte b);
		void setBackColor(byte r, byte g, byte b);
		void print(char *st, int x, int y, int deg=0);
		void print(String st, int x, int y, int deg=0);
		void printNumI(long num, int x, int y, int length=0, char filler=' ');
		void printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ');
		void setFont(uint8_t* font);
		void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int scale=1);
		void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy);
		void lcdOff();
		void lcdOn();
		void setContrast(char c);
		int  getDisplayXSize();
		int	 getDisplayYSize();

	protected:
		byte fcolorr,fcolorg,fcolorb;
		byte bcolorr,bcolorg,bcolorb;
		byte orient;
		long disp_x_size, disp_y_size;
		byte display_model, display_transfer_mode, display_serial_mode;
		regtype *P_RS, *P_WR, *P_CS, *P_RST, *P_SDA, *P_SCL,* P_F_CS;
		regsize B_RS, B_WR, B_CS, B_RST, B_SDA, B_SCL, B_F_CS;
		_current_font	cfont;
	
		void SPI_WriteByte(byte data);
		byte SPI_ReadByte();
		void Draw_character(unsigned char character);
		void LCD_Writ_Bus(char VH,char VL, byte mode);
		void LCD_Write_COM(char VL);
		void LCD_Write_DATA(char VH,char VL);
		void LCD_Write_DATA(char VL);
		void LCD_Write_COM_DATA(char com1,int dat1);
		void setPixel(byte r,byte g,byte b);
		void drawHLine(int x, int y, int l);
		void drawVLine(int x, int y, int l);
		void printChar(byte c, int x, int y);
		void setXY(word x1, word y1, word x2, word y2);
		void setXY_2(word x1, word y1, word x2, word y2);
		void setXY_4(word x1, word y1, word x2, word y2);
		void clrXY();
		void rotateChar(byte c, int x, int y, int pos, int deg);
		void _set_direction_registers(byte mode);
};

#endif

There are VERY specific requirements to getting the CTE image uploader to work, not least of which is an older version of the Arduino IDE. V1.5.7 from memory? Even then you can look forward to image corruption at some point. One immediate problem I note, is that the flash_cs_pin is 52 for the DUE, it is 45 for the MEGA! I gave up on the CTE library long ago when I decided to rewrite it, but nobody has shown any interest in my replacement so good luck with that.

Regards,

Graham

PS: ALL of the errors you listed are caused by not including "UTFT_CTE.h"

ghlawrence2000:
There are VERY specific requirements to getting the CTE image uploader to work, not least of which is an older version of the Arduino IDE. V1.5.7 from memory?

PS: ALL of the errors you listed are caused by not including "UTFT_CTE.h"

So i need to download the V1.5.7 of Arduino IDE.

I included the UTFT.CTE file as you told however, the error is still there.

Anymore help would be appreciated.

Thanks

shayaan123:
I included the UTFT.CTE file as you told however, the error is still there.

Are you SURE?? Please confirm UTFT_CTE folder is in your ...\Arduino\libraries folder?

When you open the IDE, go to File->Examples->UTFT_CTE......... Do you see the examples? If not then your library is not being 'seen' by the IDE..

If you DO see the examples, try running some of them, do they work?

The ONLY reason you are seeing the errors you listed is because UTFT_CTE.h is not being seen!!

I just looked at your sketch again........... ::slight_smile: :roll_eyes: I think 'somebody' has made a right mess of that sketch!! Where did you get it from??

Regards,

Graham

I bought the lcd from sainsmart who also gave me the code.
If you have the correct code, could please upload it.
I have been trying to get it to work for days.

No, I am tired of dealing with sainshit related problems. Talk to them!

Graham