code-AR 发表于 2015-3-22 22:47:40

Camera VC0706,延时摄影

本帖最后由 code-AR 于 2015-3-22 22:48 编辑

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

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

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

//库文件定义声明
#include <Adafruit_VC0706.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>         
// sd卡CS/SS端接pin 10   
#define chipSelect 10
#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;
strcpy(filename, "IMAGE000.JPG");
//设定是最大1000张,即IMAGE000至999
for (int i = 0; i < 1000; i++) {
    filename = '0' + i/100;
    filename = '0' + (i%100)/10;
    filename = '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();
}
}


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

http://v.youku.com/v_show/id_XOTE3NjMwMTM2.html



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

suoma 发表于 2015-3-31 18:35:52

你好,按你说的,我出现这个情况

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

梦之澜657 发表于 2015-3-23 12:06:10

支持一个!厉害啊!

连菜鸟都算不上 发表于 2015-3-24 13:45:04

mark!   VC0706串口摄像头这个模块没用过,有机会玩下

suoma 发表于 2015-3-25 08:57:17

谢谢分享学习一下

suoma 发表于 2015-3-25 08:58:36

楼主,你的文件里怎么还有Py文件?求教

code-AR 发表于 2015-3-25 10:12:26

suoma 发表于 2015-3-25 08:58 static/image/common/back.gif
楼主,你的文件里怎么还有Py文件?求教

这个还有树莓派支持,

suoma 发表于 2015-3-25 16:08:54

code-AR 发表于 2015-3-25 10:12 static/image/common/back.gif
这个还有树莓派支持,

用树莓派的话,该怎么接线?

suoma 发表于 2015-3-31 17:06:27

那两个电阻是什么作用?不加可以吗?

suoma 发表于 2015-3-31 17:07:33

那个红色的RN是什么模块?

suoma 发表于 2015-3-31 18:08:38

如果用蓝牙模块,程序是什么样?如何与手机建立连接?

code-AR 发表于 2015-4-4 16:35:03

suoma 发表于 2015-3-31 18:35 static/image/common/back.gif
你好,按你说的,我出现这个情况

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

先看看接线问题,再发个代码看看吧。

suoma 发表于 2015-4-4 17:02:19

code-AR 发表于 2015-4-4 16:35 static/image/common/back.gif
先看看接线问题,再发个代码看看吧。

参考了你的程序,稍有修改
#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;
strcpy(filename, "IMAGE000.JPG");
//设定是最大1000张,即IMAGE000至999
for (int i = 0; i < 1000; i++) {
    filename = '0' + i/100;
    filename = '0' + (i%100)/10;
    filename = '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();
}
}

code-AR 发表于 2015-4-4 17:35:47

suoma 发表于 2015-4-4 17:02 static/image/common/back.gif
参考了你的程序,稍有修改
#include
#include


你检查了接线没有,有可能是接线问题。没识别到相机,

suoma 发表于 2015-4-5 08:40:31

VC0706接线一样,我用的是W5100上的SD模块,直接堆叠到arduino上
页: [1] 2
查看完整版本: Camera VC0706,延时摄影