Pages: 1 [2]   Go Down
Author Topic: [SOLVED] Recovering photos from SD card - Console freezes by big jpeg files  (Read 3190 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
Studying Mechanical & Aeronautical Engineering at University of Patras, Greece
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

   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:
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:
#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.  smiley-lol
« Last Edit: September 13, 2013, 05:38:23 am by al1x » Logged

Pages: 1 [2]   Go Up
Jump to: