VC0706 driver for radio shack camera shield

Dependencies:   MODSERIAL

Sample Code

#include "mbed.h"
#include "SDFileSystem.h"
#include "CameraShield.h"
#include <stdio.h>


unsigned char VC0706_rx_buffer[80];
    

SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd", PTE6, SDFileSystem::SWITCH_POS_NO, 25000000); // MOSI, MISO, SCLK, SSEL
CameraShield camera(PTC17, PTC16);


void CapturePhoto()
{
    uint32_t    frame_length = camera.VC0706_get_frame_buffer_length();        //get frame buffer length
    uint32_t    vc_frame_address = READ_DATA_BLOCK_NO;    
        
    FILE* camFile = fopen("/sd/temp.jpg", "w");
        
    while(vc_frame_address<frame_length)
    {   
        camera.VC0706_read_frame_buffer(vc_frame_address - READ_DATA_BLOCK_NO, READ_DATA_BLOCK_NO);
        wait_ms(9);

        //get the data with length=READ_DATA_BLOCK_NObytes 
        camera.buffer_read(VC0706_rx_buffer, 80);

        // write data to temp.jpg
        fwrite(VC0706_rx_buffer + 5, sizeof(char), READ_DATA_BLOCK_NO, camFile);
    
        //read next READ_DATA_BLOCK_NO bytes from frame buffer
        vc_frame_address = vc_frame_address + READ_DATA_BLOCK_NO;
    }

    // get the last data
    vc_frame_address = vc_frame_address - READ_DATA_BLOCK_NO;
    uint32_t last_data_length = frame_length - vc_frame_address;
    
    camera.VC0706_read_frame_buffer(vc_frame_address, last_data_length);
    wait_ms(9);
    //get the data 
    camera.buffer_read(VC0706_rx_buffer, 80);
            
    fwrite(VC0706_rx_buffer+5, sizeof(char), last_data_length, camFile);
    
    fclose(camFile);
}

 
int main (void) 
{                      
    // Check to see if the file exists: 
    // if exists,delete the file:
    sd.remove("/sd/temp.jpg");
    
    camera.Init();  
    camera.VC0706_image_size(VC0706_640x480);
    camera.ResumeVideo();   
    wait_ms(500);   
    
    
    while(1)
    {
        camera.ResumeVideo();   
        wait_ms(1000);
        
        camera.TakeSnapShot();
        CapturePhoto(); 
    }
}
Committer:
davidr99
Date:
Thu Dec 18 04:36:48 2014 +0000
Revision:
1:5cff9e627e06
Parent:
0:e5fc19091502
Added modserial to its dependency

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidr99 0:e5fc19091502 1 /*****************************************************************************************
davidr99 0:e5fc19091502 2 ** File: CameraShield.h **
davidr99 0:e5fc19091502 3 ** **
davidr99 0:e5fc19091502 4 ** For radio shack Camera Shield. **
davidr99 0:e5fc19091502 5 ** http://blog.radioshack.com/2013/01/radioshack-camera-shield-for-arduino-boards/ **
davidr99 0:e5fc19091502 6 *****************************************************************************************/
davidr99 0:e5fc19091502 7
davidr99 0:e5fc19091502 8 #ifndef CAMERA_SHIELD_H
davidr99 0:e5fc19091502 9 #define CAMERA_SHIELD_H
davidr99 0:e5fc19091502 10
davidr99 0:e5fc19091502 11
davidr99 0:e5fc19091502 12 #include "mbed.h"
davidr99 0:e5fc19091502 13 #include "string.h"
davidr99 0:e5fc19091502 14 #include "MODSERIAL.h"
davidr99 0:e5fc19091502 15
davidr99 0:e5fc19091502 16 #define VC0706_PROTOCOL_SIGN 0x56
davidr99 0:e5fc19091502 17 #define VC0706_SERIAL_NUMBER 0x00
davidr99 0:e5fc19091502 18
davidr99 0:e5fc19091502 19 #define VC0706_COMMAND_RESET 0x26
davidr99 0:e5fc19091502 20 #define VC0706_COMMAND_GEN_VERSION 0x11
davidr99 0:e5fc19091502 21 #define VC0706_COMMAND_TV_OUT_CTRL 0x44
davidr99 0:e5fc19091502 22 #define VC0706_COMMAND_OSD_ADD_CHAR 0x45
davidr99 0:e5fc19091502 23 #define VC0706_COMMAND_DOWNSIZE_SIZE 0x53
davidr99 0:e5fc19091502 24 #define VC0706_COMMAND_READ_FBUF 0x32
davidr99 0:e5fc19091502 25 #define FBUF_CURRENT_FRAME 0
davidr99 0:e5fc19091502 26 #define FBUF_NEXT_FRAME 0
davidr99 0:e5fc19091502 27
davidr99 0:e5fc19091502 28 #define VC0706_COMMAND_FBUF_CTRL 0x36
davidr99 0:e5fc19091502 29 #define VC0706_COMMAND_COMM_MOTION_CTRL 0x37
davidr99 0:e5fc19091502 30 #define VC0706_COMMAND_COMM_MOTION_DETECTED 0x39
davidr99 0:e5fc19091502 31 #define VC0706_COMMAND_POWER_SAVE_CTRL 0x3E
davidr99 0:e5fc19091502 32 #define VC0706_COMMAND_COLOR_CTRL 0x3C
davidr99 0:e5fc19091502 33 #define VC0706_COMMAND_MOTION_CTRL 0x42
davidr99 0:e5fc19091502 34
davidr99 0:e5fc19091502 35
davidr99 0:e5fc19091502 36 #define VC0706_COMMAND_WRITE_DATA 0x31
davidr99 0:e5fc19091502 37 #define VC0706_COMMAND_GET_FBUF_LEN 0x34
davidr99 0:e5fc19091502 38
davidr99 0:e5fc19091502 39 #define READ_DATA_BLOCK_NO 56
davidr99 0:e5fc19091502 40
davidr99 0:e5fc19091502 41 #define VC0706_640x480 0x00
davidr99 0:e5fc19091502 42 #define VC0706_320x240 0x11
davidr99 0:e5fc19091502 43 #define VC0706_160x120 0x22
davidr99 0:e5fc19091502 44
davidr99 0:e5fc19091502 45
davidr99 0:e5fc19091502 46
davidr99 0:e5fc19091502 47 class CameraShield
davidr99 0:e5fc19091502 48 {
davidr99 0:e5fc19091502 49 public:
davidr99 0:e5fc19091502 50 CameraShield ( PinName tx, PinName rx, int speed = 115200 );
davidr99 0:e5fc19091502 51
davidr99 0:e5fc19091502 52 void Init();
davidr99 0:e5fc19091502 53 void VC0706_reset();
davidr99 0:e5fc19091502 54 void VC0706_get_version();
davidr99 0:e5fc19091502 55 void VC0706_tv_out_control(int on);
davidr99 0:e5fc19091502 56 void VC0706_osd_add_char(int col, int row, char * osd_string);
davidr99 0:e5fc19091502 57 void VC0706_w_h_downsize(int scale_width, int scale_height);
davidr99 0:e5fc19091502 58 void VC0706_read_frame_buffer(unsigned long buffer_address, unsigned long buffer_length);
davidr99 0:e5fc19091502 59 void VC0706_frame_control(char frame_control);
davidr99 0:e5fc19091502 60 void VC0706_motion_detection(int control_flag);
davidr99 0:e5fc19091502 61 void VC0706_motion_control(int control_flag);
davidr99 0:e5fc19091502 62 void VC0706_get_framebuffer_length(char fbuf_type);
davidr99 0:e5fc19091502 63 void VC0706_uart_power_save(char power_save_on);
davidr99 0:e5fc19091502 64 void VC0706_uart_color_control(char show_mode);
davidr99 0:e5fc19091502 65 void VC0706_compression_ratio(int ratio);
davidr99 0:e5fc19091502 66 void VC0706_motion_windows_setting(unsigned int register_address, unsigned long data);
davidr99 0:e5fc19091502 67 uint32_t VC0706_get_frame_buffer_length();
davidr99 0:e5fc19091502 68 void VC0706_image_size(int ratio);
davidr99 0:e5fc19091502 69 void TakeSnapShot();
davidr99 0:e5fc19091502 70 void ResumeVideo();
davidr99 0:e5fc19091502 71 void buffer_send(unsigned char *buff, int buffSize);
davidr99 0:e5fc19091502 72 int buffer_read(unsigned char *buff, int buffSize);
davidr99 0:e5fc19091502 73
davidr99 0:e5fc19091502 74 private:
davidr99 0:e5fc19091502 75 MODSERIAL _serial;
davidr99 0:e5fc19091502 76
davidr99 0:e5fc19091502 77 };
davidr99 0:e5fc19091502 78
davidr99 0:e5fc19091502 79 #endif