I am working on a project which requires me to transfer .jpg from SD to computer through SPI using arduino. I found [SOLVED] thread on the same topic but the code that the person had provided does not seem to work when i use it. It looks as the arduino does send the file but i dont seem to be receiving it at the other end.
Here’s the code:
For arduino:
#include <SD.h>
File photoFile;
const int buttonPin = 7;
const int ledPin = 5;
void setup(){
Serial.begin(115200);
pinMode(buttonPin,INPUT);
pinMode(ledPin,OUTPUT);
//Serial.println("initializing sd card");
pinMode(10,OUTPUT); // CS pin of SD Card Shield
if (!SD.begin(10)) {
Serial.print("sd initialzation failed");
return;
}
//Serial.println("sd initialization done");
}
void loop(){
while(1){
// Serial.println("press the button to send picture");
Serial.flush();
while(digitalRead(buttonPin) == LOW);
if(digitalRead(buttonPin) == HIGH){
delay(50);
if(digitalRead(buttonPin) == HIGH){
delay(200);
File photoFile = SD.open("pic02.jpg");
if (photoFile) {
while (photoFile.position() < photoFile.size()) {
digitalWrite(ledPin,HIGH);
Serial.write(photoFile.read());
}
photoFile.close();
digitalWrite(ledPin,LOW);
}
else {
Serial.println("error sending photo");
}
}
//Serial.println("photo sent");
}
}
}
and for processing:
import processing.serial.*;
Serial myPort;
OutputStream output;
void setup() {
size(320, 240);
//println( Serial.list() );
myPort = new Serial( this, Serial.list()[0], 115200);
myPort.clear();
output = createOutput("pic02.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();
}
}
the website is here: Dread-Eye: Arduino + Processing: JPEG Serial Transfer
He says it works but mmm not so sure. Since i am new to both formats i cant really check it.
Has anyone tried out this code? Is there another code that i could perhaps use. I have done exhaustive search but dont seem to nail this one down