如何正确地将JPG数据保存到SD

时间:2016-04-01 02:32:15

标签: c++ c arduino

#include <LSY201.h>
#include <SD.h>

/* assuming the TX and RX pins on the camera are attached to pins 2 and 3 of
 * the arduino. */

#define camera_serial Serial1  //Tells library to use Serial1
LSY201 camera;
uint8_t buf[32];

const int chipSelect_SD_default = 51;  //SS pin for WF32
const int chipSelect_SD = chipSelect_SD_default;

File myFile;

void setup()
{
 Serial.begin(38400);
 camera.setSerial(camera_serial);
 camera_serial.begin(38400);

 pinMode(chipSelect_SD, OUTPUT);
 digitalWrite(chipSelect_SD, HIGH);

 if (!SD.begin(chipSelect_SD)) {
   Serial.println("initialization failed!");
   return;
  }
 Serial.println("initialization done.");
 Serial.println("Taking picture...");
 camera.takePicture();
 delay(3000);

 Serial.println("Bytes:");


 myFile = SD.open("testpic.jpg", FILE_WRITE);
 uint16_t offset = 0;
 while (camera.readJpegFileContent(offset, buf, sizeof(buf)))
 {
   for (int i = 0; i < sizeof(buf); i ++)
     myFile.println(buf[i], HEX);

   offset += sizeof(buf);
 }
 myFile.close();

 Serial.println("Done.");


 camera.stopTakingPictures();
 delay(10000);
}

我在WF32上使用UART硬件序列,在Arduino IDE上进行编译。数据是正确的,但我不知道如何以正确的JPG格式保存数据,所以我只需打开testpic.jpg即可查看图像。

相机模块:https://www.sparkfun.com/products/retired/10061

非常感谢任何帮助!

0 个答案:

没有答案