Some trouble with SD reading

Status
Not open for further replies.

Quentin

New member
Hello.
I have a little problem I don't understand at all. I really hope you'll be able to help me solving this.
I'm using a teensy 4.0 and a ILI9341 TFT 1.8 display, and I'm using it SD slot.
It works perfectly, I mean I can read and write in the SD.

However, depending on the code I upload on the Teensy, sometimes the Teensy itself is no longer recognized by my computer.
Let me show you some part of the code.

When I'm using this :

void setup(void) {
pinMode(SD_CS, INPUT_PULLUP);
delay(200);

tft.begin();
Serial.begin(9600);

Serial.println(F("Initializing SD card..."));
tft.println(F("Init SD card..."));
while (!SD.begin(SD_CS)) {
Serial.println(F("failed to access SD card!"));
tft.println(F("failed to access SD card!"));
delay(2000);
}

pinMode(20,INPUT);
pinMode(21,INPUT);
pinMode(22,INPUT);
pinMode(23,INPUT);
drawArduimon(0,60,60);

}

void loop() {
if (Peter_x==15 && Peter_y==27) {
changeMap(1);
}
}


--> I got this error on my Arduino IDE :
"La carte sur usb:0/140000/0/2 n'est pas disponible", "The bord usb:0/140000/0/2 isn't available".

But if I'm using only one of both functions drawArduimon(0,60,60) OR changeMap(1), it works !

Sometimes, including one of these function in a if also makes my teensy not available.
I don't know at all what's happening, it seems so random.
By the way, including a library I coded also make this problem appeared, what isn't the case in a brand new sketch.

Let me give you the two functions I used in the part of code given before :

void drawArduimon(int ArduimonID, uint8_t x, uint16_t y) {
uint32_t startTime = millis();
File fichier;

switch(ArduimonID) {
case 0:fichier = SD.open("test.txt");break;
default:return;
}

for (int i=0;i<115;i++) { //Pour chaque ligne ////////////////////////////////////////////////////////////////////
for (int j=0;j<100;j++) { //Pour chaque pixels d'une ligne ////////////////////////////////////////////
char pixel[6] = "0x";
for (int i=0;i<4;i++) {pixel[2+i]=fichier.read();}
if (strtol(pixel,NULL,16)!=0xf815) tft.drawPixel(j, i, strtol(pixel,NULL,16));
}
fichier.read();fichier.read();
}

fichier.close();
Serial.print("Arduimon loaded in ");
Serial.println(millis() - startTime);
}


void changeMap(int mapID) {
uint32_t startTime = millis();
File fichierMAP;
uint32_t count=0;

switch(mapID) {
case 0:fichierMAP = SD.open("MAP0.txt");break;
case 1:fichierMAP = SD.open("MAP1.txt");break;
default :return;
}

for (int i=0;i<480;i++) { //Pour chaque ligne ////////////////////////////////////////////////////////////////////
for (int j=0;j<480;j++) { //Pour chaque pixels d'une ligne ////////////////////////////////////////////
char pixel[6] = "0x";
for (int i=0;i<4;i++) {pixel[2+i]=fichierMAP.read();}
MAP[count] = strtol(pixel,NULL,16);
count++;
}
fichierMAP.read();fichierMAP.read();
}

switch(Peter_dir) {
case 0:drawMap(Peter_x*16, Peter_y*16+2, MAP, 480, PETER0);break;
case 1:drawMap(Peter_x*16, Peter_y*16+2, MAP, 480, PETER2);break;
case 2:drawMap(Peter_x*16, Peter_y*16+2, MAP, 480, PETER4);break;
case 3:drawMap(Peter_x*16, Peter_y*16+2, MAP, 480, PETER7);break;
default:return;
}

fichierMAP.close();
Serial.print("Map loaded in ");
Serial.println(millis() - startTime);
}


drawArduimon read a file in the SD which contains a 16-bit colored String which represents an image, and it draw it on the display.
changeMap read a file in the SD which contains a 16-bit colored String which also represents an image, but keep it in the RAM on the teensy as a parameter of the code.

It would be awesome if you could help me solving this, I hope you'll pay attention to my problem.
Cheers,
Quentin
 
Oh, I noticed another clue to find the problem : usingtft.fillRect() words but tft.drawRect() make the exact same problem : USB board not available. I don't know if it can help, but I thought it is important to report.
Cheers,
Quentin
 
Status
Not open for further replies.
Back
Top