Copying a .JPG file from PC to SD Card

Hello everybody, this is my first post in this forum. I hope you guys can help me and tell me if I did something wrong with the post :smiley:

Is it possible to copy an image with .JPG/.JPEG format from pc to SD card using arduino?

I try to read a 8mb .JPG file from my SD card and write it to the serial monitor using this code :
the first idea came into my mind is to read the JPG as a text and write it back to the SD card to do the copying things.
////////////////////
#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
;
}

Serial.print(“Initializing SD card…”);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
while (1);
}
Serial.println(“card initialized.”);

//Choose the file to open
File dataFile = SD.open(“IMG_5596.JPG”);

// if the file is available, write to serial monitor:
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
}
// if the file isn’t open, pop up an error:
else {
Serial.println(“error opening datalog.txt”);
}
}

void loop() {
}

////////////////////

What happened in the serial monitor is like showing a lot of things like this :

ÊŽ+æ8Ÿ ,t¨ÒÃÍ9©vØ÷òÚrÃàªÑ¬¬ªGOŸü~øÏþ
]ðóU�iÚ§Â
{ÇžÐlîl|£xÃâÞ¯
…„m$³³Eg§¬¬®Ò>e�I’Ì2ÛTàÞ4ý¡þ|x°ƒ^o
üXðî�e�§øbÇâ-Ö­nl’

What can I do with this kind of things? I’m so new to arduino and programming

Why do you need the Arduino for this? Why not just write the file to the card directly from the PC?

The code you have is reading from an SD with the Arduino. So what is it that you actually want to do? Read a jpeg? display it? Copy it? What is it that you're really after here?

What happened in the serial monitor is like showing a lot of things like this :

ÊŽ+æ8Ÿ ,t¨ÒÃÍ9©vØ÷òÚrÃàªÑ¬¬ªGOŸü~øÏþ
]ðóU�iÚ§Â
{ÇžÐlîl|£xÃâÞ¯
…„m$³³Eg§¬¬®Ò>e�I’Ì2ÛTàÞ4ý¡þ|x°ƒ^o
üXðî�e�§øbÇâ-Ö­nl’

Yes. Were you expecting the contents of a jpeg to be human readable?

Im experimenting with it, do you think it's possible to do so?

I didn't expected to be readable, but it's like endless. I don't know if i can write it again to the sd card

kwlsq:
Im experimenting with it, do you think it’s possible to do so?

To do what exactly? That was like the whole point of my last post was to try to find out exactly what it is you want to be able to do.

kwlsq:
I didn’t expected to be readable, but it’s like endless. I don’t know if i can write it again to the sd card

Yeah, how long is your jpeg file. how many characters is that? It’s going to be really long.

to do what exactly? That was like the whole point of my last post was to try to find out exactly what it is you want to be able to do.

I wanted to copy it, from pc to sd card using arduino

Yeah, how long is your jpeg file. how many characters is that? It's going to be really long.

I dont know how many characters in it, it's still writing since I make this post. Maybe I should try with smaller file.

kwlsq: I dont know how many characters in it

Sure you do.

I try to read a 8mb .JPG file from my SD card

There's 8 million of them. You're printing them at about 1 per ms. So you've got about 2 hours to wait at least. Anything involving the Arduino and IO is going to be slow.

I wanted to copy it, from pc to sd card using arduino

That's why I'm confused. The code you have is going the other way. Perhaps you could elaborate a little. Maybe use more than one or two sentences to get the thought out.

If you really want to copy the jpeg from the PC to the SD card then you don't need the Arduino. It is just going to slow things down to a crawl. You can write directly from the PC to the SD card in a fraction of the time.

It's a bit like saying you want to know how to use a herring to cut down the mightiest tree in the forest. I'm sure there's a way, but it's just stupid to use such a tool.

There's 8 million of them. You're printing them at about 1 per ms. So you've got about 2 hours to wait at least. Anything involving the Arduino and IO is going to be slow.

Omg.. it took a long time..

It's a bit like saying you want to know how to use a herring to cut down the mightiest tree in the forest. I'm sure there's a way, but it's just stupid to use such a tool.

Yeah maybe I'll just stick with the proper way of copying JPG files :D

Thanks a lot Delta_G for responding my post! Really appreciate it!

As indicated, it can be done. Reason why I post this is that you might not necessarily have to transfer a 8MByte jpeg but a small configuration that you want to store in e.g. EEPROM or on SD card.

What you need is a terminal program (realterm, putty, ...) that can read files on the PC and transfer them over the serial port.

You will also need a handshaking mechanism because writing to EEPROM and SD is relatively slow and you will loose data if you don't tell the PC to stop sending when needed and start sending again when you have written the current data to storage. This can be a hardware handshake (not supported by standard Arduino) or a software handshake (xon/xoff, which needs to be implemented in the code that you write for the Arduino and needs to be supported by the terminal program of choice).

Reason why I post this is that you might not necessarily have to transfer a 8MByte jpeg but a small configuration that you want to store in e.g. EEPROM or on SD card.

So in other words, I dont need to read and write the file to move the data?

Do you have any good sources to learn these kind of things? :D your reply give me inspiration!

(xon/xoff, which needs to be implemented in the code that you write for the Arduino and needs to be supported by the terminal program of choice).

Can you explain more about this? Im still confused