Hi all
My hardware is an Arduino mega, Itead tft lcd shield v1.1 and ITDb02-3.2 TFT screen. I am using a mac for the compiling etc
The sd card is supposed to be formatted in FAT16. to do this I have tried 2 methods. Fristly, opened disk utility, selected the device name, selected partition, created 1 partition and selected MS dos and selected apply.
After doing this I right clicked on the sd card and selected get info and it says in partition info it is "Fat16"
The second method was to drag out an ancient windows laptop and format it on that to FAT16. Both seemed to work okay.
I have dragged this old Arduino Mega out of storage to set up an arduino reef controller. It si not displaying correctly on my screen and I think it has something to do with the pin outs or similar. Or perhaps the chipset.
When I run this code
// UTFT_ViewFont (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the included fonts.
//
// This demo was made for modules with a screen resolution
// of 320x240 pixels.
//
// This program requires the UTFT library.
//
// set up variables using the SD utility library functions:
#include <SD.h>
#include <tinyFAT.h>
#include <UTFT.h>
#include <UTouch.h>
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 53;
int x, y;
int bg[] = {
0, 0, 255};
int fg[] = {
255, 255, 255};
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(ITDB32S,19,18,17,16); // Remember to change the model parameter to suit your display module!
// Uncomment the next line for Arduino Mega
UTFT myGLCD(ITDB32S,38,39,40,41); // Remember to change the model parameter to suit your display module!
UTouch myTouch(6,5,4,3,2);
byte initres;
byte res;
byte input;
void setup()
{
START:
// Initialize serial communication
Serial.begin(115200);
Serial.println("press the ENTER button on your Touch Screen!");
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setColor(0, 255, 0);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(SmallFont);
myGLCD.print("Initializing SD card...", CENTER, 0);
pinMode(chipSelect, OUTPUT);
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
myGLCD.print("initialization failed. Things to check:", CENTER, 16);
myGLCD.print("* is a card inserted?", CENTER, 32);
myGLCD.print("* Is your wiring correct?", CENTER, 48);
myGLCD.print("* Is your CS pin setting correct?", CENTER, 64);
delay(5000);
goto START;
}
else {
myGLCD.print("Wiring is correct and a card is present.", CENTER, 16);
String CT = "Card type: ";
switch(card.type()) {
case SD_CARD_TYPE_SD1:
CT = CT + " SD1";
break;
case SD_CARD_TYPE_SD2:
CT = CT + " SD2";
break;
case SD_CARD_TYPE_SDHC:
CT = CT + " SDHC";
break;
default:
CT = CT + "Unknown";
}
myGLCD.print(CT, CENTER, 32);
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
myGLCD.print("Could not find FAT16/FAT32 partition.Make sure you've formatted the card", CENTER, 48);
delay (5000);
goto START;
}
else{
// print the type and size of the first FAT-type volume
myGLCD.print("Volume type is FAT "+(String)volume.fatType(), CENTER, 48);
uint32_t volumesize;
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
myGLCD.print("Volume size (bytes): "+(String)volumesize, CENTER, 64);
volumesize /= 1024;
myGLCD.print("Volume size (Kbytes): "+(String)volumesize, CENTER, 80);
volumesize /= 1024;
myGLCD.print("Volume size (Mbytes): "+(String)volumesize, CENTER, 96);
myGLCD.print("Files found on the card", CENTER, 112);
myGLCD.print("Open the Serial Monitor", CENTER, 128);
myGLCD.print("and wait for instructions!", CENTER, 144);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(bg[0], bg[1], bg[2]);
initres=file.initFAT();
if (initres!=NO_ERROR)
{
myGLCD.print("***** ERROR: ",CENTER,144);
while (true) {
};
}
drawButtons();
}
}
}
void drawButtons()
{
// Draw the ENTER buttons
myGLCD.setColor(bg[0], bg[1], bg[2]);
myGLCD.fillRoundRect (90, 180, 220, 230);
myGLCD.setColor(fg[0], fg[1], fg[2]);
myGLCD.drawRoundRect (90, 180, 220, 230);
myGLCD.print("Enter", 115, 195);
myGLCD.setBackColor (0, 0, 0);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
}
// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable()){
}
delay(20);
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
ListFiles();
myGLCD.setColor(fg[0], fg[1], fg[2]);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void loop()
{
if(Serial.available()){
int ib = Serial.read();
String is = (String)(char)ib;
myGLCD.print(" ",CENTER,160);
myGLCD.print(is, CENTER,160);
}
if (myTouch.dataAvailable())
{
delay(10);
int xt;
int yt;
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if (x>=90 && x<=220 && y >=180 && y<=230) // Button: Enter
{
waitForIt(90, 180, 220, 230);
}
else {
if (y >= 5 && y <= 235 && x >= 5 && x <= 315){
myGLCD.print(" ",260,160);
int x1 = ((x-5)/72+1)*72-72+4;
int x2 = x1 + 65;
int y1 = ((y-5)/10+1)*10-10+5;
int y2 = y1 + 10;
myGLCD.print((String)((y-5)/10+1),260,160);
myGLCD.print((String)((x-5)/72+1),280,160);
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while(myTouch.dataAvailable()){
}
delay(20);
myGLCD.setColor(0, 255, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
}
}
}
void ListFiles(){
int x = 5;
int y = 5;
String FN;
String EX;
myGLCD.clrScr();
myGLCD.setColor(0, 255, 0);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(SmallFont);
res = file.findFirstFile(&file.DE);
if (res==NO_ERROR)
{
EX = (String)file.DE.fileext;
EX.trim();
if(EX == "RAW"){
myGLCD.print(file.DE.filename, x, y);
myGLCD.drawRoundRect (x-1, y, x+64, y+10);
y+=10;
}
}
else
{
myGLCD.print("No files found...",CENTER,144);
}
while (res==NO_ERROR)
{
res = file.findNextFile(&file.DE);
if (res==NO_ERROR)
{
EX = (String)file.DE.fileext;
EX.trim();
if(EX == "RAW"){
myGLCD.print(file.DE.filename, x, y);
myGLCD.drawRoundRect (x-1, y, x+64, y+10);
y+=10;
if (y > 230){
y = 5;
x+=72;
}
}
}
}
}
code]
I get the following message. "Initialising SD card... Wiring is correct and a card is present. Card typeL SD2 Fat16/Fat32 partition. make sure youve formatted"
Cannot see the whole message because I obviously have set up the screen aspect incorrectly.
What it is supposed to do is display the sd card contents on the screen and I have added several raw files which it cannot seem to read.