SD card initializing failed using arduing Mega and CTE shield with 7'' lcd

hi,

I am using a 7'' lcd with an arduino Mega and a CTE shield. I have attached a 2gb FAT SD card to the CTE shield.
The libraries i am using are
#UTFT
#UTFT_tinyFAt
#tinyfat

However, while trying to upload the demo_Potrait from the UTFT_TinyFAT, the screen just shows a blank. It does not give an error saying image file is not present.

I have also tried to attach the SD card to the LCD itself but it says the image files are not present.

I would be glad if anyone could help in this matter.

Dump tinyfat and use my UTFT_SdRaw library.

Regards,

Graham

So i tried using your UTFT_SdRaw library.

#define SD_CHIP_SELECT 53 seems to be working on the Arduino Mega as it does not give any initializing error.
However, the LCD stops at the "Waiting for GPS lock" screen and i cant seem to skip it even.

I have downloaded the image files on the SD card but it doesnt show any image.

Just for checking i also tried the tinyfat demo aswell however, the lcd shows image not present.

Any solutions.

What does serial monitor show? All the useful information is in there.

Regards,

Graham

the serial monitor shows the following :
Initialising SD card…
Card initialised.
Initialising LCD.
LCD initialised.
Initialising GPS.
Time to draw 240x240 raw 952 ms

On the top left of the LCD, it says " Waiting for GPS lock" and “skip”, however i am unable to press skip and the lcd just keeps on showing this.

Then it is working!!

‘Waiting for GPS Lock’ is an image on the SD card!

replace this block

  myButtons.drawButton(butskip);
  while (wait == 2) {
    pressed_button = myButtons.checkButtons();
    if (pressed_button == butskip)
    {
      cout << F("Skip button detected (No GPS :( )\n");
      wait = true;
    }
  }

with delay(2000);

And then do your touch calibration and fix your touch problems…

Regards,

Graham

Thanks Graham, got it working.

Is there a way to show 6 images at once and then show which image is being touched at the serial.

Regards,

Shayaan

One more thing,

After the first image of a map in your SDRaw file, it goes back to the "waiting for GPS Lock" image and does not show SK45.RAW and icons.RAW image.

I have copied the image files folder in the SD card.

The serial shows as below :

Initialising GPS.
Time to draw 240x240 raw 876 ms
Skip button detected (No GPS :frowning: )
Time to draw 440x440 raw (no extra buffer) (non inverted colour) 3042 ms
Initialising SD card...
Card initialised.
Initialising LCD.
LCD initialised.
Initialising GPS.
Time to draw 240x240 raw 876 ms

That means your Mega is crashing and restarting… which example sketch are you using? AVR or ARM ?

If you are using the AVR example it SHOULD work fine, but try replacing this line myFiles.load(20, 20, 440, 440, fname440, 4, 0);

with thismyFiles.load(20, 20, 440, 440, fname440, 2, 0);

if you know the location where you drew each picture, you can just test for those coordinates using normal UTouch functions.

example for the image above (20,20,440,440) this would be 20-460, 20-460, so you would do something like this :-

if (myTouch.dataAvailable())  {
  myTouch.read();
  word x = myTouch.getX();
  word y = myTouch.getY();
  if ((y >= 20) && (y < 460)) {
    if ((x >= 20) && (x < 460)) {
      Serial.println("Picture 1");
    }
  }
  if ((y >= ??) && (y < ??)) {
    if ((x >= ??) && (x < ??)) {
      Serial.println("Picture 2");
    }
  }
}

Regards,

Graham

Thanks Graham, SDRaw code is working fine now.

If it is possible could you please give me the coordinates of fitting 6 images at once.

The 6 images should be displayed at the start and not one by one.

Regards,
Shayaan

I don’t understand what you mean? If you have 6 small pictures example 200x200

You can place them at 0,0 300,0 600,0 0,280 300,280 and 600,280 or am I misunderstanding you?

Or, you can make yourself one large image 800x480 with your 6 small pictures contained within it

Regards,

Graham

Yes, i have 6 small pictures and want to put them at separate locations for the users to press them individually.

Then, i want to pressed image to be shown at the serial.

Then something like this will do?

  myFiles.load(0, 0, 200, 200, "image1.raw", 2, 1);
  myFiles.load(300, 0, 200, 200, "image2.raw", 2, 1);
  myFiles.load(600, 0, 200, 200, "image3.raw", 2, 1);
  myFiles.load(0, 280, 200, 200, "image4.raw", 2, 1);
  myFiles.load(300, 280, 200, 200, "image5.raw", 2, 1);
  myFiles.load(600, 280, 200, 200, "image6.raw", 2, 1);

Regards,

Graham

EDIT: Changed coordinates for the 4th,5th and 6th images, I realised they were wrong!

Hey Graham,

Sorry for the late reply. Have been busy lately.

Yes, that worked thanks!!

Now i am working with a single large image (800x480) which contains 5 smaller images which the user would press.

Would it be possible for you to give me the coordinates of the pictures which the users would have to press.

(i have attached the picture with this)

I have attached the image.

if (myTouch.dataAvailable()) {
  myTouch.read();
  x = myTouch.getX();
  y = myTouch.getY();
  if ((x > 19 && x < 155) && (y > 44 && y < 436)) {
    //button 'back';
  }
  if ((x > 201 && x < 455) && (y > 21 && y < 212)) {
    //button 'news';
  }
  if ((x > 201 && x < 455) && (y > 267 && y < 444)) {
    //button 'medicine';
  }
  if ((x > 507 && x < 771) && (y > 26 && y < 208)) {
    //button 'light';
  }
  if ((x > 507 && x < 771) && (y > 263 && y < 448)) {
    //button 'towel';
  }
}

Regards,

Graham

i added used the following the code, however nothing shows on the serial after the lcd is initialized.

// UTFT_SdRaw_800x480_Demo
// Copyright (C)2015 Graham Lawrence (GHLawrence2000). All Rights reserved.
// web: https://github.com/ghlawrence2000/UTFT_SdRaw
//
// This program is a demo of how to use the functions provided by UTFT_SdRaw.
//
// This program requires the UTFT, UTouch, UTFT_Buttons and SdFat libraries.
//
#include <SPI.h>
// SdFat lib from here :-
// https://github.com/greiman/SdFat/archive/master.zip
#include <SdFat.h>
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
#include <UTFT_SdRaw.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

#define SD_CHIP_SELECT  53  // SD chip select pin
// file system object
SdFat sd;
// print stream
ArduinoOutStream cout(Serial);

int wait = 2, pressed_button;

// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due       : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board                   : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!

UTFT myGLCD(CTE70, 38, 39, 40, 41);
//UTFT myGLCD(CTE50, 38, 39, 40, 41);
//UTFT myGLCD(CTE70, 38, 39, 40, 41);


// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield            :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due       :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due (JP10):  6, 5,32, 3, 2
// Teensy 3.x TFT Test Board                   : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
UTouch  myTouch( 6, 5, 4, 3, 2);

UTFT_SdRaw myFiles(&myGLCD);
UTFT_Buttons  myButtons(&myGLCD, &myTouch);
int x,y;
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for DUE & Leonardo only
  }
  Serial.println(F("Initialising SD card..."));
  bool mysd = 0;
  // see if the card is present and can be initialized:
  while (!mysd)
  {
    if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) {
      Serial.println(F("Card failed, or not present"));
      Serial.println(F("Retrying...."));
    }
    else
    {
      mysd = 1;
      Serial.println(F("Card initialised."));
    }
  }
  Serial.println(F("Initialising LCD."));
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  myButtons.setTextFont(BigFont);
  int butskip = myButtons.addButton( 85,  219 , 70,  20, "Skip");
  Serial.println(F("LCD initialised."));


  myGLCD.clrScr();
   myFiles.load(0, 0, 800, 480, "lcd_2.raw", 2, 0);
   if (myTouch.dataAvailable()) {
  myTouch.read();
  x = myTouch.getX();
  y = myTouch.getY();
  if ((x > 19 && x < 155) && (y > 44 && y < 436)) {
    //button 'back'
    Serial.println(F("back."));
  }
  if ((x > 201 && x < 455) && (y > 21 && y < 212)) {
    //button 'news'
    Serial.println(F("news."));
  }
  if ((x > 201 && x < 455) && (y > 267 && y < 444)) {
    //button 'medicine';
    Serial.println(F("medicine."));
  }
  if ((x > 507 && x < 771) && (y > 26 && y < 208)) {
    //button 'light';
    Serial.println(F("light."));
  }
  if ((x > 507 && x < 771) && (y > 263 && y < 448)) {
    //button 'towel';
   cout << F("Skip button detected (No GPS :( )\n");
  }
}
 
}

void loop()
{
}
// UTFT_SdRaw_800x480_Demo
// Copyright (C)2015 Graham Lawrence (GHLawrence2000). All Rights reserved.
// web: https://github.com/ghlawrence2000/UTFT_SdRaw
//
// This program is a demo of how to use the functions provided by UTFT_SdRaw.
//
// This program requires the UTFT, UTouch, UTFT_Buttons and SdFat libraries.
//
#include <SPI.h>
// SdFat lib from here :-
// https://github.com/greiman/SdFat/archive/master.zip
#include <SdFat.h>
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_SdRaw.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

#define SD_CHIP_SELECT  53  // SD chip select pin
// file system object
SdFat sd;
// print stream
ArduinoOutStream cout(Serial);

int wait = 2, pressed_button;

// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due       : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board                   : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!

UTFT myGLCD(CTE70, 38, 39, 40, 41);
//UTFT myGLCD(CTE50, 38, 39, 40, 41);
//UTFT myGLCD(CTE70, 38, 39, 40, 41);


// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield            :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due       :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due (JP10):  6, 5,32, 3, 2
// Teensy 3.x TFT Test Board                   : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
UTouch  myTouch(6, 5, 4, 3, 2);

UTFT_SdRaw myFiles(&myGLCD);
int x, y;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for DUE & Leonardo only
  }
  Serial.println(F("Initialising SD card..."));
  bool mysd = 0;
  // see if the card is present and can be initialized:
  while (!mysd) {
    if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) {
      Serial.println(F("Card failed, or not present"));
      Serial.println(F("Retrying...."));
    } else {
      mysd = 1;
      Serial.println(F("Card initialised."));
    }
  }
  Serial.println(F("Initialising LCD."));
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  Serial.println(F("LCD initialised."));
  myGLCD.clrScr();
  myFiles.load(0, 0, 800, 480, "lcd_2.raw", 2, 0);

}

void loop() {
  if (myTouch.dataAvailable()) {
    myTouch.read();
    x = myTouch.getX();
    y = myTouch.getY();
    if ((x > 19 && x < 155) && (y > 44 && y < 436)) {
      //button 'back'
      Serial.println(F("back."));
    }
    if ((x > 201 && x < 455) && (y > 21 && y < 212)) {
      //button 'news'
      Serial.println(F("news."));
    }
    if ((x > 201 && x < 455) && (y > 267 && y < 444)) {
      //button 'medicine';
      Serial.println(F("medicine."));
    }
    if ((x > 507 && x < 771) && (y > 26 && y < 208)) {
      //button 'light';
      Serial.println(F("light."));
    }
    if ((x > 507 && x < 771) && (y > 263 && y < 448)) {
      //button 'towel';
      cout << F("Skip button detected (No GPS :( )\n");
    }
  }

}

Try something like this.

Regards,

Graham

Thanks for the code.

Initially it wasnt working but after changing the serial to 9600 baud, it started working somehow.

However, after a single press on an image, it shows the name of that image on the serial not once but about 10 to 12 times.

e.g After pressing " news" once it shows the following:
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.
news.

Any solution to this.

So it turns out that the number of times it is shown on the serial is linked to how long the image is being pressed for. ( 1 sec results in about 20 to 30 times being shown on the serial).

Is there a way to show the image only once on the serial no matter for how long the image is being pressed for.

Thanks