极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 48409|回复: 27

Camera VC0706,延时摄影

[复制链接]
发表于 2015-3-22 22:47:40 | 显示全部楼层 |阅读模式
本帖最后由 code-AR 于 2015-3-22 22:48 编辑

很长段时间没有混在论坛了,平时就是签个到。今天带了个新玩意吧,利用VC0706串口摄像头定时拍摄照片,以制作延时摄影
       不知道什么是延时摄影的,自行度娘去。整个流程就是用arduino来控制摄像头拍摄照片,并存储到SD卡中,最后用SD卡中的照片来制作延时摄影的影片,利用了arduino UNO,外加SD卡模块,VC0706串口摄像头(可以在加个蓝牙模块,监控拍摄信息)。来个简陋的硬件图吧,
   →_→

      这些组合起来,再外加个5000mAH的移动电源。用个纸盒包装起来,即可成个延时摄影器材,电力可以支持十几个小时的拍摄工作。再来就是硬件的连接图(其中的蓝牙模块,可要,可不要。我主要是拿来检测拍摄信息的)
   →_→

     代码部分(基于vc0706的库文件的例程修改)
  1. //自动延时摄影
  2. //MCU内部自走时,设定时间,驱动VC0706进行拍照

  3. //库文件定义声明
  4. #include <Adafruit_VC0706.h>
  5. #include <SPI.h>
  6. #include <SD.h>
  7. #include <SoftwareSerial.h>         
  8. // sd卡CS/SS端接pin 10   
  9. #define chipSelect 10
  10. #define DelayTime 30000//定义延时时间
  11. static long timer;

  12. // 对于 Uno: camera TX 接 pin 2, camera RX 接 pin 3:
  13. SoftwareSerial cameraconnection = SoftwareSerial(2, 3);

  14. Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

  15. void setup() {

  16.   pinMode(10, OUTPUT); // SS on Uno, etc.
  17.   Serial.begin(9600);
  18.   Serial.println("VC0706 Camera test");
  19.   
  20.   // see if the card is present and can be initialized:
  21.   if (!SD.begin(chipSelect)) {
  22.     Serial.println("Card failed, or not present");
  23.     // don't do anything more:
  24.     return;
  25.   }  
  26.   
  27.   // Try to locate the camera
  28.   if (cam.begin()) {
  29.     Serial.println("Camera Found:");
  30.   } else {
  31.     Serial.println("No camera found?");
  32.     return;
  33.   }
  34.   // Print out the camera version information (optional)
  35.   char *reply = cam.getVersion();
  36.   if (reply == 0) {
  37.     Serial.print("Failed to get version");
  38.   } else {
  39.     Serial.println("-----------------");
  40.     Serial.print(reply);
  41.     Serial.println("-----------------");
  42.   }

  43.   // 设置照片尺寸 -  640x480, 320x240 or 160x120   
  44.   //cam.setImageSize(VC0706_640x480);        // biggest
  45.   cam.setImageSize(VC0706_320x240);          // medium
  46.   //cam.setImageSize(VC0706_160x120);        // small

  47.   // You can read the size back from the camera (optional, but maybe useful?)
  48.   uint8_t imgsize = cam.getImageSize();
  49.   Serial.print("Image size: ");
  50.   if (imgsize == VC0706_640x480) Serial.println("640x480");
  51.   if (imgsize == VC0706_320x240) Serial.println("320x240");
  52.   if (imgsize == VC0706_160x120) Serial.println("160x120");
  53.   
  54.   timer = 0;
  55. }




  56. void loop() {
  57. if (millis() > timer + DelayTime) {
  58.    timer = millis();
  59.    Serial.println("Delay Done!");   
  60.    
  61.   if (! cam.takePicture())
  62.     Serial.println("Failed to snap!");
  63.   else
  64.     Serial.println("Picture taken!");
  65.   
  66.   char filename[13];
  67.   strcpy(filename, "IMAGE000.JPG");
  68.   //设定是最大1000张,即IMAGE000至999
  69.   for (int i = 0; i < 1000; i++) {
  70.     filename[5] = '0' + i/100;
  71.     filename[6] = '0' + (i%100)/10;
  72.     filename[7] = '0' + (i%100)%10;
  73.     // create if does not exist, do not open existing, write, sync after write
  74.     if (! SD.exists(filename)) {
  75.       break;
  76.     }
  77.   }
  78.   
  79.   File imgFile = SD.open(filename, FILE_WRITE);
  80.   
  81.   uint16_t jpglen = cam.frameLength();
  82.   Serial.print(jpglen, DEC);
  83.   Serial.println(" byte image");

  84.   Serial.print("Writing image to "); Serial.print(filename);
  85.   
  86.   while (jpglen > 0) {
  87.     // read 32 bytes at a time;
  88.     uint8_t *buffer;
  89.     uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
  90.     buffer = cam.readPicture(bytesToRead);
  91.     imgFile.write(buffer, bytesToRead);

  92.     //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");

  93.     jpglen -= bytesToRead;
  94.   }
  95.   imgFile.close();
  96.   Serial.println("...Done!");
  97.   cam.resumeVideo();
  98. }
  99. }
复制代码


     自己制作的视频(渣画质,慎点),外加vc0706库文件。。。





     希望有兴趣的朋友,可以分享自己拍摄的作品那,也可以在这个基础上完成其他好作品,谢谢!!!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-3-31 18:35:52 | 显示全部楼层
你好,按你说的,我出现这个情况

串口显示0 byte image,我在SD卡中也看到了图片。但都是0B,打开错误,怎么解决?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 1 反对 0

使用道具 举报

发表于 2015-3-23 12:06:10 | 显示全部楼层
支持一个!厉害啊!
回复 支持 反对

使用道具 举报

发表于 2015-3-24 13:45:04 | 显示全部楼层
mark!   VC0706串口摄像头这个模块没用过,有机会玩下
回复 支持 反对

使用道具 举报

发表于 2015-3-25 08:57:17 | 显示全部楼层
谢谢分享学习一下
回复 支持 反对

使用道具 举报

发表于 2015-3-25 08:58:36 | 显示全部楼层
楼主,你的文件里怎么还有Py文件?求教
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-25 10:12:26 | 显示全部楼层
suoma 发表于 2015-3-25 08:58
楼主,你的文件里怎么还有Py文件?求教

这个还有树莓派支持,
回复 支持 反对

使用道具 举报

发表于 2015-3-25 16:08:54 | 显示全部楼层
code-AR 发表于 2015-3-25 10:12
这个还有树莓派支持,

用树莓派的话,该怎么接线?
回复 支持 反对

使用道具 举报

发表于 2015-3-31 17:06:27 | 显示全部楼层
那两个电阻是什么作用?不加可以吗?
回复 支持 反对

使用道具 举报

发表于 2015-3-31 17:07:33 | 显示全部楼层
那个红色的RN是什么模块?
回复 支持 反对

使用道具 举报

发表于 2015-3-31 18:08:38 | 显示全部楼层
如果用蓝牙模块,程序是什么样?如何与手机建立连接?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-4 16:35:03 | 显示全部楼层
suoma 发表于 2015-3-31 18:35
你好,按你说的,我出现这个情况

串口显示0 byte image,我在SD卡中也看到了图片。但都是0B,打开错误, ...

先看看接线问题,再发个代码看看吧。
回复 支持 反对

使用道具 举报

发表于 2015-4-4 17:02:19 | 显示全部楼层
code-AR 发表于 2015-4-4 16:35
先看看接线问题,再发个代码看看吧。

参考了你的程序,稍有修改
#include <Adafruit_VC0706.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>         
// sd卡CS/SS端接pin 10   
#define chipSelect 4
#define DelayTime 30000//定义延时时间
static long timer;

// 对于 Uno: camera TX 接 pin 2, camera RX 接 pin 3:
SoftwareSerial cameraconnection = SoftwareSerial(2, 3);

Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

void setup() {

  pinMode(10, OUTPUT); // SS on Uno, etc.
  Serial.begin(9600);
  Serial.println("VC0706 Camera test");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }  

  // Try to locate the camera
  if (cam.begin()) {
    Serial.println("Camera Found:");
  } else {
    Serial.println("No camera found?");
    return;
  }
  // Print out the camera version information (optional)
  char *reply = cam.getVersion();
  if (reply == 0) {
    Serial.print("Failed to get version");
  } else {
    Serial.println("-----------------");
    Serial.print(reply);
    Serial.println("-----------------");
  }

  // 设置照片尺寸 -  640x480, 320x240 or 160x120   
  //cam.setImageSize(VC0706_640x480);        // biggest
  cam.setImageSize(VC0706_320x240);          // medium
  //cam.setImageSize(VC0706_160x120);        // small

  // You can read the size back from the camera (optional, but maybe useful?)
  uint8_t imgsize = cam.getImageSize();
  Serial.print("Image size: ");
  if (imgsize == VC0706_640x480) Serial.println("640x480");
  if (imgsize == VC0706_320x240) Serial.println("320x240");
  if (imgsize == VC0706_160x120) Serial.println("160x120");

  timer = 0;
}




void loop() {
if (millis() > timer + DelayTime) {
   timer = millis();
   Serial.println("Delay Done!");   

  if (! cam.takePicture())
    Serial.println("Failed to snap!");
  else
    Serial.println("Picture taken!");

  char filename[13];
  strcpy(filename, "IMAGE000.JPG");
  //设定是最大1000张,即IMAGE000至999
  for (int i = 0; i < 1000; i++) {
    filename[5] = '0' + i/100;
    filename[6] = '0' + (i%100)/10;
    filename[7] = '0' + (i%100)%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }

  File imgFile = SD.open(filename, FILE_WRITE);

  uint16_t jpglen = cam.frameLength();
  Serial.print(jpglen, DEC);
  Serial.println(" byte image");

  Serial.print("Writing image to "); Serial.print(filename);

  while (jpglen > 0) {
    // read 32 bytes at a time;
    uint8_t *buffer;
    uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
    buffer = cam.readPicture(bytesToRead);
    imgFile.write(buffer, bytesToRead);

    //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");

    jpglen -= bytesToRead;
  }
  imgFile.close();
  Serial.println("...Done!");
  cam.resumeVideo();
}
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-4 17:35:47 | 显示全部楼层
suoma 发表于 2015-4-4 17:02
参考了你的程序,稍有修改
#include
#include

你检查了接线没有,有可能是接线问题。没识别到相机,
回复 支持 反对

使用道具 举报

发表于 2015-4-5 08:40:31 | 显示全部楼层
VC0706接线一样,我用的是W5100上的SD模块,直接堆叠到arduino上
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 22:30 , Processed in 0.048327 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表