Go Down

Topic: [SOLVED] Recovering photos from SD card - Console freezes by big jpeg files (Read 3627 times) previous topic - next topic

PaulS

Quote
I am talking about the way Processing code -who grabs the data from serial- writes them in the .txt file. Maybe there's the problem.

JPEG data is typically not stored in text files. You REALLY need to understand binary vs. ASCII data. Neither end of the serial port should be attempting to understand the data.

Read a byte from the file. Write it to the serial port.

Read a byte from the serial port. Write it to a BINARY file using a BINARY stream writer.

DO NOT ATTEMPT TO INTERPRET THE DATA AS TEXT!

al1x

  Thanks a lot for the guidance. I knew there was something wrong with my Processing code so I searched the Processing forum and I found this code that worked for me.

Code: [Select]
import processing.serial.*;

   Serial myPort;
   OutputStream output;

    void setup() {

     size(320, 240);
     myPort = new Serial( this, Serial.list()[0], 115200);
     myPort.clear();

     output = createOutput("formula3.jpg");
   }

   void draw() {

     try {
       while ( myPort.available () > 0 ) {
         output.write(myPort.read());
       }
     }
     catch (IOException e) {
       e.printStackTrace();
     }
   }


   void keyPressed() {

     try {
       output.flush();  // Writes the remaining data to the file
       output.close();  // Finishes the file
     }

     catch (IOException e) {
       e.printStackTrace();
     }
   }


In combination with this code I modified for Arduino...
Code: [Select]
#include <SdFat.h>

SdFat sd;
SdFile myFile;
const int chipSelect = 10;

void setup() {
 Serial.begin(115200);
 //Serial.println("Type any character to start");
 //while (Serial.read() <= 0) {}
 
 if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();

 if (!myFile.open("DCIM/###D####/_DSC####.JPG", O_READ)) {
   sd.errorHalt("opening file for read failed");
 }
 //Serial.println("formula.jpg:");

 
 int data;
 while ((data = myFile.read()) >= 0) Serial.write(data);

 myFile.close();
}

void loop() {
 // nothing happens after setup
}


... I finally managed to recover my 6Mb photos from my almost dead SD card. I only need to add an iteration to just don't do this manually using <CardInfo> photo names.  XD

Go Up