├── _registers ├── ov2640_regs.h ├── ov5640_regs.h ├── mt9t112_regs.h ├── mt9m001_regs.h ├── ov7725_regs.h ├── mt9v111_regs.h ├── ov3640_regs.h ├── ov7660_regs.h ├── _cpu_commons.h ├── ov7675_regs.h ├── ov7670_regs.h ├── _sensorsDefinitions.h └── mt9m112_regs.h ├── examples ├── mini │ ├── ArduCAM_host_v1.0.exe │ ├── ArduCAM_Mini_OV2640_Yun_WebServer │ │ ├── ArduCAMYun │ │ │ ├── shot.png │ │ │ └── index.html │ │ └── ArduCAM_Mini_OV2640_Yun_WebServer.ino │ ├── ArduCAM_Mini_OV5642_Yun_WebServer │ │ ├── ArduCAMYun │ │ │ ├── shot.png │ │ │ └── index.html │ │ └── ArduCAM_Mini_OV5642_Yun_WebServer.ino │ ├── ArduCAM_Mini_OV5642_LowPowerMode │ │ └── ArduCAM_Mini_OV5642_LowPowerMode.ino │ ├── ArduCAM_Mini_2MP_TimeElapse2SD │ │ └── ArduCAM_Mini_2MP_TimeElapse2SD.ino │ ├── ArduCAM_Mini_OV5642_FIFO_UART_Burst │ │ └── ArduCAM_Mini_OV5642_FIFO_UART_Burst.ino │ ├── ArduCAM_Mini_5MP_TimeElapse2SD │ │ └── ArduCAM_Mini_5MP_TimeElapse2SD.ino │ ├── ArduCAM_Mini_OV2640_LowPowerMode │ │ └── ArduCAM_Mini_OV2640_LowPowerMode.ino │ └── ArduCAM_Mini_OV2640_FIFO_UART_Burst │ │ └── ArduCAM_Mini_OV2640_FIFO_UART_Burst.ino ├── ESP8266 │ └── ArduCAM_Mini_OV2640_websocket_server │ │ ├── html │ │ ├── websock_camera.ucf │ │ ├── images │ │ │ ├── ESP8266_demo.jpg │ │ │ └── ti_simplelink.jpg │ │ └── camera_demo.html │ │ └── ArduCAM_Mini_OV2640_websocket_server.ino ├── testing │ ├── ArduCAM_I2C_TEST │ │ └── ArduCAM_I2C_TEST.ino │ └── ArduCAM_SPI_BUS_TEST │ │ └── ArduCAM_SPI_BUS_TEST.ino └── REVC │ ├── ArduCAM_SPI_OV5642_FIFO_UART │ └── ArduCAM_SPI_OV5642_FIFO_UART.ino │ ├── ArduCAM_SPI_OV2640_FIFO_UART │ └── ArduCAM_SPI_OV2640_FIFO_UART.ino │ ├── ArduCAM_MT9M001_Camera_RAW │ └── ArduCAM_MT9M001_Camera_RAW.ino │ ├── ArduCAM_OV2640_Digital_Camera │ └── ArduCAM_OV2640_Digital_Camera.ino │ ├── ArduCAM_OV5642_Digital_Camera │ └── ArduCAM_OV5642_Digital_Camera.ino │ ├── ArduCAM_OV7670_Camera_Playback │ └── ArduCAM_OV7670_Camera_Playback.ino │ ├── ArduCAM_OV3640_Camera_Playback │ └── ArduCAM_OV3640_Camera_Playback.ino │ ├── ArduCAM_OV7675_Camera_Playback │ └── ArduCAM_OV7675_Camera_Playback.ino │ ├── ArduCAM_MT9D111AF_Camera_Playback │ └── ArduCAM_MT9D111AF_Camera_Playback.ino │ ├── ArduCAM_MT9D111_Camera_Playback │ └── ArduCAM_MT9D111_Camera_Playback.ino │ ├── ArduCAM_Yun_OV2640_Digital_Camera │ └── ArduCAM_Yun_OV2640_Digital_Camera.ino.bak │ ├── ArduCAM_OV7660_Camera_Playback │ └── ArduCAM_OV7660_Camera_Playback.ino │ ├── ArduCAM_OV7725_Camera_Playback │ ├── ArduCAM_OV7725_Camera_Playback.ino │ └── ArduCAM_OV7725_Camera_Playback.ino.bak │ ├── ArduCAM_MT9D112_Camera_Playback │ └── ArduCAM_MT9D112_Camera_Playback.ino │ ├── ArduCAM_MT9T112_Camera_Playback │ └── ArduCAM_MT9T112_Camera_Playback.ino │ ├── ArduCAM_MT9M112_Camera_Playback │ └── ArduCAM_MT9M112_Camera_Playback.ino │ ├── ArduCAM_MT9V111_Camera_Playback │ └── ArduCAM_MT9V111_Camera_Playback.ino │ └── ArduCAM_OV2640_Camera_Playback │ └── ArduCAM_OV2640_Camera_Playback.ino ├── .gitattributes ├── .gitignore ├── README.md ├── memorysaver.h └── keywords.txt /_registers/ov2640_regs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sumotoy/ArduCAM/HEAD/_registers/ov2640_regs.h -------------------------------------------------------------------------------- /_registers/ov5640_regs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sumotoy/ArduCAM/HEAD/_registers/ov5640_regs.h -------------------------------------------------------------------------------- /examples/mini/ArduCAM_host_v1.0.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sumotoy/ArduCAM/HEAD/examples/mini/ArduCAM_host_v1.0.exe -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV2640_Yun_WebServer/ArduCAMYun/shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sumotoy/ArduCAM/HEAD/examples/mini/ArduCAM_Mini_OV2640_Yun_WebServer/ArduCAMYun/shot.png -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV5642_Yun_WebServer/ArduCAMYun/shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sumotoy/ArduCAM/HEAD/examples/mini/ArduCAM_Mini_OV5642_Yun_WebServer/ArduCAMYun/shot.png -------------------------------------------------------------------------------- /examples/ESP8266/ArduCAM_Mini_OV2640_websocket_server/html/websock_camera.ucf: -------------------------------------------------------------------------------- 1 | #Mon Aug 25 17:51:09 IST 2014 2 | com=54 3 | interface=CC31x Flash Connections 4 | device=CC31x Flash Devices 5 | -------------------------------------------------------------------------------- /examples/ESP8266/ArduCAM_Mini_OV2640_websocket_server/html/images/ESP8266_demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sumotoy/ArduCAM/HEAD/examples/ESP8266/ArduCAM_Mini_OV2640_websocket_server/html/images/ESP8266_demo.jpg -------------------------------------------------------------------------------- /examples/ESP8266/ArduCAM_Mini_OV2640_websocket_server/html/images/ti_simplelink.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sumotoy/ArduCAM/HEAD/examples/ESP8266/ArduCAM_Mini_OV2640_websocket_server/html/images/ti_simplelink.jpg -------------------------------------------------------------------------------- /_registers/mt9t112_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef MT9M112_REGS_H 2 | #define MT9M112_REGS_H 3 | #include "ArduCAM.h" 4 | //#include 5 | 6 | const struct sensor_reg MT9T112_QVGA[] PROGMEM = 7 | { 8 | {0xffff, 0xffff} 9 | }; 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /_registers/mt9m001_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef MT9M001_REGS_H 2 | #define MT9M001_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | 6 | const struct sensor_reg MT9M001_QVGA_30fps[] PROGMEM = 7 | { 8 | 9 | {0x03, 240},//Row Size 10 | {0x04, 639},//Col Size 11 | {0xff, 0xffff } 12 | }; 13 | 14 | #endif //MT9M001_REGS_H -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /examples/testing/ArduCAM_I2C_TEST/ArduCAM_I2C_TEST.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2013 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to communicate with camera modules 4 | // via I2C interface and send read data back to Serial Monitor in Arduino IDE. 5 | // 6 | // This demo was made for Omnivision OV5642 sensor. 7 | // 1. Receive commands from Serial Monitor 8 | // 2. Read Product ID from OV5642 registers 9 | // 3. Send back to Serial Monitor. 10 | // This program requires the ArduCAM V3.0.0 (or above) library and Rev.C ArduCAM shield 11 | // and use Arduino IDE 1.5.2 compiler 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "ov5642_regs.h" 19 | 20 | // set pin 10 as the slave select for the ArduCAM shield: 21 | const int slaveSelectPin = 10; 22 | 23 | ArduCAM myCAM(OV5642, 10); 24 | UTFT myGLCD(slaveSelectPin); 25 | 26 | void setup() 27 | { 28 | Serial.begin(115200); 29 | Serial.println("hello"); 30 | myCAM.begin(); 31 | 32 | myCAM.set_mode(MCU2LCD_MODE); 33 | delay(2000); 34 | myGLCD.InitLCD(); 35 | 36 | myCAM.set_format(JPEG); 37 | myCAM.InitCAM(); 38 | 39 | } 40 | 41 | void loop() 42 | { 43 | uint8_t temp; 44 | temp = Serial.read(); 45 | switch (temp) 46 | { 47 | case 0x11: 48 | myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &temp); 49 | Serial.write(temp); 50 | break; 51 | case 0x12: 52 | myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &temp); 53 | Serial.write(temp); 54 | break; 55 | default: 56 | break; 57 | } 58 | 59 | } 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV2640_Yun_WebServer/ArduCAMYun/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ArduCam Yun Web Server 6 | 7 | 17 | 18 | 19 | 20 |
21 | 22 | ArduCAM Yun Web Server 23 | 24 |
25 |
26 | 27 | 28 |
29 |
30 | 31 | 32 | 33 | 34 | 35 | 39 | 40 |
 
36 | 37 |
38 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV5642_Yun_WebServer/ArduCAMYun/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ArduCam Yun Web Server 6 | 7 | 17 | 18 | 19 | 20 |
21 | 22 | ArduCAM Yun Web Server 23 | 24 |
25 |
26 | 27 | 28 |
29 |
30 | 31 | 32 | 33 | 34 | 35 | 39 | 40 |
 
36 | 37 |
38 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /_registers/ov7725_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef OV7725_REGS_H 2 | #define OV7725_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | const struct sensor_reg OV7725_QVGA[] PROGMEM = 6 | { 7 | {0x32,0x00}, 8 | {0x2a,0x00}, 9 | {0x11,0x02}, 10 | {0x12,0x46},//QVGA RGB565 11 | {0x12,0x06}, 12 | 13 | 14 | {0x42,0x7f}, 15 | {0x4d,0x00},//0x09 16 | {0x63,0xf0}, 17 | {0x64,0xff}, 18 | {0x65,0x20}, 19 | {0x66,0x00}, 20 | {0x67,0x00}, 21 | {0x69,0x5d}, 22 | 23 | 24 | {0x13,0xff}, 25 | {0x0d,0x81},//PLL 26 | {0x0f,0xc5}, 27 | {0x14,0x11}, 28 | {0x22,0xFF},//7f 29 | {0x23,0x01}, 30 | {0x24,0x34}, 31 | {0x25,0x3c}, 32 | {0x26,0xa1}, 33 | {0x2b,0x00}, 34 | {0x6b,0xaa}, 35 | {0x13,0xff}, 36 | 37 | {0x90,0x0a},// 38 | {0x91,0x01},// 39 | {0x92,0x01},// 40 | {0x93,0x01}, 41 | 42 | {0x94,0x5f}, 43 | {0x95,0x53}, 44 | {0x96,0x11}, 45 | {0x97,0x1a}, 46 | {0x98,0x3d}, 47 | {0x99,0x5a}, 48 | {0x9a,0x1e}, 49 | 50 | {0x9b,0x00},//set luma 51 | {0x9c,0x25},//set contrast 52 | {0xa7,0x65},//set saturation 53 | {0xa8,0x65},//set saturation 54 | {0xa9,0x80},//set hue 55 | {0xaa,0x80},//set hue 56 | 57 | {0x9e,0x81}, 58 | {0xa6,0x06}, 59 | 60 | {0x7e,0x0c}, 61 | {0x7f,0x16}, 62 | {0x80,0x2a}, 63 | {0x81,0x4e}, 64 | {0x82,0x61}, 65 | {0x83,0x6f}, 66 | {0x84,0x7b}, 67 | {0x85,0x86}, 68 | {0x86,0x8e}, 69 | {0x87,0x97}, 70 | {0x88,0xa4}, 71 | {0x89,0xaf}, 72 | {0x8a,0xc5}, 73 | {0x8b,0xd7}, 74 | {0x8c,0xe8}, 75 | {0x8d,0x20}, 76 | 77 | {0x33,0x00}, 78 | {0x22,0x99}, 79 | {0x23,0x03}, 80 | {0x4a,0x00}, 81 | {0x49,0x13}, 82 | {0x47,0x08}, 83 | {0x4b,0x14}, 84 | {0x4c,0x17}, 85 | {0x46,0x05}, 86 | {0x0e,0x75}, 87 | {0x0c,0x90}, 88 | {0x00,0xf0}, 89 | {0x29,0x50}, 90 | {0x2C,0x78}, 91 | {0xff, 0xff}, 92 | }; 93 | 94 | 95 | #endif 96 | 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ArduCAM 2 | A refractored version of ArduCAM, keep away from distro because massive changes! 3 | Backgrounds:
4 | ArduCAM it's a nice hardware design, it uses an FPGA and camera with exchangeable lenses and internally does all the calculations so it's easy to integrate it in many project, Lee done a great work as hardware and FPGA design, the API are well done but the Arduino support it's actually a bit too messy for me, I cannot get working on a ESP8266 despite there's a tutorial on site (with wrong connection explained!), it completely missed support for Teensy and I had several problem with SPI transactions, not least, the SPI doesn't play nice with other SPI devices. Inside library there's a TFT library that I decided to avoid completely, it's an old version modified and once again it doesn't play nice with other SPI devices (and even this one lack of Teensy support). 5 | If everithing works as I suppose the end user can choose the TFT/OLED he prefere! 6 | I proposed some days ago a pull to Lee but at the end it's not enough, the original library carry initialization for many cameras so I will split all these in code chunks and create a virtual lib calls for the main code (that is common), this simplify a lot the integration on projects and user have just to declare withch came he's using at the start of the project. It have also the ability to use different cameras in the same project. 7 | Actually this version works perfectly with ESP8266 and Teensy 3.0, 3.1 and LC as opposed the original and I already modified some examples, other example will not work because I'm using a missed begin() function to initialize correctly (for the processor used) wire and SPI and now the library it's using the advantages of SPI Transactions (that recently was added to ESP8266 as well). 8 | This is a working on experiment so do not apology, I will use to propose to Lee some changes without using a massive pull to his original library (none developer like this). 9 | -------------------------------------------------------------------------------- /memorysaver.h: -------------------------------------------------------------------------------- 1 | #ifndef _MEMORYSAVER_ 2 | #define _MEMORYSAVER_ 3 | 4 | #include 5 | 6 | /****************************************************************/ 7 | /* define a structure for sensor register initialization values */ 8 | /****************************************************************/ 9 | 10 | struct sensor_reg { 11 | uint16_t reg; 12 | uint16_t val; 13 | }; 14 | 15 | //Uncomment the following definition when you use them 16 | //#define OV7660_CAM 17 | //#define OV7725_CAM 18 | //#define OV7670_CAM 19 | //#define OV7675_CAM 20 | #define OV2640_CAM 21 | //#define OV3640_CAM 22 | #define OV5642_CAM 23 | //#define MT9D111_CAM 24 | //#define MT9M112_CAM 25 | //#define MT9V111_CAM 26 | //#define OV5640_CAM 27 | //#define MT9M001_CAM 28 | //#define MT9T112_CAM 29 | #define MT9D112_CAM 30 | 31 | #if defined OV7660_CAM 32 | #include "_registers/ov7660_regs.h" 33 | #endif 34 | 35 | #if defined OV7725_CAM 36 | #include "_registers/ov7725_regs.h" 37 | #endif 38 | 39 | #if defined OV7670_CAM 40 | #include "_registers/ov7670_regs.h" 41 | #endif 42 | 43 | #if defined OV7675_CAM 44 | #include "_registers/ov7675_regs.h" 45 | #endif 46 | 47 | #if defined OV5642_CAM 48 | #include "_registers/ov5642_regs.h" 49 | #endif 50 | 51 | #if defined OV3640_CAM 52 | #include "_registers/ov3640_regs.h" 53 | #endif 54 | 55 | #if defined OV2640_CAM 56 | #include "_registers/ov2640_regs.h" 57 | #endif 58 | 59 | #if defined MT9D111_CAM 60 | #include "_registers/mt9d111_regs.h" 61 | #endif 62 | 63 | #if defined MT9M112_CAM 64 | #include "_registers/mt9m112_regs.h" 65 | #endif 66 | 67 | #if defined MT9V111_CAM 68 | #include "_registers/mt9v111_regs.h" 69 | #endif 70 | 71 | #if defined OV5640_CAM 72 | #include "_registers/ov5640_regs.h" 73 | #endif 74 | 75 | #if defined MT9M001_CAM 76 | #include "_registers/mt9m001_regs.h" 77 | #endif 78 | 79 | #if defined MT9T112_CAM 80 | #include "_registers/mt9t112_regs.h" 81 | #endif 82 | 83 | #if defined MT9D112_CAM 84 | #include "_registers/mt9d112_regs.h" 85 | #endif 86 | 87 | #endif //_MEMORYSAVER_ 88 | -------------------------------------------------------------------------------- /examples/testing/ArduCAM_SPI_BUS_TEST/ArduCAM_SPI_BUS_TEST.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2013 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to test the ArduCAM shield SPI communication 4 | // to check out if bus has errors. 5 | // 6 | // This demo was made for Omnivision OV5642 sensor. 7 | // 1. Write ArduCHIP internal test registers. 8 | // 2. Read out ArduCHIP internal test registers and send back to Serial Monitor 9 | // 3. Read out ArduCHIP internal Revision registers and send back to Serial Monitor 10 | // This program requires the ArduCAM V3.0.0 (or above) library and Rev.C ArduCAM shield 11 | // and use Arduino IDE 1.5.2 compiler 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | // set pin 10 as the slave select for the ArduCAM shield: 20 | const int slaveSelectPin = 10; 21 | 22 | 23 | ArduCAM myCAM(OV7670,slaveSelectPin); 24 | 25 | void setup() 26 | { 27 | Serial.begin(115200); 28 | Serial.println("Test START..."); 29 | // initialize SPI: 30 | myCAM.begin(true,false); 31 | 32 | } 33 | 34 | void loop() 35 | { 36 | uint8_t temp1,temp2,revision; 37 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); //Write to test1 register by 0x55 38 | myCAM.write_reg(ARDUCHIP_TEST2, 0xAA); //Write to test1 register by 0xaa 39 | delay(1000); 40 | temp1 = myCAM.read_reg(ARDUCHIP_TEST1); //Read from test1 register 41 | temp2 = myCAM.read_reg(ARDUCHIP_TEST2); //Read from test1 register 42 | Serial.write(temp1); 43 | Serial.write(temp2); 44 | delay(1000); 45 | myCAM.write_reg(ARDUCHIP_TEST1, 0xAA); //Write to test1 register by 0x55 46 | myCAM.write_reg(ARDUCHIP_TEST2, 0x55); //Write to test1 register by 0xaa 47 | delay(1000); 48 | temp1 = myCAM.read_reg(ARDUCHIP_TEST1); //Read from test1 register 49 | temp2 = myCAM.read_reg(ARDUCHIP_TEST2); //Read from test1 register 50 | Serial.write(temp1); 51 | Serial.write(temp2); 52 | delay(1000); 53 | revision = myCAM.read_reg(ARDUCHIP_REV); //Read from REV register 54 | Serial.write(revision); 55 | delay(1000); 56 | 57 | } 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /_registers/mt9v111_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef MT9V111_REGS_H 2 | #define MT9V111_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | 6 | #define I2C_SLAVE_ADDRESS 0xB8 7 | 8 | 9 | const struct sensor_reg MT9V111_QVGA[] PROGMEM = 10 | { 11 | {0x01, 0x04}, //REG=4 Sensor Core Register Access 12 | {64, 488 }, // anti-eclipse Vref 13 | {47, 63408}, //set for Fmclk>13.5MHz 14 | {2, 11}, 15 | {3, 487}, 16 | {4, 646}, 17 | {0x06, 70 }, //vertical blank, 18 | {32, 0x4000}, 19 | 20 | {0x01, 1}, //REG=1 IFP Register Access 21 | {0x08, 0xd802}, //RGB mode 22 | {58, 0x0001}, 23 | {165, 0x8000}, // [QVGA 1:1 zoom] 24 | {166, 0x8280}, // 25 | {167, 0x8140}, // 26 | {168, 0x8000}, // 27 | {169, 0x81e0}, // 28 | {170, 0x00f0}, // 29 | 30 | //[Auto Lens Correction Setup] 31 | {0x2B, 0x0022}, //(36) GREEN1_GAIN_REG 32 | {0x2C, 0x003E}, //(48) BLUE_GAIN_REG 33 | {0x2D, 0x0020}, //(53) RED_GAIN_REG 34 | {0x2E, 0x0066}, //(36) GREEN2_GAIN_REG 35 | {0x02, 0x0000}, //(18) BASE_MATRIX_SIGNS 36 | {0x03, 0x3923}, //(11) BASE_MATRIX_SCALE_K1_K5 37 | {0x04, 0x0724}, //(10) BASE_MATRIX_SCALE_K6_K9 38 | {0x06, 0xF00C}, //(14) MODE_CONTROL R6[14]:enable AEs 39 | {0x09, 0x0080}, //(3) BASE_MATRIX_COEF_K1 40 | {0x0A, 0x0000}, //(2) BASE_MATRIX_COEF_K2 41 | {0x0B, 0x0000}, //(2) BASE_MATRIX_COEF_K3 42 | {0x0C, 0x0000}, //(1) BASE_MATRIX_COEF_K4 43 | {0x0D, 0x0080}, //(3) BASE_MATRIX_COEF_K5 44 | {0x0E, 0x0000}, //(2) BASE_MATRIX_COEF_K6 45 | {0x0F, 0x0000}, //(2) BASE_MATRIX_COEF_K7 46 | {0x10, 0x0000}, //(2) BASE_MATRIX_COEF_K8 47 | {0x11, 0x0080}, //(3) BASE_MATRIX_COEF_K9 48 | {0x15, 0x0000}, //(21) DELTA_COEFS_SIGNS 49 | {0x16, 0x0000}, //(3) DELTA_MATRIX_COEF_D1 50 | {0x17, 0x0000}, //(2) DELTA_MATRIX_COEF_D2 51 | {0x18, 0x0000}, //(2) DELTA_MATRIX_COEF_D3 52 | {0x19, 0x0000}, //(1) DELTA_MATRIX_COEF_D4 53 | {0x1A, 0x0000}, //(3) DELTA_MATRIX_COEF_D5 54 | {0x1B, 0x0000}, //(2) DELTA_MATRIX_COEF_D6 55 | {0x1C, 0x0000}, //(2) DELTA_MATRIX_COEF_D7 56 | {0x1D, 0x0000}, //(2) DELTA_MATRIX_COEF_D8 57 | {0x1E, 0x0000}, //(4) DELTA_MATRIX_COEF_D9 58 | {0x25, 0x0514}, //(1) AWB_SPEED_SATURATION 59 | {0x34, 0x0010}, //(5) LUMA_OFFSET 60 | {0x35, 0xF010}, //(10) CLIPPING_LIM_OUT_LUMA 61 | {0x48, 0x0080}, //(1) TEST_PATTERN_GEN 62 | {0x53, 0x0804}, //(10) GAMMA_Y1_Y2 63 | {0x54, 0x2010}, //(10) GAMMA_Y3_Y4 64 | {0x55, 0x6040}, //(10) GAMMA_Y5_Y6 65 | {0x56, 0xA080}, //(10) GAMMA_Y7_Y8 66 | {0x57, 0xE0C0}, //(10) GAMMA_Y9_Y10 67 | 68 | {0xff, 0xffff}, 69 | }; 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ArduCAM KEYWORD1 2 | InitCAM KEYWORD2 3 | read_reg KEYWORD2 4 | write_reg KEYWORD2 5 | set_mode KEYWORD2 6 | get_bit KEYWORD2 7 | set_bit KEYWORD2 8 | clear_bit KEYWORD2 9 | read_fifo_length KEYWORD2 10 | enable_fifo KEYWORD2 11 | disable_fifo KEYWORD2 12 | flush_fifo KEYWORD2 13 | start_capture KEYWORD2 14 | clear_fifo_flag KEYWORD2 15 | read_fifo KEYWORD2 16 | read_reg KEYWORD2 17 | write_reg KEYWORD2 18 | OV2640_set_JPEG_size KEYWORD2 19 | startSend KEYWORD2 20 | endSend KEYWORD2 21 | sendData KEYWORD2 22 | set_format KEYWORD2 23 | wrSensorReg8_8 KEYWORD2 24 | wrSensorReg16_8 KEYWORD2 25 | wrSensorReg8_16 KEYWORD2 26 | wrSensorReg16_16 KEYWORD2 27 | rdSensorReg8_8 KEYWORD2 28 | rdSensorReg16_8 KEYWORD2 29 | rdSensorReg8_16 KEYWORD2 30 | rdSensorReg16_16 KEYWORD2 31 | read_fifo_length KEYWORD2 32 | set_fifo_burst KEYWORD2 33 | OV7670 LITERAL1 34 | MT9D111_A LITERAL1 35 | MT9D111_B LITERAL1 36 | OV7675 LITERAL1 37 | OV5642 LITERAL1 38 | OV3640 LITERAL1 39 | OV2640 LITERAL1 40 | OV7725 LITERAL1 41 | MT9M112 LITERAL1 42 | MT9M001 LITERAL1 43 | MT9V111 LITERAL1 44 | OV5640 LITERAL1 45 | OV5642 LITERAL1 46 | OV9650 LITERAL1 47 | MT9D112 LITERAL1 48 | MT9T112 LITERAL1 49 | OV9655 LITERAL1 50 | JPEG LITERAL1 51 | BMP LITERAL1 52 | FIFO_SIZE1 LITERAL1 53 | FIFO_SIZE2 LITERAL1 54 | FIFO_SIZE3 LITERAL1 55 | ARDUCHIP_FRAMES LITERAL1 56 | OV2640_160x120 LITERAL1 57 | OV2640_176x144 LITERAL1 58 | OV2640_320x240 LITERAL1 59 | OV2640_352x288 LITERAL1 60 | OV2640_640x480 LITERAL1 61 | OV2640_800x600 LITERAL1 62 | OV2640_1024x768 LITERAL1 63 | OV2640_1280x1024 LITERAL1 64 | OV2640_1600x1200 LITERAL1 65 | ARDUCHIP_TEST1 LITERAL1 66 | ARDUCHIP_TEST2 LITERAL1 67 | ARDUCHIP_MODE LITERAL1 68 | MCU2LCD_MODE LITERAL1 69 | CAM2LCD_MODE LITERAL1 70 | LCD2MCU_MODE LITERAL1 71 | ARDUCHIP_TIM LITERAL1 72 | HREF_LEVEL_MASK LITERAL1 73 | VSYNC_LEVEL_MASK LITERAL1 74 | LCD_BKEN_MASK LITERAL1 75 | DELAY_MASK LITERAL1 76 | MODE_MASK LITERAL1 77 | FIFO_PWRDN_MASK LITERAL1 78 | LOW_POWER_MODE LITERAL1 79 | ARDUCHIP_FIFO LITERAL1 80 | FIFO_CLEAR_MASK LITERAL1 81 | FIFO_START_MASK LITERAL1 82 | FIFO_RDPTR_RST_MASK LITERAL1 83 | FIFO_WRPTR_RST_MASK LITERAL1 84 | ARDUCHIP_GPIO LITERAL1 85 | GPIO_RESET_MASK LITERAL1 86 | GPIO_PWDN_MASK LITERAL1 87 | BURST_FIFO_READ LITERAL1 88 | ARDUCHIP_REV LITERAL1 89 | VER_LOW_MASK LITERAL1 90 | VER_HIGH_MASK LITERAL1 91 | ARDUCHIP_TRIG LITERAL1 92 | VSYNC_MASK LITERAL1 93 | SHUTTER_MASK LITERAL1 94 | CAP_DONE_MASK LITERAL1 95 | OV2640_CHIPID_HIGH LITERAL1 96 | OV2640_CHIPID_LOW LITERAL1 97 | OV5642_CHIPID_HIGH LITERAL1 98 | OV5642_CHIPID_LOW LITERAL1 99 | 100 | -------------------------------------------------------------------------------- /_registers/ov3640_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef OV3640_REGS_H 2 | #define OV3640_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | const struct sensor_reg OV3640_QVGA[] PROGMEM = 6 | { 7 | {0x3012, 0x80}, 8 | {0x304d, 0x45}, 9 | {0x30a7, 0x5e}, 10 | {0x3087, 0x16}, 11 | {0x309c, 0x1a}, 12 | {0x30a2, 0xe4}, 13 | {0x30aa, 0x42}, 14 | {0x30b0, 0xff}, 15 | {0x30b1, 0xff}, 16 | {0x30b2, 0x10}, 17 | {0x300e, 0x32}, 18 | {0x300f, 0x21}, 19 | {0x3010, 0x20}, 20 | {0x3011, 0x4}, 21 | {0x304c, 0x81}, 22 | {0x30d7, 0x10}, 23 | {0x30d9, 0xd}, 24 | {0x30db, 0x8}, 25 | {0x3016, 0x82}, 26 | {0x3018, 0x38}, 27 | {0x3019, 0x30}, 28 | {0x301a, 0x61}, 29 | {0x307d, 0x0}, 30 | {0x3087, 0x2}, 31 | {0x3082, 0x20}, 32 | {0x3015, 0x12}, 33 | {0x3014, 0x4}, 34 | {0x3013, 0xf7}, 35 | {0x303c, 0x8}, 36 | {0x303d, 0x18}, 37 | 38 | {0x303e, 0x6}, 39 | {0x303f, 0xc}, 40 | {0x3030, 0x62}, 41 | {0x3031, 0x26}, 42 | {0x3032, 0xe6}, 43 | {0x3033, 0x6e}, 44 | {0x3034, 0xea}, 45 | {0x3035, 0xae}, 46 | {0x3036, 0xa6}, 47 | {0x3037, 0x6a}, 48 | {0x3104, 0x2}, 49 | {0x3105, 0xfd}, 50 | {0x3106, 0x0}, 51 | {0x3107, 0xff}, 52 | {0x3300, 0x12}, 53 | {0x3301, 0xde}, 54 | {0x3302, 0xef}, 55 | {0x3316, 0xff}, 56 | {0x3317, 0x0}, 57 | {0x3312, 0x26}, 58 | {0x3314, 0x42}, 59 | {0x3313, 0x2b}, 60 | {0x3315, 0x42}, 61 | {0x3310, 0xd0}, 62 | {0x3311, 0xbd}, 63 | {0x330c, 0x18}, 64 | {0x330d, 0x18}, 65 | {0x330e, 0x56}, 66 | {0x330f, 0x5c}, 67 | {0x330b, 0x1c}, 68 | {0x3306, 0x5c}, 69 | {0x3307, 0x11}, 70 | {0x336a, 0x52}, 71 | {0x3370, 0x46}, 72 | {0x3376, 0x38}, 73 | {0x3300, 0x13}, 74 | {0x30b8, 0x20}, 75 | {0x30b9, 0x17}, 76 | {0x30ba, 0x4}, 77 | {0x30bb, 0x8}, 78 | 79 | {0x3507, 0x6}, 80 | {0x350a, 0x4f}, 81 | {0x3100, 0x2}, 82 | {0x3301, 0xde}, 83 | {0x3304, 0x0}, 84 | {0x3400, 0x1}, 85 | {0x3404, 0x11}, 86 | {0x335f, 0x68}, 87 | {0x3360, 0x18}, 88 | {0x3361, 0xc}, 89 | {0x3362, 0x12}, 90 | {0x3363, 0x88}, 91 | {0x3364, 0xe4}, 92 | {0x3403, 0x42}, 93 | {0x3088, 0x2}, 94 | {0x3089, 0x80}, 95 | {0x308a, 0x1}, 96 | {0x308b, 0xe0}, 97 | {0x308d, 0x4}, 98 | {0x3086, 0x3}, 99 | {0x3086, 0x0}, 100 | {0x3011, 0x0}, 101 | {0x304c, 0x85}, 102 | {0x3600, 0xd0}, 103 | {0x335f, 0x68}, 104 | {0x3360, 0x18}, 105 | {0x3361, 0xc}, 106 | {0x3362, 0x1}, 107 | {0x3363, 0x48}, 108 | {0x3364, 0xf4}, 109 | {0x3403, 0x42}, 110 | {0x3088, 0x1}, 111 | {0x3089, 0x40}, 112 | {0x308a, 0x0}, 113 | {0x308b, 0xf0}, 114 | 115 | {0x307c, 0x12}, 116 | {0x3090, 0xc8}, 117 | 118 | //{0x3080, 0x02}, 119 | //{0x307D, 0x80}, 120 | //{0x306C, 0x10}, 121 | 122 | {0x3600, 0xc4}, 123 | {0xffff,0xff}, 124 | }; 125 | 126 | 127 | #endif 128 | 129 | -------------------------------------------------------------------------------- /_registers/ov7660_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef OV7660_REGS_H 2 | #define OV7660_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | const struct sensor_reg OV7660_QVGA[] PROGMEM = 6 | { 7 | {0x11, 0x83}, 8 | {0x92, 0x48}, 9 | {0x93, 0x00}, 10 | {0x9d, 0x31}, 11 | {0x9e, 0x29}, 12 | {0x3b, 0x02}, 13 | {0x13, 0xf2}, 14 | {0x10, 0x00}, 15 | {0x00, 0x00}, 16 | {0x01, 0x80}, 17 | {0x02, 0x80}, 18 | {0x13, 0xf7}, 19 | {0x12, 0x14}, 20 | {0x04, 0x00}, 21 | {0x18, 0x4b}, 22 | {0x17, 0x23}, 23 | {0x32, 0xbf}, 24 | {0x19, 0x02}, 25 | {0x1a, 0x7a}, 26 | {0x03, 0x00}, 27 | {0x0e, 0x84}, 28 | {0x0f, 0x62}, 29 | {0x15, 0x02}, 30 | {0x16, 0x02}, 31 | {0x1b, 0x01}, 32 | {0x1e, 0x01}, 33 | {0x29, 0x3c}, 34 | {0x33, 0x00}, 35 | {0x34, 0x07}, 36 | {0x35, 0x84}, 37 | {0x36, 0x00}, 38 | {0x38, 0x13}, 39 | {0x39, 0x43}, 40 | {0x3a, 0x00}, 41 | {0x3c, 0x6c}, 42 | {0x3d, 0x90}, 43 | {0x3f, 0x29}, 44 | {0x40, 0xd1}, 45 | {0x41, 0x20}, 46 | {0x6b, 0x0a}, 47 | {0xa1, 0xc8}, 48 | {0x69, 0x80}, 49 | {0x43, 0xf0}, 50 | {0x44, 0x10}, 51 | {0x45, 0x78}, 52 | {0x46, 0xa8}, 53 | {0x47, 0x60}, 54 | {0x48, 0x80}, 55 | {0x59, 0xba}, 56 | {0x5a, 0x9a}, 57 | {0x5b, 0x22}, 58 | {0x5c, 0xb9}, 59 | {0x5d, 0x9b}, 60 | {0x5e, 0x10}, 61 | {0x5f, 0xe0}, 62 | {0x60, 0x85}, 63 | {0x61, 0x60}, 64 | {0x9f, 0x9d}, 65 | {0xa0, 0xa0}, 66 | {0x4f, 0xae}, 67 | {0x50, 0x26}, 68 | {0x51, 0x08}, 69 | {0x52, 0x1a}, 70 | {0x53, 0xa9}, 71 | {0x54, 0x0f}, 72 | {0x55, 0x05}, 73 | {0x56, 0x46}, 74 | {0x57, 0xcb}, 75 | {0x58, 0x77}, 76 | {0x8b, 0xcc}, 77 | {0x8c, 0xcc}, 78 | {0x8d, 0xcf}, 79 | {0x6c, 0x40}, 80 | {0x6d, 0x30}, 81 | {0x6e, 0x4b}, 82 | {0x6f, 0x60}, 83 | {0x70, 0x70}, 84 | {0x71, 0x70}, 85 | {0x72, 0x70}, 86 | {0x73, 0x70}, 87 | {0x74, 0x60}, 88 | {0x75, 0x60}, 89 | {0x76, 0x50}, 90 | {0x77, 0x48}, 91 | {0x78, 0x3a}, 92 | {0x79, 0x2e}, 93 | {0x7a, 0x28}, 94 | {0x7b, 0x22}, 95 | {0x7c, 0x04}, 96 | {0x7d, 0x07}, 97 | {0x7e, 0x10}, 98 | {0x7f, 0x28}, 99 | {0x80, 0x36}, 100 | {0x81, 0x44}, 101 | {0x82, 0x52}, 102 | {0x83, 0x60}, 103 | {0x84, 0x6c}, 104 | {0x85, 0x78}, 105 | {0x86, 0x8c}, 106 | {0x87, 0x9e}, 107 | {0x88, 0xbb}, 108 | {0x89, 0xd2}, 109 | {0x8a, 0xe6}, 110 | {0x14, 0x2e}, 111 | {0x24, 0x68}, 112 | {0x25, 0x58}, 113 | {0xff, 0xff}, 114 | }; 115 | 116 | 117 | #endif 118 | 119 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_SPI_OV5642_FIFO_UART/ArduCAM_SPI_OV5642_FIFO_UART.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2013 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV5642 sensor. 7 | // 1. Set the sensor to JPEG output mode. 8 | // 2. Capture and buffer the image to FIFO. 9 | // 3. Transfer the captured JPEG image back to host via Arduino board USB port. 10 | // This program requires the ArduCAM V3.0.0 (or above) library and Rev.C ArduCAM shield 11 | // and use Arduino IDE 1.5.2 compiler 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "memorysaver.h" 20 | 21 | // set pin 10 as the slave select for the digital pot: 22 | const int SPI_CS = 10; 23 | 24 | 25 | ArduCAM myCAM(OV5642,10); 26 | UTFT myGLCD(SPI_CS); 27 | 28 | void setup() 29 | { 30 | uint8_t vid,pid; 31 | uint8_t temp; 32 | #if defined (__AVR__) 33 | Wire.begin(); 34 | #endif 35 | #if defined(__arm__) 36 | Wire1.begin(); 37 | #endif 38 | Serial.begin(115200); 39 | Serial.println("ArduCAM Start!"); 40 | 41 | // set the SPI_CS as an output: 42 | pinMode(SPI_CS, OUTPUT); 43 | 44 | // initialize SPI: 45 | SPI.begin(); 46 | //Check if the ArduCAM SPI bus is OK 47 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 48 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 49 | if(temp != 0x55) 50 | { 51 | Serial.println("SPI interface Error!"); 52 | while(1); 53 | } 54 | 55 | //Change MCU mode 56 | myCAM.set_mode(MCU2LCD_MODE); 57 | 58 | //Check if the camera module type is OV5642 59 | myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); 60 | myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); 61 | if((vid != 0x56) || (pid != 0x42)) 62 | Serial.println("Can't find OV5642 module!"); 63 | else 64 | Serial.println("OV5642 detected"); 65 | 66 | //Change to JPEG capture mode and initialize the OV5642 module 67 | myCAM.set_format(JPEG); 68 | myCAM.InitCAM(); 69 | myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH 70 | } 71 | 72 | void loop() 73 | { 74 | uint8_t temp,temp_last; 75 | uint8_t start_capture = 0; 76 | 77 | temp = Serial.read(); 78 | switch(temp) 79 | { 80 | case 0x10: 81 | start_capture = 1; 82 | Serial.println("Start Capture"); 83 | myCAM.flush_fifo(); 84 | break; 85 | default: 86 | break; 87 | } 88 | //start_capture = 1; 89 | if(start_capture) 90 | { 91 | //Clear the capture done flag 92 | myCAM.clear_fifo_flag(); 93 | //Start capture 94 | myCAM.start_capture(); 95 | } 96 | if(myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)) 97 | { 98 | Serial.println("Capture Done!"); 99 | 100 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 101 | { 102 | temp_last = temp; 103 | temp = myCAM.read_fifo(); 104 | Serial.write(temp); 105 | } 106 | 107 | //Clear the capture done flag 108 | myCAM.clear_fifo_flag(); 109 | start_capture = 0; 110 | } 111 | } 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /_registers/_cpu_commons.h: -------------------------------------------------------------------------------- 1 | #ifndef _CPU_COMM__H_ 2 | #define _CPU_COMM__H_ 3 | 4 | #include "Arduino.h" 5 | #include 6 | 7 | #if defined (__AVR__) 8 | #define cbi(reg, bitmask) *reg &= ~bitmask 9 | #define sbi(reg, bitmask) *reg |= bitmask 10 | //#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask); 11 | //#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask); 12 | 13 | //#define cport(port, data) port &= data 14 | //#define sport(port, data) port |= data 15 | 16 | #define swap(type, i, j) {type t = i; i = j; j = t;} 17 | 18 | #define fontbyte(x) pgm_read_byte(&cfont.font[x]) 19 | 20 | #define regtype volatile uint8_t 21 | #define regsize uint8_t 22 | 23 | 24 | //sure way to detect DUE 25 | #elif defined(ARDUINO_ARCH_SAM) && !defined(TEENSYDUINO) && !defined(ARDUINO_ARCH_SAMD) && !defined(ESP8266) && !defined(ARDUINO_ARCH_STM32F2) 26 | 27 | #define cbi(reg, bitmask) *reg &= ~bitmask 28 | #define sbi(reg, bitmask) *reg |= bitmask 29 | //#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask); 30 | //#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask); 31 | 32 | //#define cport(port, data) port &= data 33 | //#define sport(port, data) port |= data 34 | 35 | #define swap(type, i, j) {type t = i; i = j; j = t;} 36 | 37 | #define fontbyte(x) cfont.font[x] 38 | 39 | #define regtype volatile uint32_t 40 | #define regsize uint32_t 41 | #define PROGMEM 42 | 43 | 44 | #define pgm_read_byte(x) (*((char *)x)) 45 | // #define pgm_read_word(x) (*((short *)(x & 0xfffffffe))) 46 | #define pgm_read_word(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))) 47 | #define pgm_read_byte_near(x) (*((char *)x)) 48 | #define pgm_read_byte_far(x) (*((char *)x)) 49 | // #define pgm_read_word_near(x) (*((short *)(x & 0xfffffffe)) 50 | // #define pgm_read_word_far(x) (*((short *)(x & 0xfffffffe))) 51 | #define pgm_read_word_near(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))) 52 | #define pgm_read_word_far(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))) 53 | #define PSTR(x) x 54 | #if defined F 55 | #undef F 56 | #endif 57 | #define F(X) (X) 58 | 59 | //teensy' ARM 60 | #elif defined(TEENSYDUINO) 61 | 62 | //#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask); 63 | //#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask); 64 | 65 | //#define cport(port, data) port &= data 66 | //#define sport(port, data) port |= data 67 | 68 | #define swap(type, i, j) {type t = i; i = j; j = t;} 69 | 70 | #define fontbyte(x) cfont.font[x] 71 | 72 | #define regtype volatile uint8_t 73 | #define regsize uint8_t 74 | 75 | 76 | 77 | #elif defined(ESP8266) 78 | 79 | //#define cbi(reg, bitmask) digitalWrite(bitmask, LOW) 80 | //#define sbi(reg, bitmask) digitalWrite(bitmask, HIGH) 81 | //#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask); 82 | //#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask); 83 | 84 | //#define cport(port, data) port &= data 85 | //#define sport(port, data) port |= data 86 | 87 | #define swap(type, i, j) {type t = i; i = j; j = t;} 88 | 89 | #define fontbyte(x) cfont.font[x] 90 | 91 | #define regtype volatile uint32_t 92 | #define regsize uint32_t 93 | 94 | #endif 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /examples/ESP8266/ArduCAM_Mini_OV2640_websocket_server/html/camera_demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 101 | 102 | 103 | 104 | 105 | 115 | 116 | 117 | 118 | 119 | 120 | 122 | 123 |
100 | Camera Demo

106 | 107 |
108 | Location:
109 | 110 | 111 |

112 | Websocket Message:
113 | 114 |
121 |
124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV5642_LowPowerMode/ArduCAM_Mini_OV5642_LowPowerMode.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "memorysaver.h" 5 | 6 | // set pin 4 as the slave select for the digital pot: 7 | const int CS = 4; 8 | 9 | ArduCAM myCAM(OV5642,CS); 10 | 11 | void setup() { 12 | uint8_t vid,pid; 13 | uint8_t temp; 14 | #if defined (__AVR__) 15 | Wire.begin(); 16 | #endif 17 | #if defined(__arm__) 18 | Wire1.begin(); 19 | #endif 20 | Serial.begin(921600); 21 | Serial.println("ArduCAM Start!"); 22 | 23 | // set the SPI_CS as an output: 24 | pinMode(CS, OUTPUT); 25 | 26 | // initialize SPI: 27 | SPI.begin(); 28 | //Check if the ArduCAM SPI bus is OK 29 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 30 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 31 | //Serial.println(temp); 32 | if(temp != 0x55) 33 | { 34 | Serial.println("SPI1 interface Error!"); 35 | //while(1); 36 | } 37 | 38 | //Check if the camera module type is OV5642 39 | myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); 40 | myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); 41 | if((vid != 0x56) || (pid != 0x42)) 42 | Serial.println("Can't find OV5642 module!"); 43 | else 44 | Serial.println("OV5642 detected."); 45 | 46 | //Change to JPEG capture mode and initialize the OV5642 module 47 | myCAM.set_format(JPEG); 48 | myCAM.InitCAM(); 49 | myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); 50 | 51 | myCAM.clear_fifo_flag(); 52 | myCAM.write_reg(ARDUCHIP_FRAMES,0x00); 53 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);//enable low power 54 | } 55 | 56 | void loop() { 57 | uint8_t temp,temp_last; 58 | uint8_t start_capture = 0; 59 | 60 | temp = Serial.read(); 61 | switch(temp) 62 | { 63 | case 0: 64 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 65 | myCAM.OV5642_set_JPEG_size(OV5642_320x240); 66 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 67 | break; 68 | case 1: 69 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 70 | myCAM.OV5642_set_JPEG_size(OV5642_640x480); 71 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 72 | break; 73 | case 2: 74 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 75 | myCAM.OV5642_set_JPEG_size(OV5642_1280x720); 76 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 77 | break; 78 | case 3: 79 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 80 | myCAM.OV5642_set_JPEG_size(OV5642_1920x1080); 81 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 82 | break; 83 | case 4: 84 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 85 | myCAM.OV5642_set_JPEG_size(OV5642_2048x1563); 86 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 87 | break; 88 | case 5: 89 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 90 | myCAM.OV5642_set_JPEG_size(OV5642_2592x1944); 91 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 92 | break; 93 | case 0x10: 94 | start_capture = 1; 95 | Serial.println("CAM1 start single shot."); 96 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);//disable low power 97 | 98 | delay(800); 99 | break; 100 | default: 101 | break; 102 | } 103 | if(start_capture == 1) 104 | { 105 | myCAM.flush_fifo(); 106 | myCAM.clear_fifo_flag(); 107 | //Start capture 108 | myCAM.start_capture(); 109 | start_capture = 0; 110 | } 111 | if(myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) 112 | { 113 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 114 | Serial.println("CAM1 Capture Done!"); 115 | temp = 0; 116 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 117 | { 118 | temp_last = temp; 119 | temp = myCAM.read_fifo(); 120 | Serial.write(temp); 121 | delayMicroseconds(10); 122 | } 123 | //Clear the capture done flag 124 | myCAM.clear_fifo_flag(); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /_registers/ov7675_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef OV7675_REGS_H 2 | #define OV7675_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | #define OV7675_CHIPID_HIGH 0x0A 6 | #define OV7675_CHIPID_LOW 0x0B 7 | const struct sensor_reg OV7675_QVGA[] PROGMEM = 8 | { 9 | {0x11,0x80}, 10 | {0x3a,0x4}, 11 | {0x12,0x0}, 12 | {0x17,0x13}, 13 | {0x18,0x1}, 14 | {0x32,0xb6}, 15 | {0x19,63}, 16 | {0x1a,0x7b}, 17 | {0x03,0x01}, 18 | {0xc,0x0}, 19 | {0x3e,0x0}, 20 | {0x70,0x3a}, 21 | {0x71,0x35}, 22 | {0x72,0x11}, 23 | {0x73,0xf0}, 24 | {0xa2,0x2}, 25 | {0x15,0x0}, 26 | {0x7a,0x18}, 27 | {0x7b,0x4}, 28 | {0x7c,0x9}, 29 | {0x7d,0x18}, 30 | {0x7e,0x38}, 31 | {0x7f,0x47}, 32 | {0x80,0x56}, 33 | {0x81,0x66}, 34 | {0x82,0x74}, 35 | {0x83,0x7f}, 36 | {0x84,0x89}, 37 | {0x85,0x9a}, 38 | {0x86,0xa9}, 39 | {0x87,0xc4}, 40 | {0x88,0xdb}, 41 | {0x89,0xee}, 42 | {0x13,0xe0}, 43 | {0x1,0x50}, 44 | {0x2,0x68}, 45 | {0x0,0x0}, 46 | {0x10,0x0}, 47 | {0xd,0x40}, 48 | {0x14,0x48}, 49 | {0x15,0x07}, 50 | {0xab,0x8}, 51 | {0x24,0x60}, 52 | {0x25,0x50}, 53 | {0x26,0xe3}, 54 | {0x9f,0x78}, 55 | {0xa0,0x68}, 56 | {0xa1,0x3}, 57 | {0xa6,0xd8}, 58 | {0xa7,0xd8}, 59 | {0xa8,0xf0}, 60 | {0xa9,0x90}, 61 | {0xaa,0x14}, 62 | {0x13,0xe5}, 63 | {0xe,0x61}, 64 | {0xf,0x4b}, 65 | {0x16,0x2}, 66 | {0x1e,0x27},//0x1e,0x17 67 | {0x21,0x2}, 68 | {0x22,0x91}, 69 | {0x29,0x07}, 70 | {0x33,0xb}, 71 | {0x35,0xb}, 72 | {0x37,0x1d}, 73 | {0x38,0x71}, 74 | {0x39,0x2a}, 75 | {0x3c,0x78}, 76 | {0x4d,0x40}, 77 | {0x4e,0x20}, 78 | {0x69,0x0}, 79 | {0x4e,0x20}, 80 | {0x74,0x10}, 81 | {0x8d,0x4f}, 82 | {0x8e,0x0}, 83 | {0x8f,0x0}, 84 | {0x90,0x0}, 85 | {0x91,0x0}, 86 | {0x92,0x66}, 87 | {0x96,0x0}, 88 | {0x9a,0x80}, 89 | {0xb0,0x84}, 90 | {0xb1,0xc}, 91 | {0xb2,0xe}, 92 | {0xb3,0x82}, 93 | {0xb8,0x0a}, 94 | {0x43,0x14}, 95 | {0x44,0xf0}, 96 | {0x45,0x41}, 97 | {0x46,0x66}, 98 | {0x47,0x2a}, 99 | {0x48,0x3e}, 100 | {0x59,0x8d}, 101 | {0x5a,0x8e}, 102 | {0x5b,0x53}, 103 | {0x5c,0x83}, 104 | {0x5d,0x4f}, 105 | {0x5e,0xe}, 106 | {0x6c,0x0a}, 107 | {0x6d,0x55}, 108 | {0x6e,0x11}, 109 | {0x6f,0x9e}, 110 | {0x62,0x90}, 111 | {0x63,0x30}, 112 | {0x64,0x11}, 113 | {0x65,0x0}, 114 | {0x66,0x5}, 115 | {0x94,0x11}, 116 | {0x95,0x18}, 117 | {0x6a,0x40}, 118 | {0x1,0x40}, 119 | {0x2,0x40}, 120 | {0x13,0xe7}, 121 | {0x4f,0x80}, 122 | {0x50,0x80}, 123 | {0x51,0x0}, 124 | {0x52,0x22}, 125 | {0x53,0x5e}, 126 | {0x54,0x80}, 127 | {0x58,0x9e}, 128 | {0x41,0x8}, 129 | {0x3f,0x0}, 130 | {0x75,0x3}, 131 | {0x76,0xe1}, 132 | {0x4c,0x0}, 133 | {0x77,0x0}, 134 | {0x3d,0xc2}, 135 | {0x4b,0x9}, 136 | {0xc9,0x60}, 137 | {0x41,0x38}, 138 | {0x56,0x3a}, 139 | {0x34,0x11}, 140 | {0x3b,0x0a}, 141 | {0xa4,0x88}, 142 | {0x96,0x0}, 143 | {0x97,0x30}, 144 | {0x98,0x20}, 145 | {0x99,0x30}, 146 | {0x9a,0x84}, 147 | {0x9b,0x29}, 148 | {0x9c,0x3}, 149 | {0x9d,0x98}, 150 | {0x9e,0x3f}, 151 | {0x78,0x4}, 152 | {0x79,0x1}, 153 | {0xc8,0xf0}, 154 | {0x79,0xf}, 155 | {0xc8,0x0}, 156 | {0x79,0x10}, 157 | {0xc8,0x7e}, 158 | {0x79,0x0a}, 159 | {0xc8,0x80}, 160 | {0x79,0xb}, 161 | {0xc8,0x1}, 162 | {0x79,0xc}, 163 | {0xc8,0xf}, 164 | {0x79,0xd}, 165 | {0xc8,0x20}, 166 | {0x79,0x9}, 167 | {0xc8,0x80}, 168 | {0x79,0x2}, 169 | {0xc8,0xc0}, 170 | {0x79,0x3}, 171 | {0xc8,0x40}, 172 | {0x79,0x5}, 173 | {0xc8,0x30}, 174 | {0x79,0x26}, 175 | {0x2d,0x0}, 176 | {0x2e,0x0}, 177 | {0x11,0x40}, 178 | {0x6b,0x0a}, 179 | {0x2a,0x0}, 180 | {0x2b,0x0}, 181 | {0x2d,0x0}, 182 | {0x2e,0x0}, 183 | {0xca,0x0}, 184 | {0x92,0x66}, 185 | {0x93,0x0}, 186 | {0x3b,0x0a}, 187 | {0xcf,0x8c}, 188 | {0x9d,0x98}, 189 | {0x9e,0x7f}, 190 | {0xa5,0x2}, 191 | {0xab,0x3}, 192 | {0x15,0x2}, 193 | {0x12,0x14}, 194 | {0x8c,0x0}, 195 | {0x4,0x0}, 196 | {0x40,0x10}, 197 | {0x14,0x48}, 198 | {0x4f,0xb3}, 199 | {0x50,0xb3}, 200 | {0x51,0x0}, 201 | {0x52,0x3d}, 202 | {0x53,0xa7}, 203 | {0x54,0xe4}, 204 | {0x3d,0xc0}, 205 | {0x15,0x2}, 206 | {0xff, 0xff}, 207 | }; 208 | 209 | 210 | #endif 211 | 212 | -------------------------------------------------------------------------------- /_registers/ov7670_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef OV7670_REGS_H 2 | #define OV7670_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | const struct sensor_reg OV7670_QVGA[] PROGMEM = 6 | { 7 | {0x3a, 0x04}, 8 | {0x40, 0xd0}, 9 | {0x12, 0x14}, 10 | {0x32, 0x80}, 11 | {0x17, 0x16}, 12 | {0x18, 0x04}, 13 | {0x19, 0x02}, 14 | {0x1a, 0x7b}, 15 | {0x03, 0x06}, 16 | {0x0c, 0x00}, 17 | {0x3e, 0x00}, 18 | {0x70, 0x00}, 19 | {0x71, 0x00}, 20 | {0x72, 0x11}, 21 | {0x73, 0x00}, 22 | {0xa2, 0x02}, 23 | {0x11, 0x81}, 24 | {0x7a, 0x20}, 25 | {0x7b, 0x1c}, 26 | {0x7c, 0x28}, 27 | {0x7d, 0x3c}, 28 | {0x7e, 0x55}, 29 | {0x7f, 0x68}, 30 | {0x80, 0x76}, 31 | {0x81, 0x80}, 32 | {0x82, 0x88}, 33 | {0x83, 0x8f}, 34 | {0x84, 0x96}, 35 | {0x85, 0xa3}, 36 | {0x86, 0xaf}, 37 | {0x87, 0xc4}, 38 | {0x88, 0xd7}, 39 | {0x89, 0xe8}, 40 | {0x13, 0xe0}, 41 | {0x00, 0x00}, 42 | {0x10, 0x00}, 43 | {0x0d, 0x00}, 44 | {0x14, 0x28}, 45 | {0xa5, 0x05}, 46 | {0xab, 0x07}, 47 | {0x24, 0x75}, 48 | {0x25, 0x63}, 49 | {0x26, 0xA5}, 50 | {0x9f, 0x78}, 51 | {0xa0, 0x68}, 52 | {0xa1, 0x03}, 53 | {0xa6, 0xdf}, 54 | {0xa7, 0xdf}, 55 | {0xa8, 0xf0}, 56 | {0xa9, 0x90}, 57 | {0xaa, 0x94}, 58 | {0x13, 0xe5}, 59 | {0x0e, 0x61}, 60 | {0x0f, 0x4b}, 61 | {0x16, 0x02}, 62 | {0x1e, 0x17}, 63 | {0x21, 0x02}, 64 | {0x22, 0x91}, 65 | {0x29, 0x07}, 66 | {0x33, 0x0b}, 67 | {0x35, 0x0b}, 68 | {0x37, 0x1d}, 69 | {0x38, 0x71}, 70 | {0x39, 0x2a}, 71 | {0x3c, 0x78}, 72 | {0x4d, 0x40}, 73 | {0x4e, 0x20}, 74 | {0x69, 0x00}, 75 | {0x6b, 0x00}, 76 | {0x74, 0x19}, 77 | {0x8d, 0x4f}, 78 | {0x8e, 0x00}, 79 | {0x8f, 0x00}, 80 | {0x90, 0x00}, 81 | {0x91, 0x00}, 82 | {0x92, 0x00}, 83 | {0x96, 0x00}, 84 | {0x9a, 0x80}, 85 | {0xb0, 0x84}, 86 | {0xb1, 0x0c}, 87 | {0xb2, 0x0e}, 88 | {0xb3, 0x82}, 89 | {0xb8, 0x0a}, 90 | {0x43, 0x14}, 91 | {0x44, 0xf0}, 92 | {0x45, 0x34}, 93 | {0x46, 0x58}, 94 | {0x47, 0x28}, 95 | {0x48, 0x3a}, 96 | {0x59, 0x88}, 97 | {0x5a, 0x88}, 98 | {0x5b, 0x44}, 99 | {0x5c, 0x67}, 100 | {0x5d, 0x49}, 101 | {0x5e, 0x0e}, 102 | {0x64, 0x04}, 103 | {0x65, 0x20}, 104 | {0x66, 0x05}, 105 | {0x94, 0x04}, 106 | {0x95, 0x08}, 107 | {0x6c, 0x0a}, 108 | {0x6d, 0x55}, 109 | {0x6e, 0x11}, 110 | {0x6f, 0x9f}, 111 | {0x6a, 0x40}, 112 | {0x01, 0x40}, 113 | {0x02, 0x40}, 114 | {0x13, 0xe7}, 115 | {0x15, 0x02}, 116 | {0x4f, 0x80}, 117 | {0x50, 0x80}, 118 | {0x51, 0x00}, 119 | {0x52, 0x22}, 120 | {0x53, 0x5e}, 121 | {0x54, 0x80}, 122 | {0x58, 0x9e}, 123 | {0x41, 0x08}, 124 | {0x3f, 0x00}, 125 | {0x75, 0x05}, 126 | {0x76, 0xe1}, 127 | {0x4c, 0x00}, 128 | {0x77, 0x01}, 129 | {0x3d, 0xc2}, 130 | {0x4b, 0x09}, 131 | {0xc9, 0x60}, 132 | {0x41, 0x38}, 133 | {0x56, 0x40}, 134 | {0x34, 0x11}, 135 | {0x3b, 0x02}, 136 | {0xa4, 0x89}, 137 | {0x96, 0x00}, 138 | {0x97, 0x30}, 139 | {0x98, 0x20}, 140 | {0x99, 0x30}, 141 | {0x9a, 0x84}, 142 | {0x9b, 0x29}, 143 | {0x9c, 0x03}, 144 | {0x9d, 0x4c}, 145 | {0x9e, 0x3f}, 146 | {0x78, 0x04}, 147 | {0x79, 0x01}, 148 | {0xc8, 0xf0}, 149 | {0x79, 0x0f}, 150 | {0xc8, 0x00}, 151 | {0x79, 0x10}, 152 | {0xc8, 0x7e}, 153 | {0x79, 0x0a}, 154 | {0xc8, 0x80}, 155 | {0x79, 0x0b}, 156 | {0xc8, 0x01}, 157 | {0x79, 0x0c}, 158 | {0xc8, 0x0f}, 159 | {0x79, 0x0d}, 160 | {0xc8, 0x20}, 161 | {0x79, 0x09}, 162 | {0xc8, 0x80}, 163 | {0x79, 0x02}, 164 | {0xc8, 0xc0}, 165 | {0x79, 0x03}, 166 | {0xc8, 0x40}, 167 | {0x79, 0x05}, 168 | {0xc8, 0x30}, 169 | {0x79, 0x26}, 170 | {0x09, 0x03}, 171 | {0x3b, 0x42}, 172 | {0xff, 0xff}, 173 | }; 174 | 175 | 176 | #endif 177 | 178 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_SPI_OV2640_FIFO_UART/ArduCAM_SPI_OV2640_FIFO_UART.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV2640 sensor. 7 | // 1. Set the sensor to JPEG output mode. 8 | // 2. Capture and buffer the image to FIFO. 9 | // 3. Transfer the captured JPEG image back to host via Arduino board USB port. 10 | // 4. Resolution can be changed by myCAM.OV2640_set_JPEG_size() function. 11 | // This program requires the ArduCAM V3.0.1 (or above) library and Rev.C ArduCAM shield 12 | // and use Arduino IDE 1.5.2 compiler 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "memorysaver.h" 20 | 21 | // set pin 10 as the slave select for the digital pot: 22 | const int SPI_CS = 10; 23 | 24 | 25 | ArduCAM myCAM(OV2640,10); 26 | UTFT myGLCD(SPI_CS); 27 | 28 | void setup() 29 | { 30 | uint8_t vid,pid; 31 | uint8_t temp; 32 | #if defined (__AVR__) 33 | Wire.begin(); 34 | #endif 35 | #if defined(__arm__) 36 | Wire1.begin(); 37 | #endif 38 | Serial.begin(115200); 39 | 40 | Serial.println("ArduCAM Start!"); 41 | 42 | // set the SPI_CS as an output: 43 | pinMode(SPI_CS, OUTPUT); 44 | 45 | // initialize SPI: 46 | SPI.begin(); 47 | //Check if the ArduCAM SPI bus is OK 48 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 49 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 50 | if(temp != 0x55) 51 | { 52 | Serial.println("SPI interface Error!"); 53 | Serial.println(temp,HEX); 54 | while(1); 55 | } 56 | 57 | myCAM.set_mode(MCU2LCD_MODE); 58 | 59 | //Check if the camera module type is OV2640 60 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 61 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 62 | if((vid != 0x26) || (pid != 0x42)) 63 | Serial.println("Can't find OV2640 module!"); 64 | else 65 | Serial.println("OV2640 detected"); 66 | 67 | //Change to JPEG capture mode and initialize the OV2640 module 68 | myCAM.set_format(JPEG); 69 | myCAM.InitCAM(); 70 | myCAM.OV2640_set_JPEG_size(OV2640_320x240); 71 | } 72 | 73 | void loop() 74 | { 75 | uint8_t temp,temp_last; 76 | uint8_t start_capture = 0; 77 | 78 | temp = Serial.read(); 79 | switch(temp) 80 | { 81 | case 0: 82 | myCAM.OV2640_set_JPEG_size(OV2640_160x120); 83 | break; 84 | case 1: 85 | myCAM.OV2640_set_JPEG_size(OV2640_176x144); 86 | break; 87 | case 2: 88 | myCAM.OV2640_set_JPEG_size(OV2640_320x240); 89 | break; 90 | case 3: 91 | myCAM.OV2640_set_JPEG_size(OV2640_352x288); 92 | break; 93 | case 4: 94 | myCAM.OV2640_set_JPEG_size(OV2640_640x480); 95 | break; 96 | case 5: 97 | myCAM.OV2640_set_JPEG_size(OV2640_800x600); 98 | break; 99 | case 6: 100 | myCAM.OV2640_set_JPEG_size(OV2640_1024x768); 101 | break; 102 | case 7: 103 | myCAM.OV2640_set_JPEG_size(OV2640_1280x1024); 104 | break; 105 | case 8: 106 | myCAM.OV2640_set_JPEG_size(OV2640_1600x1200); 107 | break; 108 | 109 | case 0x10: 110 | start_capture = 1; 111 | Serial.println("Start Capture"); 112 | myCAM.flush_fifo(); 113 | break; 114 | default: 115 | break; 116 | } 117 | //start_capture = 1; 118 | if(start_capture) 119 | { 120 | //Clear the capture done flag 121 | myCAM.clear_fifo_flag(); 122 | //Start capture 123 | myCAM.start_capture(); 124 | } 125 | if(myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)) 126 | { 127 | Serial.println("Capture Done!"); 128 | 129 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 130 | { 131 | temp_last = temp; 132 | temp = myCAM.read_fifo(); 133 | Serial.write(temp); 134 | } 135 | 136 | 137 | //Clear the capture done flag 138 | myCAM.clear_fifo_flag(); 139 | start_capture = 0; 140 | } 141 | } 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /_registers/_sensorsDefinitions.h: -------------------------------------------------------------------------------- 1 | #ifndef _SENSOR_DEF__H_ 2 | #define _SENSOR_DEF__H_ 3 | 4 | /****************************************************/ 5 | /* Sensor related definition */ 6 | /****************************************************/ 7 | #define BMP 0 8 | #define JPEG 1 9 | 10 | #define OV7670 0 11 | #define MT9D111_A 1 12 | #define OV7675 2 13 | #define OV5642 3 14 | #define OV3640 4 15 | #define OV2640 5 16 | #define OV9655 6 17 | #define MT9M112 7 18 | #define OV7725 8 19 | #define OV7660 9 20 | #define MT9M001 10 21 | #define OV5640 11 22 | #define MT9D111_B 12 23 | #define OV9650 13 24 | #define MT9V111 14 25 | #define MT9T112 15 26 | #define MT9D112 16 27 | 28 | #define OV2640_160x120 0 //160x120 29 | #define OV2640_176x144 1 //176x144 30 | #define OV2640_320x240 2 //320x240 31 | #define OV2640_352x288 3 //352x288 32 | #define OV2640_640x480 4 //640x480 33 | #define OV2640_800x600 5 //800x600 34 | #define OV2640_1024x768 6 //1024x768 35 | #define OV2640_1280x1024 7 //1280x1024 36 | #define OV2640_1600x1200 8 //1600x1200 37 | 38 | #define OV5642_320x240 1 //320x240 39 | #define OV5642_640x480 2 //640x480 40 | #define OV5642_1280x720 3 //1280x720 41 | #define OV5642_1920x1080 4 //1920x1080 42 | #define OV5642_2048x1563 5 //2048x1563 43 | #define OV5642_2592x1944 6 //2592x1944 44 | 45 | /****************************************************/ 46 | /* I2C Control Definition */ 47 | /****************************************************/ 48 | #define I2C_ADDR_8BIT 0 49 | #define I2C_ADDR_16BIT 1 50 | #define I2C_REG_8BIT 0 51 | #define I2C_REG_16BIT 1 52 | #define I2C_DAT_8BIT 0 53 | #define I2C_DAT_16BIT 1 54 | 55 | /* Register initialization tables for SENSORs */ 56 | /* Terminating list entry for reg */ 57 | #define SENSOR_REG_TERM_8BIT 0xFF 58 | #define SENSOR_REG_TERM_16BIT 0xFFFF 59 | /* Terminating list entry for val */ 60 | #define SENSOR_VAL_TERM_8BIT 0xFF 61 | #define SENSOR_VAL_TERM_16BIT 0xFFFF 62 | 63 | /****************************************************/ 64 | /* ArduChip related definition */ 65 | /****************************************************/ 66 | #define RWBIT 0x80 //READ AND WRITE BIT IS BIT[7] 67 | 68 | #define ARDUCHIP_TEST1 0x00 //TEST register 69 | #define ARDUCHIP_TEST2 0x01 //TEST register 70 | 71 | #define ARDUCHIP_FRAMES 0x01 //Bit[2:0]Number of frames to be captured 72 | 73 | #define ARDUCHIP_MODE 0x02 //Mode register 74 | #define MCU2LCD_MODE 0x00 75 | #define CAM2LCD_MODE 0x01 76 | #define LCD2MCU_MODE 0x02 77 | 78 | #define ARDUCHIP_TIM 0x03 //Timming control 79 | #define HREF_LEVEL_MASK 0x01 //0 = High active , 1 = Low active 80 | #define VSYNC_LEVEL_MASK 0x02 //0 = High active , 1 = Low active 81 | #define LCD_BKEN_MASK 0x04 //0 = Enable, 1 = Disable 82 | #define DELAY_MASK 0x08 //0 = no delay, 1 = delay one clock 83 | #define MODE_MASK 0x10 //0 = LCD mode, 1 = FIFO mode 84 | #define FIFO_PWRDN_MASK 0x20 //0 = Normal operation, 1 = FIFO power down 85 | #define LOW_POWER_MODE 0x40 //0 = Normal mode, 1 = Low power mode 86 | 87 | #define ARDUCHIP_FIFO 0x04 //FIFO and I2C control 88 | #define FIFO_CLEAR_MASK 0x01 89 | #define FIFO_START_MASK 0x02 90 | #define FIFO_RDPTR_RST_MASK 0x10 91 | #define FIFO_WRPTR_RST_MASK 0x20 92 | 93 | #define ARDUCHIP_GPIO 0x06 //GPIO Write Register 94 | #define GPIO_RESET_MASK 0x01 //0 = default state, 1 = Sensor reset IO value 95 | #define GPIO_PWDN_MASK 0x02 //0 = Sensor power down IO value, 1 = Sensor power enable IO value 96 | 97 | #define BURST_FIFO_READ 0x3C //Burst FIFO read operation 98 | #define SINGLE_FIFO_READ 0x3D //Single FIFO read operation 99 | 100 | #define ARDUCHIP_REV 0x40 //ArduCHIP revision 101 | #define VER_LOW_MASK 0x3F 102 | #define VER_HIGH_MASK 0xC0 103 | 104 | #define ARDUCHIP_TRIG 0x41 //Trigger source 105 | #define VSYNC_MASK 0x01 106 | #define SHUTTER_MASK 0x02 107 | #define CAP_DONE_MASK 0x08 108 | 109 | #define FIFO_SIZE1 0x42 //Camera write FIFO size[7:0] for burst to read 110 | #define FIFO_SIZE2 0x43 //Camera write FIFO size[15:8] 111 | #define FIFO_SIZE3 0x44 //Camera write FIFO size[18:16] 112 | 113 | #endif //_MEMORYSAVER_ 114 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_2MP_TimeElapse2SD/ArduCAM_Mini_2MP_TimeElapse2SD.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules, and can run on any Arduino platform. 5 | // 6 | // This demo was made for Omnivision OV2640 2MP sensor. 7 | // It will run the ArduCAM Mini 2MP as a real 2MP digital camera, provide both JPEG capture. 8 | // The demo sketch will do the following tasks: 9 | // 1. Set the sensor to JPEG mode. 10 | // 2. Capture and buffer the image to FIFO every 5 seconds 11 | // 3. Store the image to Micro SD/TF card with JPEG format in sequential. 12 | // 4. Resolution can be changed by myCAM.set_JPEG_size() function. 13 | // This program requires the ArduCAM V3.4.0 (or later) library and ArduCAM Mini 2MP shield 14 | // and use Arduino IDE 1.5.2 compiler or above 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | #if defined(__SAM3X8E__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | // set pin 4 as the slave select for SPI: 28 | const int SPI_CS = 4; 29 | 30 | ArduCAM myCAM(OV2640, SPI_CS); 31 | UTFT myGLCD(SPI_CS); 32 | 33 | 34 | void setup() 35 | { 36 | uint8_t vid, pid; 37 | uint8_t temp; 38 | Serial.begin(115200); 39 | Serial.println("ArduCAM Start!"); 40 | myCAM.begin(); 41 | //Check if the ArduCAM SPI bus is OK 42 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 43 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 44 | if (temp != 0x55) 45 | { 46 | Serial.println("SPI interface Error!"); 47 | while (1); 48 | } 49 | 50 | //Check if the camera module type is OV2640 51 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 52 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 53 | if ((vid != 0x26) || (pid != 0x42)) 54 | Serial.println("Can't find OV2640 module!"); 55 | else 56 | Serial.println("OV2640 detected"); 57 | 58 | //Change to BMP capture mode and initialize the OV2640 module 59 | myCAM.set_format(JPEG); 60 | 61 | myCAM.InitCAM(); 62 | //myCAM.OV2640_set_JPEG_size(OV2640_640x480); 63 | //myCAM.OV2640_set_JPEG_size(OV2640_1600x1200); 64 | 65 | //Initialize SD Card 66 | if (!SD.begin(SD_CS)) 67 | { 68 | //while (1); //If failed, stop here 69 | Serial.println("SD Card Error"); 70 | } 71 | else 72 | Serial.println("SD Card detected!"); 73 | } 74 | 75 | void loop() 76 | { 77 | char str[8]; 78 | File outFile; 79 | byte buf[256]; 80 | static int i = 0; 81 | static int k = 0; 82 | static int n = 0; 83 | uint8_t temp, temp_last; 84 | uint8_t start_capture = 0; 85 | int total_time = 0; 86 | //////////////////////////////// 87 | 88 | start_capture = 1; 89 | delay(5000); 90 | 91 | if (start_capture) 92 | { 93 | //Flush the FIFO 94 | myCAM.flush_fifo(); 95 | //Clear the capture done flag 96 | myCAM.clear_fifo_flag(); 97 | //Start capture 98 | myCAM.start_capture(); 99 | Serial.println("Start Capture"); 100 | } 101 | 102 | while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)); 103 | 104 | 105 | Serial.println("Capture Done!"); 106 | 107 | //Construct a file name 108 | k = k + 1; 109 | itoa(k, str, 10); 110 | strcat(str, ".jpg"); 111 | //Open the new file 112 | outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); 113 | if (! outFile) 114 | { 115 | Serial.println("open file failed"); 116 | return; 117 | } 118 | total_time = millis(); 119 | i = 0; 120 | myCAM.startSend(); 121 | myCAM.set_fifo_burst(); 122 | temp = myCAM.sendData(0x00); 123 | // 124 | //Read JPEG data from FIFO 125 | while ( (temp != 0xD9) | (temp_last != 0xFF)) 126 | { 127 | temp_last = temp; 128 | temp = myCAM.sendData(0x00); 129 | 130 | //Write image data to buffer if not full 131 | if (i < 256) 132 | buf[i++] = temp; 133 | else 134 | { 135 | //Write 256 bytes image data to file 136 | myCAM.endSend(); 137 | outFile.write(buf, 256); 138 | i = 0; 139 | buf[i++] = temp; 140 | myCAM.startSend(); 141 | myCAM.set_fifo_burst(); 142 | } 143 | } 144 | //Write the remain bytes in the buffer 145 | if (i > 0) 146 | { 147 | myCAM.endSend(); 148 | outFile.write(buf, i); 149 | } 150 | //Close the file 151 | outFile.close(); 152 | total_time = millis() - total_time; 153 | Serial.print("Total time used:"); 154 | Serial.print(total_time, DEC); 155 | Serial.println(" millisecond"); 156 | //Clear the capture done flag 157 | myCAM.clear_fifo_flag(); 158 | //Clear the start capture flag 159 | start_capture = 0; 160 | } 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV5642_FIFO_UART_Burst/ArduCAM_Mini_OV5642_FIFO_UART_Burst.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV5642 sensor. 7 | // 1. Set the sensor to JPEG output mode. 8 | // 2. Capture and buffer the image to FIFO. 9 | // 3. Transfer the captured JPEG image back to host via Arduino board USB port. 10 | // This program requires the ArduCAM V3.0.1 (or above) library and Rev.C ArduCAM shield 11 | // and use Arduino IDE 1.5.2 compiler 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "memorysaver.h" 18 | 19 | // set pin 10 as the slave select for the digital pot: 20 | const int SPI_CS = 10; 21 | 22 | 23 | ArduCAM myCAM(OV5642,SPI_CS); 24 | 25 | void setup() 26 | { 27 | uint8_t vid,pid; 28 | uint8_t temp; 29 | #if defined (__AVR__) 30 | Wire.begin(); 31 | #endif 32 | #if defined(__arm__) 33 | Wire1.begin(); 34 | #endif 35 | Serial.begin(115200); 36 | Serial.println("ArduCAM Start!"); 37 | 38 | // set the SPI_CS as an output: 39 | pinMode(SPI_CS, OUTPUT); 40 | 41 | // initialize SPI: 42 | SPI.begin(); 43 | //Check if the ArduCAM SPI bus is OK 44 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 45 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 46 | if(temp != 0x55) 47 | { 48 | Serial.println("SPI interface Error!"); 49 | Serial.print(temp, HEX); 50 | while(1); 51 | } 52 | 53 | //myCAM.set_mode(MCU2LCD_MODE); 54 | 55 | //Check if the camera module type is OV2640 56 | myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); 57 | myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); 58 | if((vid != 0x56) || (pid != 0x42)) 59 | Serial.println("Can't find OV5642 module!"); 60 | else 61 | Serial.println("OV5642 detected"); 62 | 63 | //Change to JPEG capture mode and initialize the OV2640 module 64 | myCAM.set_format(JPEG); 65 | 66 | myCAM.InitCAM(); 67 | 68 | myCAM.clear_fifo_flag(); 69 | //myCAM.write_reg(0x81, 0x00); 70 | myCAM.write_reg(ARDUCHIP_FRAMES,0x00); //Bit[2:0]Number of frames to be captured 71 | } 72 | 73 | void loop() 74 | { 75 | uint8_t temp,temp_last; 76 | uint8_t start_capture = 0; 77 | static int Ts, Tc, Td, Tt, Tu, T0; 78 | T0 = millis(); 79 | temp = Serial.read(); 80 | Tu = millis(); 81 | switch(temp) 82 | { 83 | case 0x0a: 84 | myCAM.set_bit(ARDUCHIP_TIM,LOW_POWER_MODE); 85 | break; 86 | case 0x0b: 87 | myCAM.clear_bit(ARDUCHIP_TIM,LOW_POWER_MODE); 88 | break; 89 | case 0x0c: 90 | myCAM.set_bit(ARDUCHIP_FIFO,FIFO_RDPTR_RST_MASK); 91 | read_fifo_again(); 92 | break; 93 | case 0x0d: //reset 94 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_RESET_MASK); 95 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_RESET_MASK); 96 | break; 97 | case 0x0e: //pwdn low 98 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_POWER_MASK); 99 | break; 100 | case 0x0f: //pwdn 101 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_POWER_MASK); 102 | break; 103 | case 0x10: 104 | start_capture = 1; 105 | Serial.println("Start Capture"); 106 | Ts = millis(); 107 | myCAM.flush_fifo(); 108 | break; 109 | default: 110 | break; 111 | } 112 | 113 | if(start_capture) 114 | { 115 | //Clear the capture done flag 116 | myCAM.clear_fifo_flag(); 117 | //Start capture 118 | myCAM.start_capture(); 119 | start_capture = 0; 120 | Tc = millis(); 121 | } 122 | if(myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) 123 | { 124 | Td = millis(); 125 | Serial.println("Capture Done!"); 126 | read_fifo_burst(); 127 | Tt = millis(); 128 | //Clear the capture done flag 129 | myCAM.clear_fifo_flag(); 130 | start_capture = 0; 131 | Serial.println(""); 132 | Serial.println("-----------------------"); 133 | Serial.println("Time used:"); 134 | Serial.println(Tu-T0, DEC); 135 | Serial.println(Tc-Ts, DEC); 136 | Serial.println(Td-Tc, DEC); 137 | Serial.println(Tt-Td, DEC); 138 | 139 | } 140 | } 141 | 142 | uint8_t read_fifo_burst() 143 | { 144 | uint32_t length = 0; 145 | uint8_t temp,temp_last; 146 | length = myCAM.read_fifo_length(); 147 | if(length >= 512000) //512 kb 148 | { 149 | Serial.println("Not found the end."); 150 | return 0; 151 | } 152 | Serial.println(length); 153 | 154 | myCAM.CS_LOW(); 155 | myCAM.set_fifo_burst(); 156 | length--; 157 | while( length-- ) 158 | { 159 | temp_last = temp; 160 | temp = SPI.transfer(0x00); 161 | Serial.write(temp); 162 | if( (temp == 0xD9) && (temp_last == 0xFF) ) 163 | break; 164 | delayMicroseconds(10); 165 | } 166 | myCAM.CS_HIGH(); 167 | } 168 | 169 | void read_fifo_again() 170 | { 171 | read_fifo_burst(); 172 | } 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_MT9M001_Camera_RAW/ArduCAM_MT9M001_Camera_RAW.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Aptina MT9M001 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 9 | // 1. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 2. Store the image to Micro SD/TF card with RAW format. 11 | // 12 | // This program requires the ArduCAM V3.4.5 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.8 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | 28 | // set pin 10 as the slave select for the ArduCAM shield 29 | const int SPI_CS = 10; 30 | 31 | 32 | ArduCAM myCAM(MT9M001,SPI_CS); 33 | UTFT myGLCD(SPI_CS); 34 | 35 | void setup() 36 | { 37 | uint16_t vid; 38 | uint8_t temp; 39 | 40 | #if defined (__AVR__) 41 | Wire.begin(); 42 | #endif 43 | #if defined(__arm__) 44 | Wire1.begin(); 45 | #endif 46 | Serial.begin(115200); 47 | Serial.println("ArduCAM Start!"); 48 | 49 | // set the SPI_CS as an output: 50 | pinMode(SPI_CS, OUTPUT); 51 | 52 | // initialize SPI: 53 | SPI.begin(); 54 | //Check if the ArduCAM SPI bus is OK 55 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 56 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 57 | if(temp != 0x55) 58 | { 59 | Serial.println("SPI interface Error!"); 60 | while(1); 61 | } 62 | //Check if the camera module type is MT9M001 63 | myCAM.rdSensorReg8_16(0x00, &vid); 64 | 65 | if (vid != 0x8431) 66 | { 67 | Serial.println("Can't find MT9M001 module!"); 68 | Serial.println(vid, HEX); 69 | } 70 | else 71 | Serial.println("MT9M001 detected"); 72 | //Change MCU mode 73 | myCAM.set_mode(MCU2LCD_MODE); 74 | 75 | //Initialize the LCD Module 76 | myGLCD.InitLCD(); 77 | 78 | myCAM.InitCAM(); 79 | 80 | //Initialize SD Card 81 | if (!SD.begin(SD_CS)) 82 | { 83 | //while (1); //If failed, stop here 84 | Serial.println("SD Card Error"); 85 | } 86 | else 87 | Serial.println("SD Card detected!"); 88 | } 89 | 90 | void loop() 91 | { 92 | char str[8]; 93 | unsigned long previous_time = 0; 94 | static int k = 0; 95 | uint8_t temp; 96 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 97 | 98 | while(1) 99 | { 100 | 101 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 102 | { 103 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 104 | myGLCD.resetXY(); 105 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 106 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 107 | } 108 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 109 | { 110 | 111 | k = k + 1; 112 | itoa(k, str, 10); 113 | strcat(str,".raw"); //Generate file name 114 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 115 | GrabImage(str); 116 | 117 | } 118 | } 119 | } 120 | 121 | 122 | void GrabImage(char* str) 123 | { 124 | File outFile; 125 | char VH,VL; 126 | uint8_t temp; 127 | byte buf[256]; 128 | static int k = 0; 129 | int i,j = 0; 130 | 131 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 132 | if (! outFile) 133 | { 134 | Serial.println("Open File Error"); 135 | return; 136 | } 137 | myCAM.wrSensorReg8_16(0x03, 599); 138 | myCAM.wrSensorReg8_16(0x04, 639); 139 | //Switch to FIFO Mode 140 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 141 | //Flush the FIFO 142 | myCAM.flush_fifo(); 143 | //Start capture 144 | myCAM.start_capture(); 145 | Serial.println("Start Capture"); 146 | 147 | //Polling the capture done flag 148 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 149 | Serial.println("Capture Done!"); 150 | 151 | //Read the first dummy byte 152 | //myCAM.read_fifo(); 153 | 154 | k = 0; 155 | //Read 640x600 byte from FIFO 156 | //Save as RAW format 157 | for(i = 0; i < 600; i++) 158 | for(j = 0; j < 320; j++) 159 | { 160 | VL = myCAM.read_fifo(); 161 | VH = myCAM.read_fifo(); 162 | buf[k++] = VL; 163 | buf[k++] = VH; 164 | //Write image data to bufer if not full 165 | if(k >= 256) 166 | { 167 | //Write 256 bytes image data to file from buffer 168 | outFile.write(buf,256); 169 | k = 0; 170 | } 171 | } 172 | //Close the file 173 | outFile.close(); 174 | //Clear the capture done flag 175 | myCAM.clear_fifo_flag(); 176 | myCAM.wrSensorReg8_16(0x03, 240); 177 | myCAM.wrSensorReg8_16(0x04, 639); 178 | //Switch to LCD Mode 179 | myCAM.write_reg(ARDUCHIP_TIM, 0); 180 | return; 181 | } 182 | 183 | -------------------------------------------------------------------------------- /_registers/mt9m112_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef MT9M112_REGS_H 2 | #define MT9M112_REGS_H 3 | #include "../ArduCAM.h" 4 | //#include 5 | 6 | const struct sensor_reg MT9M112_QVGA[] PROGMEM = 7 | { 8 | 9 | #if 1 //MCLK == 24M 10 | {0xf0,0x0000}, 11 | {0x66,0x1001}, 12 | {0x67,0x0501}, 13 | {0x65,0xa000}, 14 | {0xff,0x0064}, 15 | {0x65,0x2000}, 16 | {0xff,0x0064}, 17 | #endif 18 | {0xf0,0x0000}, 19 | {0x0d,0x0009}, 20 | {0xff,0x0020}, 21 | {0x0d,0x0008}, 22 | {0xf0,0x0000}, 23 | {0x01,0x0024}, 24 | {0x03,0x0400},// default value 25 | {0x04,0x0500}, 26 | {0x30,0x042a}, 27 | {0xf0,0x0001}, 28 | {0x05,0x000f}, 29 | {0x25,0x004d},// saturation adjustment, default value 0x4d 30 | {0x3b,0x0430},//0x0436 31 | {0x3c,0x0400}, 32 | {0x47,0x322e}, 33 | {0x9d,0x3ce0}, 34 | 35 | {0xf0,0x0002}, 36 | {0x28,0xef02},//0xef3e 37 | {0x06,0x748e}, 38 | {0x02,0x00ee},// base matrix signs 39 | {0x15,0x00d9},// delta coefficients signs 40 | {0x09,0x0067},//k1 41 | {0x0a,0x009a},//k2 42 | {0x0b,0x0028},//k3 43 | {0x0c,0x0030},//k4 44 | {0x0d,0x00ca},//k5 45 | {0x0e,0x0037},//k6 46 | {0x0f,0x001a},//k7 47 | {0x10,0x0065},//k8 48 | {0x11,0x0086},//k9 49 | {0x16,0x005e},//d1 0x0062 50 | {0x17,0x0084},//d2 51 | {0x18,0x004d},//d3 52 | {0x19,0x0024},//d4 53 | {0x1a,0x001f},//d5 54 | {0x1b,0x002f},//d6 55 | {0x1c,0x0004},//d7 56 | {0x1d,0x0023},//d8 57 | {0x1e,0x0010},//d9 58 | {0x03,0x3922},// base matrix scale k1-k5 59 | {0x04,0x0524},// base matrix scale k6-k9 0x04e4 60 | {0xf0,0x0002}, 61 | {0x1f,0x0180}, 62 | {0x20,0xc814},//0xdc0c 63 | {0x21,0x8080}, 64 | {0x22,0x9080}, 65 | {0x23,0x8878}, 66 | {0x26,0x8000}, 67 | {0x27,0x8008}, 68 | {0x2e,0x0c44},// 0x0d20 69 | {0x3e,0x1cff}, 70 | {0x46,0x00b0}, 71 | {0x5b,0x8002}, 72 | {0x5c,0x110c}, 73 | {0x5d,0x1510}, 74 | {0x5e,0x534c}, 75 | {0x5f,0x2b21}, 76 | {0x24,0x7f40}, 77 | {0x60,0x0002}, 78 | {0x62,0x1010}, 79 | {0x65,0x0000}, 80 | {0xdc,0x0ff8}, 81 | {0xdd,0x0ce0}, 82 | {0xf0,0x0001}, 83 | {0x47,0x202e}, 84 | {0x80,0x0006},// lens correction control 85 | {0x81,0x0000},// vertical red knee 0 and initial value 0x0009 86 | {0x82,0xfe05},// vertical red knees 2 and 1 87 | {0x83,0x0000},// vertical red knees 4 and 30x00ff 88 | {0x84,0x0c00},// vertical green knee 0 and initial value 89 | {0x85,0xfe02},// vertical green knees 2 and 1 90 | {0x86,0x00ff},// vertical green knees 4 and 3 91 | {0x87,0x0701},// vertical blue knee 0 and initial value 1003 92 | {0x88,0xfc06},// vertical blue knees 2 and 1 93 | {0x89,0x00ff},// vertical blue knees 4 and 3 94 | {0x8a,0x0801},// horizontal red knee 0 and initial value 95 | {0x8b,0x030e},// horizontal red knees 2 and 1 96 | {0x8c,0xfefd},// horizontal red knees 4 and 3 97 | {0x8d,0x00ff},// horizontal red knee 5 98 | {0x8e,0x0601},// horizontal green knee 0 and initial value 99 | {0x8f,0x040b},// horizontal green knees 2 and 1 100 | {0x90,0xfefb},// horizontal green knees 4 and 3 101 | {0x91,0x00fe},// horizontal green knee 5 102 | {0x92,0x0600},// horizontal blue knee 0 and initial value 103 | {0x93,0x040b},// horizontal blue knees 2 and 1 104 | {0x94,0xfefd},// horizontal blue knees 4 and 3 105 | {0x95,0x00ff},// horizontal blue knees 5 106 | {0xb6,0x0204},// lens vertical red knees 6 and 5 107 | {0xb7,0xfbfa},// lens vertical red knees 8 and 7 108 | {0xb8,0x0503},// lens vertical green knees 6 and 5 109 | {0xb9,0xfaf8},// lens vertical green knees 8 and 7 110 | {0xba,0x0401},// lens vertical blue knees 6 and 5 111 | {0xbb,0xfef8},// lens vertical blue knees 8 and 7 112 | {0xbc,0xff01},// lens horizontal red knees 7 and 6 113 | {0xbd,0xf4ff},// lens horizontal red knees 9 and 8 114 | {0xbe,0x00fb},// lens horizontal red knee 10 115 | {0xbf,0x0000},// lens horizontal green knees 7 and 6 116 | {0xc0,0xf8fd},// lens horizontal green knees 9 and 8 117 | {0xc1,0x00f7},// lens horizontal green knee 10 118 | {0xc2,0x01ff},// lens horizontal blue knees 7 and 6 119 | {0xc3,0xf5fc},// lens horizontal blue knees 9 and 8 120 | {0xc4,0x00fa},// lens horizontal blue knee 10 121 | {0x06,0x748e}, 122 | {0x9d,0x3ce0},// defect correction control 123 | {0xf0,0x0002}, 124 | {0x2e,0x0d3a},// 0x0d32 125 | {0x37,0x0081}, 126 | {0x36,0x7810}, 127 | {0xf0,0x0001}, 128 | {0x06,0xf48e}, 129 | {0xf0,0x0001}, 130 | {0x06,0x648e}, 131 | {0xf0,0x0002}, 132 | {0x5b,0x0001},//0x0003 133 | 134 | {0xf0,0x0000}, 135 | {0x20,0x0102}, 136 | {0x21,0x8000}, 137 | {0x22,0x090d}, 138 | 139 | {0xf0,0x0000}, 140 | {0x07,0x0374}, //horizontal blank 141 | {0x08,0x0009}, 142 | {0xf0,0x0002}, 143 | {0xc8,0x0000}, 144 | {0x2f,0xd100},// auto exposure speed A 145 | {0x57,0x0271}, 146 | {0x58,0x0271}, 147 | {0xf0,0x0000}, 148 | {0x21,0x8400}, 149 | {0x22,0x090d}, 150 | {0x68,0x0070}, 151 | {0xf0,0x0001}, 152 | {0xa6,0x0500},// horizontal zoom size A 153 | {0xa7,0x0140},// horizontal output size A 154 | {0xa9,0x0400},// vertical zoom size A 155 | {0xaa,0x00f0},// vertical output size A 156 | {0x3a,0x0100},// [7:6]:RGB565 157 | {0x53,0x1105},// gamma start A 158 | {0x54,0x5d33}, 159 | {0x55,0xad8d}, 160 | {0x56,0xd6c4}, 161 | {0x57,0xf3e6}, 162 | {0x58,0xff00},// gamma end A 163 | {0xf0,0x0000}, 164 | 165 | {0xff, 0xffff}, 166 | }; 167 | 168 | #endif 169 | 170 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_5MP_TimeElapse2SD/ArduCAM_Mini_5MP_TimeElapse2SD.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules, and can run on any Arduino platform. 5 | // 6 | // This demo was made for Omnivision OV5642 5MP sensor. 7 | // It will run the ArduCAM Mini 5MP as a real 5MP digital camera, provide JPEG capture. 8 | // The demo sketch will do the following tasks: 9 | // 1. Set the sensor to JPEG mode. 10 | // 2. Capture and buffer the image to FIFO every 5 seconds 11 | // 3. Store the image to Micro SD/TF card with JPEG format in sequential. 12 | // 4. Resolution can be changed by myCAM.OV5642_set_JPEG_size() function. 13 | // This program requires the ArduCAM V3.4.0 (or later) library and ArduCAM Mini 5MP shield 14 | // and use Arduino IDE 1.5.2 compiler or above 15 | 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "memorysaver.h" 23 | 24 | #if defined(__arm__) 25 | #include 26 | #endif 27 | 28 | #define SD_CS 9 29 | // set pin 10 as the slave select for SPI: 30 | const int SPI_CS = 4; 31 | 32 | ArduCAM myCAM(OV5642, SPI_CS); 33 | UTFT myGLCD(SPI_CS); 34 | boolean isShowFlag = true; 35 | 36 | void setup() 37 | { 38 | uint8_t vid, pid; 39 | uint8_t temp; 40 | #if defined (__AVR__) 41 | Wire.begin(); 42 | #endif 43 | #if defined(__arm__) 44 | Wire1.begin(); 45 | #endif 46 | Serial.begin(115200); 47 | Serial.println("ArduCAM Start!"); 48 | // set the SPI_CS as an output: 49 | pinMode(SPI_CS, OUTPUT); 50 | 51 | // initialize SPI: 52 | SPI.begin(); 53 | //Check if the ArduCAM SPI bus is OK 54 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 55 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 56 | if (temp != 0x55) 57 | { 58 | Serial.println("SPI interface Error!"); 59 | while (1); 60 | } 61 | 62 | 63 | //Check if the camera module type is OV5642 64 | myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); 65 | myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); 66 | if ((vid != 0x56) || (pid != 0x42)) 67 | Serial.println("Can't find OV5642 module!"); 68 | else 69 | Serial.println("OV5642 detected"); 70 | 71 | 72 | //Change to JPEG capture mode and initialize the OV5642 module 73 | myCAM.set_format(JPEG); 74 | 75 | myCAM.InitCAM(); 76 | myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH 77 | myCAM.OV5642_set_JPEG_size(OV5642_320x240); 78 | // myCAM.OV5642_set_JPEG_size(OV5642_640x480); 79 | // myCAM.OV5642_set_JPEG_size(OV5642_1280x720); 80 | // myCAM.OV5642_set_JPEG_size(OV5642_1920x1080); 81 | // myCAM.OV5642_set_JPEG_size(OV5642_2048x1563); 82 | // myCAM.OV5642_set_JPEG_size(OV5642_2592x1944); 83 | //Initialize SD Card 84 | if (!SD.begin(SD_CS)) 85 | { 86 | //while (1); //If failed, stop here 87 | Serial.println("SD Card Error"); 88 | } 89 | else 90 | Serial.println("SD Card detected!"); 91 | } 92 | 93 | void loop() 94 | { 95 | char str[8]; 96 | File outFile; 97 | byte buf[256]; 98 | static int i = 0; 99 | static int k = 0; 100 | static int n = 0; 101 | uint8_t temp, temp_last; 102 | uint8_t start_capture = 0; 103 | int total_time = 0; 104 | 105 | start_capture = 1; 106 | delay(5000); 107 | 108 | if (start_capture) 109 | { 110 | //Flush the FIFO 111 | myCAM.flush_fifo(); 112 | //Clear the capture done flag 113 | myCAM.clear_fifo_flag(); 114 | //Start capture 115 | myCAM.start_capture(); 116 | Serial.println("Start Capture"); 117 | } 118 | 119 | while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)); 120 | 121 | Serial.println("Capture Done!"); 122 | //Construct a file name 123 | k = k + 1; 124 | itoa(k, str, 10); 125 | strcat(str, ".jpg"); 126 | //Open the new file 127 | outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); 128 | if (! outFile) 129 | { 130 | Serial.println("open file failed"); 131 | return; 132 | } 133 | total_time = millis(); 134 | 135 | i = 0; 136 | myCAM.CS_LOW(); 137 | myCAM.set_fifo_burst(); 138 | temp = SPI.transfer(0x00); 139 | 140 | //Read JPEG data from FIFO 141 | while ( (temp != 0xD9) | (temp_last != 0xFF) ) 142 | { 143 | temp_last = temp; 144 | temp = SPI.transfer(0x00);; 145 | //Write image data to buffer if not full 146 | if (i < 256) 147 | buf[i++] = temp; 148 | else 149 | { 150 | //Write 256 bytes image data to file 151 | myCAM.CS_HIGH(); 152 | outFile.write(buf, 256); 153 | i = 0; 154 | buf[i++] = temp; 155 | myCAM.CS_LOW(); 156 | myCAM.set_fifo_burst(); 157 | } 158 | } 159 | //Write the remain bytes in the buffer 160 | if (i > 0) 161 | { 162 | myCAM.CS_HIGH(); 163 | outFile.write(buf, i); 164 | } 165 | //Close the file 166 | outFile.close(); 167 | total_time = millis() - total_time; 168 | Serial.print("Total time used:"); 169 | Serial.print(total_time, DEC); 170 | Serial.println(" millisecond"); 171 | //Clear the capture done flag 172 | myCAM.clear_fifo_flag(); 173 | //Clear the start capture flag 174 | start_capture = 0; 175 | 176 | } 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV2640_LowPowerMode/ArduCAM_Mini_OV2640_LowPowerMode.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "memorysaver.h" 5 | 6 | // set pin 4 as the slave select for the digital pot: 7 | const int CS = 4; 8 | 9 | ArduCAM myCAM(OV2640,CS); 10 | 11 | void setup() { 12 | uint8_t vid,pid; 13 | uint8_t temp; 14 | #if defined (__AVR__) 15 | Wire.begin(); 16 | #endif 17 | #if defined(__arm__) 18 | Wire1.begin(); 19 | #endif 20 | Serial.begin(921600); 21 | Serial.println("ArduCAM Start!"); 22 | 23 | // set the SPI_CS as an output: 24 | pinMode(CS, OUTPUT); 25 | 26 | // initialize SPI: 27 | SPI.begin(); 28 | //Check if the ArduCAM SPI bus is OK 29 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 30 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 31 | 32 | if(temp != 0x55) 33 | { 34 | Serial.println("SPI1 interface Error!"); 35 | //while(1); 36 | } 37 | 38 | myCAM.set_mode(MCU2LCD_MODE); 39 | 40 | //Check if the camera module type is OV2640 41 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 42 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 43 | 44 | if((vid != 0x26) || (pid != 0x42)) 45 | Serial.println("Can't find OV2640 module!"); 46 | else 47 | Serial.println("OV2640 detected."); 48 | 49 | //Change to JPEG capture mode and initialize the OV5642 module 50 | myCAM.set_format(JPEG); 51 | myCAM.InitCAM(); 52 | myCAM.OV2640_set_JPEG_size(OV2640_320x240); 53 | myCAM.clear_fifo_flag(); 54 | myCAM.write_reg(ARDUCHIP_FRAMES,0x00); 55 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);//enable low power 56 | } 57 | 58 | void loop() { 59 | uint8_t temp,temp_last; 60 | uint8_t start_capture = 0; 61 | bool is_header = false; 62 | 63 | temp = Serial.read(); 64 | switch(temp) 65 | { 66 | case 0: 67 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 68 | myCAM.OV2640_set_JPEG_size(OV2640_160x120); 69 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 70 | break; 71 | case 1: 72 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 73 | myCAM.OV2640_set_JPEG_size(OV2640_176x144); 74 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 75 | break; 76 | case 2: 77 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 78 | myCAM.OV2640_set_JPEG_size(OV2640_320x240); 79 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 80 | break; 81 | case 3: 82 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 83 | myCAM.OV2640_set_JPEG_size(OV2640_352x288); 84 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 85 | break; 86 | case 4: 87 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 88 | myCAM.OV2640_set_JPEG_size(OV2640_640x480); 89 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 90 | break; 91 | case 5: 92 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 93 | myCAM.OV2640_set_JPEG_size(OV2640_800x600); 94 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 95 | break; 96 | case 6: 97 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 98 | myCAM.OV2640_set_JPEG_size(OV2640_1024x768); 99 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 100 | break; 101 | case 7: 102 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 103 | myCAM.OV2640_set_JPEG_size(OV2640_1280x1024); 104 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 105 | break; 106 | case 8: 107 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 108 | myCAM.OV2640_set_JPEG_size(OV2640_1600x1200); 109 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 110 | break; 111 | case 0x10: 112 | start_capture = 1; 113 | Serial.println("CAM1 start single shot."); 114 | myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);//disable low power 115 | 116 | delay(800); 117 | break; 118 | default: 119 | break; 120 | } 121 | if(start_capture == 1) 122 | { 123 | myCAM.flush_fifo(); 124 | myCAM.clear_fifo_flag(); 125 | //Start capture 126 | myCAM.start_capture(); 127 | start_capture = 0; 128 | } 129 | if(myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) 130 | { 131 | myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK); 132 | Serial.println("CAM Capture Done!"); 133 | 134 | uint32_t length = 0; 135 | length = myCAM.read_fifo_length(); 136 | Serial.println(length); 137 | if(length >= 393216 ) // 384kb 138 | { 139 | Serial.println("Over size."); 140 | myCAM.clear_fifo_flag(); 141 | return; 142 | } 143 | 144 | if(length == 0 ) //0 kb 145 | { 146 | Serial.println("Size is 0."); 147 | myCAM.clear_fifo_flag(); 148 | return; 149 | } 150 | 151 | temp = 0; 152 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 153 | { 154 | temp_last = temp; 155 | temp = myCAM.read_fifo(); 156 | if(is_header == true) 157 | { 158 | Serial.write(temp); 159 | } 160 | else if((temp == 0xD8) & (temp_last == 0xFF)) 161 | { 162 | is_header = true; 163 | Serial.write(temp_last); 164 | Serial.write(temp); 165 | } 166 | delayMicroseconds(8); 167 | } 168 | //Clear the capture done flag 169 | myCAM.clear_fifo_flag(); 170 | 171 | is_header = false; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV2640_FIFO_UART_Burst/ArduCAM_Mini_OV2640_FIFO_UART_Burst.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV2640 sensor. 7 | // 1. Set the sensor to JPEG output mode. 8 | // 2. Capture and buffer the image to FIFO. 9 | // 3. Transfer the captured JPEG image back to host via Arduino board USB port. 10 | // 4. Resolution can be changed by myCAM.OV2640_set_JPEG_size() function. 11 | // This program requires the ArduCAM V3.0.1 (or above) library and Rev.C ArduCAM shield 12 | // and use Arduino IDE 1.5.2 compiler 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | // set pin 10 as the slave select for the digital pot: 20 | const int SPI_CS = 10; 21 | 22 | 23 | ArduCAM myCAM(OV2640, SPI_CS); 24 | 25 | void setup() 26 | { 27 | uint8_t vid, pid; 28 | uint8_t temp; 29 | 30 | Serial.begin(115200); 31 | Serial.println("ArduCAM Start!"); 32 | 33 | myCAM.begin();; 34 | //Check if the ArduCAM SPI bus is OK 35 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 36 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 37 | if (temp != 0x55) 38 | { 39 | Serial.println("SPI interface Error!"); 40 | Serial.print(temp, HEX); 41 | while (1); 42 | } 43 | 44 | //myCAM.set_mode(MCU2LCD_MODE); 45 | 46 | //Check if the camera module type is OV2640 47 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 48 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 49 | if ((vid != 0x26) || (pid != 0x42)) 50 | Serial.println("Can't find OV2640 module!"); 51 | else 52 | Serial.println("OV2640 detected"); 53 | 54 | //Change to JPEG capture mode and initialize the OV2640 module 55 | myCAM.set_format(JPEG); 56 | //myCAM.set_format(BMP); 57 | myCAM.InitCAM(); 58 | myCAM.OV2640_set_JPEG_size(OV2640_320x240); 59 | myCAM.clear_fifo_flag(); 60 | //myCAM.write_reg(0x81, 0x00); 61 | myCAM.write_reg(ARDUCHIP_FRAMES, 0x00); //Bit[2:0]Number of frames to be captured 62 | } 63 | 64 | void loop() 65 | { 66 | uint8_t temp, temp_last; 67 | uint8_t start_capture = 0; 68 | static int Ts, Tc, Td, Tt, Tu, T0; 69 | T0 = millis(); 70 | temp = Serial.read(); 71 | Tu = millis(); 72 | switch (temp) 73 | { 74 | case 0: 75 | myCAM.OV2640_set_JPEG_size(OV2640_160x120); 76 | break; 77 | case 1: 78 | myCAM.OV2640_set_JPEG_size(OV2640_176x144); 79 | break; 80 | case 2: 81 | myCAM.OV2640_set_JPEG_size(OV2640_320x240); 82 | break; 83 | case 3: 84 | myCAM.OV2640_set_JPEG_size(OV2640_352x288); 85 | break; 86 | case 4: 87 | myCAM.OV2640_set_JPEG_size(OV2640_640x480); 88 | break; 89 | case 5: 90 | myCAM.OV2640_set_JPEG_size(OV2640_800x600); 91 | break; 92 | case 6: 93 | myCAM.OV2640_set_JPEG_size(OV2640_1024x768); 94 | break; 95 | case 7: 96 | myCAM.OV2640_set_JPEG_size(OV2640_1280x1024); 97 | break; 98 | case 8: 99 | myCAM.OV2640_set_JPEG_size(OV2640_1600x1200); 100 | break; 101 | case 0x0a: 102 | //temp_last = myCAM.read_reg(0x03); 103 | //myCAM.write_reg(0x83, temp_last|0x40); 104 | myCAM.set_bit(ARDUCHIP_TIM, LOW_POWER_MODE); 105 | break; 106 | case 0x0b: 107 | myCAM.clear_bit(ARDUCHIP_TIM, LOW_POWER_MODE); 108 | break; 109 | case 0x0c: 110 | myCAM.set_bit(ARDUCHIP_FIFO, FIFO_RDPTR_RST_MASK); 111 | read_fifo_again(); 112 | break; 113 | case 0x0d: //reset 114 | myCAM.set_bit(ARDUCHIP_GPIO, GPIO_RESET_MASK); 115 | myCAM.clear_bit(ARDUCHIP_GPIO, GPIO_RESET_MASK); 116 | break; 117 | case 0x0e: //pwdn low 118 | myCAM.set_bit(ARDUCHIP_GPIO, GPIO_PWDN_MASK); 119 | break; 120 | case 0x0f: //pwdn 121 | myCAM.clear_bit(ARDUCHIP_GPIO, GPIO_PWDN_MASK); 122 | break; 123 | case 0x10: 124 | start_capture = 1; 125 | Serial.println("Start Capture"); 126 | Ts = millis(); 127 | myCAM.flush_fifo(); 128 | break; 129 | default: 130 | break; 131 | } 132 | 133 | if (start_capture) 134 | { 135 | //Clear the capture done flag 136 | myCAM.clear_fifo_flag(); 137 | //Start capture 138 | myCAM.start_capture(); 139 | start_capture = 0; 140 | Tc = millis(); 141 | } 142 | if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) 143 | { 144 | Td = millis(); 145 | Serial.println("Capture Done!"); 146 | read_fifo_burst(); 147 | Tt = millis(); 148 | //Clear the capture done flag 149 | myCAM.clear_fifo_flag(); 150 | start_capture = 0; 151 | Serial.println(""); 152 | Serial.println("-----------------------"); 153 | Serial.println("Time used:"); 154 | Serial.println(Tu - T0, DEC); 155 | Serial.println(Tc - Ts, DEC); 156 | Serial.println(Td - Tc, DEC); 157 | Serial.println(Tt - Td, DEC); 158 | 159 | } 160 | } 161 | 162 | uint8_t read_fifo_burst() 163 | { 164 | uint32_t length = 0; 165 | uint8_t temp, temp_last; 166 | length = myCAM.read_fifo_length(); 167 | if (length >= 393216) //384 kb 168 | { 169 | Serial.println("Not found the end."); 170 | return 0; 171 | } 172 | Serial.println(length); 173 | myCAM.startSend(); 174 | myCAM.set_fifo_burst(); 175 | //SPI.transfer(0x3C); 176 | //SPI.transfer(0x00); 177 | //Serial.write(0xff); 178 | length--; 179 | while ( length-- ) 180 | { 181 | temp_last = temp; 182 | temp = myCAM.sendData(0x00); 183 | Serial.write(temp); 184 | if ( (temp == 0xD9) && (temp_last == 0xFF) ) 185 | break; 186 | delayMicroseconds(10); 187 | } 188 | myCAM.endSend(); 189 | } 190 | 191 | void read_fifo_again() 192 | { 193 | read_fifo_burst(); 194 | } 195 | 196 | 197 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV2640_Digital_Camera/ArduCAM_OV2640_Digital_Camera.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules, and can run on any Arduino platform. 5 | // 6 | // This demo was made for Omnivision OV2640 2MP sensor. 7 | // It will run the ArduCAM as a real 2MP digital camera, provide both preview and JPEG capture. 8 | // The demo sketch will do the following tasks: 9 | // 1. Set the sensor to BMP preview output mode. 10 | // 2. Switch to JPEG mode when shutter buttom pressed. 11 | // 3. Capture and buffer the image to FIFO. 12 | // 4. Store the image to Micro SD/TF card with JPEG format. 13 | // 5. Resolution can be changed by myCAM.set_JPEG_size() function. 14 | // This program requires the ArduCAM V3.1.0 (or later) library and Rev.C ArduCAM shield 15 | // and use Arduino IDE 1.5.2 compiler or above 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "memorysaver.h" 23 | 24 | #if defined(__arm__) 25 | #include 26 | #endif 27 | 28 | #define SD_CS 9 29 | // set pin 10 as the slave select for SPI: 30 | const int SPI_CS = 10; 31 | 32 | ArduCAM myCAM(OV2640,SPI_CS); 33 | UTFT myGLCD(SPI_CS); 34 | boolean isShowFlag = true; 35 | 36 | void setup() 37 | { 38 | uint8_t vid,pid; 39 | uint8_t temp; 40 | #if defined (__AVR__) 41 | Wire.begin(); 42 | #endif 43 | #if defined(__arm__) 44 | Wire1.begin(); 45 | #endif 46 | Serial.begin(115200); 47 | Serial.println("ArduCAM Start!"); 48 | // set the SPI_CS as an output: 49 | pinMode(SPI_CS, OUTPUT); 50 | 51 | // initialize SPI: 52 | SPI.begin(); 53 | //Check if the ArduCAM SPI bus is OK 54 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 55 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 56 | if(temp != 0x55) 57 | { 58 | Serial.println("SPI interface Error!"); 59 | while(1); 60 | } 61 | 62 | //Change MCU mode 63 | myCAM.set_mode(MCU2LCD_MODE); 64 | 65 | myGLCD.InitLCD(); 66 | 67 | //Check if the camera module type is OV2640 68 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 69 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 70 | if((vid != 0x26) || (pid != 0x42)) 71 | Serial.println("Can't find OV2640 module!"); 72 | else 73 | Serial.println("OV2640 detected"); 74 | 75 | //Change to BMP capture mode and initialize the OV2640 module 76 | myCAM.set_format(BMP); 77 | 78 | myCAM.InitCAM(); 79 | 80 | //Initialize SD Card 81 | if (!SD.begin(SD_CS)) 82 | { 83 | //while (1); //If failed, stop here 84 | Serial.println("SD Card Error"); 85 | } 86 | else 87 | Serial.println("SD Card detected!"); 88 | } 89 | 90 | void loop() 91 | { 92 | char str[8]; 93 | File outFile; 94 | byte buf[256]; 95 | static int i = 0; 96 | static int k = 0; 97 | static int n = 0; 98 | uint8_t temp,temp_last; 99 | uint8_t start_capture = 0; 100 | int total_time = 0; 101 | 102 | //Wait trigger from shutter buttom 103 | if(myCAM.get_bit(ARDUCHIP_TRIG , SHUTTER_MASK)) 104 | { 105 | isShowFlag = false; 106 | myCAM.set_mode(MCU2LCD_MODE); 107 | myCAM.set_format(JPEG); 108 | myCAM.InitCAM(); 109 | 110 | myCAM.OV2640_set_JPEG_size(OV2640_640x480); 111 | //myCAM.OV2640_set_JPEG_size(OV2640_1600x1200); 112 | //Wait until buttom released 113 | while(myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)); 114 | delay(1000); 115 | start_capture = 1; 116 | 117 | } 118 | else 119 | { 120 | if(isShowFlag ) 121 | { 122 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 123 | { 124 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 125 | myGLCD.resetXY(); 126 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 127 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 128 | } 129 | } 130 | } 131 | if(start_capture) 132 | { 133 | //Flush the FIFO 134 | myCAM.flush_fifo(); 135 | //Clear the capture done flag 136 | myCAM.clear_fifo_flag(); 137 | //Start capture 138 | myCAM.start_capture(); 139 | Serial.println("Start Capture"); 140 | } 141 | 142 | if(myCAM.get_bit(ARDUCHIP_TRIG ,CAP_DONE_MASK)) 143 | { 144 | 145 | Serial.println("Capture Done!"); 146 | 147 | //Construct a file name 148 | k = k + 1; 149 | itoa(k, str, 10); 150 | strcat(str,".jpg"); 151 | //Open the new file 152 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 153 | if (! outFile) 154 | { 155 | Serial.println("open file failed"); 156 | return; 157 | } 158 | total_time = millis(); 159 | i = 0; 160 | temp = myCAM.read_fifo(); 161 | //Write first image data to buffer 162 | buf[i++] = temp; 163 | 164 | //Read JPEG data from FIFO 165 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 166 | { 167 | temp_last = temp; 168 | temp = myCAM.read_fifo(); 169 | //Write image data to buffer if not full 170 | if(i < 256) 171 | buf[i++] = temp; 172 | else 173 | { 174 | //Write 256 bytes image data to file 175 | outFile.write(buf,256); 176 | i = 0; 177 | buf[i++] = temp; 178 | } 179 | } 180 | //Write the remain bytes in the buffer 181 | if(i > 0) 182 | outFile.write(buf,i); 183 | 184 | //Close the file 185 | outFile.close(); 186 | total_time = millis() - total_time; 187 | Serial.print("Total time used:"); 188 | Serial.print(total_time, DEC); 189 | Serial.println(" millisecond"); 190 | //Clear the capture done flag 191 | myCAM.clear_fifo_flag(); 192 | //Clear the start capture flag 193 | start_capture = 0; 194 | 195 | myCAM.set_format(BMP); 196 | myCAM.InitCAM(); 197 | isShowFlag = true; 198 | } 199 | } 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /examples/ESP8266/ArduCAM_Mini_OV2640_websocket_server/ArduCAM_Mini_OV2640_websocket_server.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM Mini demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo for ESP8266 arduino board. 4 | // Publish captured image to a webpage. 5 | // 6 | // This demo was made for ArduCAM Mini OV2640 2MP Camera. 7 | // It needs to be used in combination with html webpage. 8 | // 9 | 10 | // This version uses the last sumotoy changes to work 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | // Enabe debug tracing to Serial port. 24 | #define DEBUGGING 25 | 26 | // Here we define a maximum framelength to 64 bytes. Default is 256. 27 | #if defined MAX_FRAME_LENGTH 28 | #undef MAX_FRAME_LENGTH 29 | #define MAX_FRAME_LENGTH 64 30 | #endif 31 | 32 | // Define how many callback functions you have. Default is 1. 33 | #define CALLBACK_FUNCTIONS 1 34 | 35 | 36 | const int CS = 16; 37 | 38 | const char* ssid = "your sid"; 39 | const char* password = "your sid pass"; 40 | 41 | 42 | // Create an instance of the server 43 | // specify the port to listen on as an argument 44 | WiFiServer server(80); 45 | WebSocketServer webSocketServer; 46 | 47 | void read_fifo_burst(ArduCAM myCAM); 48 | 49 | ArduCAM myCAM(OV2640, CS); 50 | 51 | 52 | void setup() { 53 | 54 | uint8_t vid, pid; 55 | uint8_t temp; 56 | 57 | Serial.begin(115200); 58 | Serial.println("\nArduCAM Start!"); 59 | myCAM.begin(); 60 | 61 | //Check if the ArduCAM SPI bus is OK 62 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 63 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 64 | if (temp != 0x55) 65 | { 66 | Serial.println("SPI1 interface Error!"); 67 | } 68 | 69 | //Check if the camera module type is OV2640 70 | myCAM.wrSensorReg8_8(0xff, 0x01); 71 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 72 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 73 | if ((vid != 0x26) || (pid != 0x42)) 74 | Serial.println("Can't find OV2640 module!"); 75 | else 76 | Serial.println("OV2640 detected."); 77 | 78 | //Change to JPEG capture mode and initialize the OV2640 module 79 | myCAM.set_format(JPEG); 80 | myCAM.InitCAM(); 81 | myCAM.OV2640_set_JPEG_size(OV2640_320x240); 82 | //myCAM.OV2640_set_JPEG_size(OV2640_640x480); 83 | myCAM.clear_fifo_flag(); 84 | myCAM.write_reg(ARDUCHIP_FRAMES, 0x00); 85 | 86 | // Connect to WiFi network 87 | Serial.println(); 88 | Serial.print("Connecting to "); 89 | Serial.println(ssid); 90 | 91 | WiFi.begin(ssid, password); 92 | 93 | while (WiFi.status() != WL_CONNECTED) { 94 | delay(500); 95 | Serial.print("."); 96 | } 97 | Serial.println(""); 98 | Serial.println("WiFi connected"); 99 | 100 | // Start the server 101 | server.begin(); 102 | Serial.println("Server started"); 103 | 104 | // Print the IP address 105 | Serial.println(WiFi.localIP()); 106 | } 107 | 108 | void loop() { 109 | // put your main code here, to run repeatedly: 110 | String data; 111 | int total_time = 0; 112 | 113 | WiFiClient client = server.available(); 114 | if (webSocketServer.handshake(client)) { 115 | while (client.connected() ) 116 | { 117 | data = webSocketServer.getData(); 118 | if (data.length() > 0) 119 | { 120 | handleClientData(data); 121 | } 122 | 123 | if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) 124 | { 125 | Serial.println("CAM Capture Done!"); 126 | total_time = millis(); 127 | read_fifo_burst(myCAM); 128 | total_time = millis() - total_time; 129 | Serial.print("total_time used (in miliseconds):"); 130 | Serial.println(total_time, DEC); 131 | Serial.println("CAM send Done!"); 132 | //Clear the capture done flag 133 | myCAM.clear_fifo_flag(); 134 | 135 | } 136 | } 137 | 138 | } 139 | // This delay is needed to let the WiFi respond properly(very important) 140 | delay(100); 141 | } 142 | 143 | void handleClientData(String &dataString) 144 | { 145 | if (dataString.startsWith("capture")) 146 | { 147 | Serial.println(dataString); 148 | start_capture(); 149 | } 150 | } 151 | 152 | // send the client the analog value of a pin 153 | void sendClientData(char *data, int size, unsigned char header) { 154 | webSocketServer.sendData(data, size, header); 155 | } 156 | 157 | 158 | void start_capture() 159 | { 160 | myCAM.flush_fifo(); 161 | myCAM.clear_fifo_flag(); 162 | myCAM.start_capture(); 163 | } 164 | 165 | void read_fifo_burst(ArduCAM myCAM) 166 | { 167 | uint8_t temp, temp_last; 168 | static int i = 0; 169 | static uint8_t first_packet = 1; 170 | byte buf[2048]; 171 | uint32_t length = 0; 172 | 173 | length = myCAM.read_fifo_length(); 174 | if (length >= 393216 ) // 384kb 175 | { 176 | Serial.println("Over size."); 177 | return; 178 | } 179 | if (length == 0 ) //0 kb 180 | { 181 | Serial.println("Size is 0."); 182 | return; 183 | } 184 | myCAM.startSend(); 185 | myCAM.set_fifo_burst();//Set fifo burst mode 186 | myCAM.sendData(0x00); 187 | //Read JPEG data from FIFO 188 | while ( (temp != 0xD9) | (temp_last != 0xFF)) 189 | { 190 | temp_last = temp; 191 | temp = myCAM.sendData(0x00); 192 | if (i < 2048) 193 | { 194 | buf[i++] = temp; 195 | //yield(); 196 | } 197 | else 198 | { 199 | if (first_packet == 1) 200 | { 201 | sendClientData((char*)buf, 2048, 0x02); 202 | first_packet = 0; 203 | } 204 | else 205 | { 206 | sendClientData((char*)buf, 2048, 0x00); 207 | } 208 | i = 0; 209 | buf[i++] = temp; 210 | 211 | } 212 | //yield(); 213 | } 214 | if (i > 0) 215 | { 216 | sendClientData((char*)buf, i, 0x80); 217 | i = 0; 218 | first_packet = 1; 219 | } 220 | //yield(); 221 | myCAM.endSend(); 222 | } -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV5642_Digital_Camera/ArduCAM_OV5642_Digital_Camera.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules, and can run on any Arduino platform. 5 | // 6 | // This demo was made for Omnivision OV5642 5MP sensor. 7 | // It will run the ArduCAM as a real 5MP digital camera, provide both preview and JPEG capture. 8 | // The demo sketch will do the following tasks: 9 | // 1. Set the sensor to BMP preview output mode. 10 | // 2. Switch to JPEG mode when shutter buttom pressed. 11 | // 3. Capture and buffer the image to FIFO. 12 | // 4. Store the image to Micro SD/TF card with JPEG format. 13 | // 5. Resolution can be changed by myCAM.OV5642_set_JPEG_size() function. 14 | // This program requires the ArduCAM V3.1.0 (or later) library and Rev.C ArduCAM shield 15 | // and use Arduino IDE 1.5.2 compiler or above 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "memorysaver.h" 23 | 24 | #if defined(__arm__) 25 | #include 26 | #endif 27 | 28 | #define SD_CS 9 29 | // set pin 10 as the slave select for SPI: 30 | const int SPI_CS = 10; 31 | 32 | ArduCAM myCAM(OV5642,SPI_CS); 33 | UTFT myGLCD(SPI_CS); 34 | boolean isShowFlag = true; 35 | 36 | void setup() 37 | { 38 | uint8_t vid,pid; 39 | uint8_t temp; 40 | #if defined (__AVR__) 41 | Wire.begin(); 42 | #endif 43 | #if defined(__arm__) 44 | Wire1.begin(); 45 | #endif 46 | Serial.begin(115200); 47 | Serial.println("ArduCAM Start!"); 48 | // set the SPI_CS as an output: 49 | pinMode(SPI_CS, OUTPUT); 50 | 51 | // initialize SPI: 52 | SPI.begin(); 53 | //Check if the ArduCAM SPI bus is OK 54 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 55 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 56 | if(temp != 0x55) 57 | { 58 | Serial.println("SPI interface Error!"); 59 | while(1); 60 | } 61 | 62 | //Change MCU mode 63 | myCAM.set_mode(MCU2LCD_MODE); 64 | 65 | myGLCD.InitLCD(); 66 | 67 | //Check if the camera module type is OV5642 68 | myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); 69 | myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); 70 | if((vid != 0x56) || (pid != 0x42)) 71 | Serial.println("Can't find OV5642 module!"); 72 | else 73 | Serial.println("OV5642 detected"); 74 | 75 | //Change to BMP capture mode and initialize the OV5642 module 76 | myCAM.set_format(BMP); 77 | 78 | myCAM.InitCAM(); 79 | 80 | 81 | 82 | //Initialize SD Card 83 | if (!SD.begin(SD_CS)) 84 | { 85 | //while (1); //If failed, stop here 86 | Serial.println("SD Card Error"); 87 | } 88 | else 89 | Serial.println("SD Card detected!"); 90 | } 91 | 92 | void loop() 93 | { 94 | char str[8]; 95 | File outFile; 96 | byte buf[256]; 97 | static int i = 0; 98 | static int k = 0; 99 | static int n = 0; 100 | uint8_t temp,temp_last; 101 | uint8_t start_capture = 0; 102 | int total_time = 0; 103 | 104 | //Wait trigger from shutter buttom 105 | if(myCAM.get_bit(ARDUCHIP_TRIG , SHUTTER_MASK)) 106 | { 107 | isShowFlag = false; 108 | myCAM.set_mode(MCU2LCD_MODE); 109 | myCAM.set_format(JPEG); 110 | myCAM.InitCAM(); 111 | myCAM.OV5642_set_JPEG_size(OV5642_320x240); 112 | myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH 113 | 114 | //Wait until buttom released 115 | while(myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)); 116 | delay(1000); 117 | start_capture = 1; 118 | } 119 | else 120 | { 121 | if(isShowFlag ) 122 | { 123 | 124 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 125 | { 126 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 127 | myGLCD.resetXY(); 128 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 129 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 130 | } 131 | } 132 | } 133 | if(start_capture) 134 | { 135 | //Flush the FIFO 136 | myCAM.flush_fifo(); 137 | //Clear the capture done flag 138 | myCAM.clear_fifo_flag(); 139 | //Start capture 140 | myCAM.start_capture(); 141 | Serial.println("Start Capture"); 142 | } 143 | 144 | if(myCAM.get_bit(ARDUCHIP_TRIG ,CAP_DONE_MASK)) 145 | { 146 | 147 | Serial.println("Capture Done!"); 148 | //Construct a file name 149 | k = k + 1; 150 | itoa(k, str, 10); 151 | strcat(str,".jpg"); 152 | //Open the new file 153 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 154 | if (! outFile) 155 | { 156 | Serial.println("open file failed"); 157 | return; 158 | } 159 | total_time = millis(); 160 | //Read first dummy byte 161 | //myCAM.read_fifo(); 162 | 163 | i = 0; 164 | temp = myCAM.read_fifo(); 165 | //Write first image data to buffer 166 | buf[i++] = temp; 167 | 168 | //Read JPEG data from FIFO 169 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 170 | { 171 | temp_last = temp; 172 | temp = myCAM.read_fifo(); 173 | //Write image data to buffer if not full 174 | if(i < 256) 175 | buf[i++] = temp; 176 | else 177 | { 178 | //Write 256 bytes image data to file 179 | outFile.write(buf,256); 180 | i = 0; 181 | buf[i++] = temp; 182 | } 183 | } 184 | //Write the remain bytes in the buffer 185 | if(i > 0) 186 | outFile.write(buf,i); 187 | 188 | //Close the file 189 | outFile.close(); 190 | total_time = millis() - total_time; 191 | Serial.print("Total time used:"); 192 | Serial.print(total_time, DEC); 193 | Serial.println(" millisecond"); 194 | //Clear the capture done flag 195 | myCAM.clear_fifo_flag(); 196 | //Clear the start capture flag 197 | start_capture = 0; 198 | 199 | myCAM.set_format(BMP); 200 | myCAM.InitCAM(); 201 | isShowFlag = true; 202 | } 203 | } 204 | 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV7670_Camera_Playback/ArduCAM_OV7670_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV7670 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.1.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(OV7670,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Change MCU mode 75 | myCAM.set_mode(MCU2LCD_MODE); 76 | 77 | //Initialize the LCD Module 78 | myGLCD.InitLCD(); 79 | 80 | myCAM.InitCAM(); 81 | 82 | //Initialize SD Card 83 | if (!SD.begin(SD_CS)) 84 | { 85 | //while (1); //If failed, stop here 86 | Serial.println("SD Card Error"); 87 | } 88 | else 89 | Serial.println("SD Card detected!"); 90 | } 91 | 92 | void loop() 93 | { 94 | char str[8]; 95 | unsigned long previous_time = 0; 96 | static int k = 0; 97 | uint8_t temp; 98 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 99 | 100 | while(1) 101 | { 102 | 103 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 104 | { 105 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 106 | myGLCD.resetXY(); 107 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 108 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 109 | } 110 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 111 | { 112 | previous_time = millis(); 113 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 114 | { 115 | if((millis() - previous_time) > 1500) 116 | { 117 | Playback(); 118 | } 119 | } 120 | if((millis() - previous_time) < 1500) 121 | { 122 | k = k + 1; 123 | itoa(k, str, 10); 124 | strcat(str,".bmp"); //Generate file name 125 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 126 | GrabImage(str); 127 | } 128 | } 129 | } 130 | } 131 | 132 | 133 | void GrabImage(char* str) 134 | { 135 | File outFile; 136 | char VH,VL; 137 | uint8_t temp; 138 | byte buf[256]; 139 | static int k = 0; 140 | int i,j = 0; 141 | 142 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 143 | if (! outFile) 144 | { 145 | Serial.println("Open File Error"); 146 | return; 147 | } 148 | 149 | //Switch to FIFO Mode 150 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 151 | //Flush the FIFO 152 | myCAM.flush_fifo(); 153 | //Start capture 154 | myCAM.start_capture(); 155 | Serial.println("Start Capture"); 156 | 157 | //Polling the capture done flag 158 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 159 | Serial.println("Capture Done!"); 160 | 161 | k = 0; 162 | //Write the BMP header 163 | for( i = 0; i < BMPIMAGEOFFSET; i++) 164 | { 165 | char ch = pgm_read_byte(&bmp_header[i]); 166 | buf[k++] = ch; 167 | } 168 | outFile.write(buf,k); 169 | //Read first dummy byte 170 | //myCAM.read_fifo(); 171 | 172 | k = 0; 173 | //Read 320x240x2 byte from FIFO 174 | //Save as RGB565 bmp format 175 | for(i = 0; i < 240; i++) 176 | for(j = 0; j < 320; j++) 177 | { 178 | VH = myCAM.read_fifo(); 179 | VL = myCAM.read_fifo(); 180 | buf[k++] = VL; 181 | buf[k++] = VH; 182 | //Write image data to bufer if not full 183 | if(k >= 256) 184 | { 185 | //Write 256 bytes image data to file from buffer 186 | outFile.write(buf,256); 187 | k = 0; 188 | } 189 | } 190 | //Close the file 191 | outFile.close(); 192 | //Clear the capture done flag 193 | myCAM.clear_fifo_flag(); 194 | 195 | //Switch to LCD Mode 196 | myCAM.write_reg(ARDUCHIP_TIM, 0); 197 | return; 198 | } 199 | 200 | void Playback() 201 | { 202 | File inFile; 203 | char str[8]; 204 | int k = 0; 205 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 206 | myGLCD.InitLCD(PORTRAIT); 207 | 208 | while(1) 209 | { 210 | k = k + 1; 211 | itoa(k, str, 10); 212 | strcat(str,".bmp"); 213 | inFile = SD.open(str,FILE_READ); 214 | if (! inFile) 215 | return; 216 | myGLCD.clrScr(); 217 | //myGLCD.resetXY(); 218 | dispBitmap(inFile); 219 | inFile.close(); 220 | delay(2000); 221 | } 222 | } 223 | //Only support RGB565 bmp format 224 | void dispBitmap(File inFile) 225 | { 226 | char VH,VL; 227 | int i,j = 0; 228 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 229 | inFile.read(); 230 | for(i = 0; i < 320; i++) 231 | for(j = 0; j < 240; j++) 232 | { 233 | VL = inFile.read(); 234 | //Serial.write(VL); 235 | VH = inFile.read(); 236 | //Serial.write(VH); 237 | myGLCD.LCD_Write_DATA(VH,VL); 238 | } 239 | myGLCD.clrXY(); 240 | } 241 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV3640_Camera_Playback/ArduCAM_OV3640_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV3640 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.1.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(OV3640,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Change MCU mode 75 | myCAM.set_mode(MCU2LCD_MODE); 76 | 77 | //Initialize the LCD Module 78 | myGLCD.InitLCD(); 79 | 80 | myCAM.InitCAM(); 81 | 82 | //Initialize SD Card 83 | if (!SD.begin(SD_CS)) 84 | { 85 | //while (1); //If failed, stop here 86 | Serial.println("SD Card Error"); 87 | } 88 | else 89 | Serial.println("SD Card detected!"); 90 | } 91 | 92 | void loop() 93 | { 94 | char str[8]; 95 | unsigned long previous_time = 0; 96 | static int k = 0; 97 | uint8_t temp; 98 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 99 | 100 | while(1) 101 | { 102 | 103 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 104 | { 105 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 106 | myGLCD.resetXY(); 107 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 108 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 109 | } 110 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 111 | { 112 | previous_time = millis(); 113 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 114 | { 115 | if((millis() - previous_time) > 1500) 116 | { 117 | Playback(); 118 | } 119 | } 120 | if((millis() - previous_time) < 1500) 121 | { 122 | k = k + 1; 123 | itoa(k, str, 10); 124 | strcat(str,".bmp"); //Generate file name 125 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 126 | GrabImage(str); 127 | } 128 | } 129 | } 130 | } 131 | 132 | 133 | void GrabImage(char* str) 134 | { 135 | File outFile; 136 | char VH,VL; 137 | uint8_t temp; 138 | byte buf[256]; 139 | static int k = 0; 140 | int i,j = 0; 141 | 142 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 143 | if (! outFile) 144 | { 145 | Serial.println("Open File Error"); 146 | return; 147 | } 148 | 149 | //Switch to FIFO Mode 150 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 151 | //Flush the FIFO 152 | myCAM.flush_fifo(); 153 | //Start capture 154 | myCAM.start_capture(); 155 | Serial.println("Start Capture"); 156 | 157 | //Polling the capture done flag 158 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 159 | Serial.println("Capture Done!"); 160 | 161 | k = 0; 162 | //Write the BMP header 163 | for( i = 0; i < BMPIMAGEOFFSET; i++) 164 | { 165 | char ch = pgm_read_byte(&bmp_header[i]); 166 | buf[k++] = ch; 167 | } 168 | outFile.write(buf,k); 169 | //Read first dummy byte 170 | //myCAM.read_fifo(); 171 | 172 | k = 0; 173 | //Read 320x240x2 byte from FIFO 174 | //Save as RGB565 bmp format 175 | for(i = 0; i < 240; i++) 176 | for(j = 0; j < 320; j++) 177 | { 178 | VH = myCAM.read_fifo(); 179 | VL = myCAM.read_fifo(); 180 | buf[k++] = VL; 181 | buf[k++] = VH; 182 | //Write image data to bufer if not full 183 | if(k >= 256) 184 | { 185 | //Write 256 bytes image data to file from buffer 186 | outFile.write(buf,256); 187 | k = 0; 188 | } 189 | } 190 | //Close the file 191 | outFile.close(); 192 | //Clear the capture done flag 193 | myCAM.clear_fifo_flag(); 194 | 195 | //Switch to LCD Mode 196 | myCAM.write_reg(ARDUCHIP_TIM, 0); 197 | return; 198 | } 199 | 200 | void Playback() 201 | { 202 | File inFile; 203 | char str[8]; 204 | int k = 0; 205 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 206 | myGLCD.InitLCD(PORTRAIT); 207 | 208 | while(1) 209 | { 210 | k = k + 1; 211 | itoa(k, str, 10); 212 | strcat(str,".bmp"); 213 | inFile = SD.open(str,FILE_READ); 214 | if (! inFile) 215 | return; 216 | myGLCD.clrScr(); 217 | //myGLCD.resetXY(); 218 | dispBitmap(inFile); 219 | inFile.close(); 220 | delay(2000); 221 | } 222 | } 223 | 224 | //Only support RGB565 bmp format 225 | void dispBitmap(File inFile) 226 | { 227 | char VH,VL; 228 | int i,j = 0; 229 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 230 | inFile.read(); 231 | for(i = 0; i < 320; i++) 232 | for(j = 0; j < 240; j++) 233 | { 234 | VL = inFile.read(); 235 | //Serial.write(VL); 236 | VH = inFile.read(); 237 | //Serial.write(VH); 238 | myGLCD.LCD_Write_DATA(VH,VL); 239 | } 240 | myGLCD.clrXY(); 241 | } 242 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV7675_Camera_Playback/ArduCAM_OV7675_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV7675 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.1.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(OV7675,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Change MCU mode 75 | myCAM.set_mode(MCU2LCD_MODE); 76 | 77 | //Initialize the LCD Module 78 | myGLCD.InitLCD(); 79 | 80 | myCAM.InitCAM(); 81 | 82 | //Initialize SD Card 83 | if (!SD.begin(SD_CS)) 84 | { 85 | //while (1); //If failed, stop here 86 | Serial.println("SD Card Error"); 87 | } 88 | else 89 | Serial.println("SD Card detected!"); 90 | } 91 | 92 | void loop() 93 | { 94 | char str[8]; 95 | unsigned long previous_time = 0; 96 | static int k = 0; 97 | uint8_t temp; 98 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 99 | 100 | while(1) 101 | { 102 | 103 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 104 | { 105 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 106 | myGLCD.resetXY(); 107 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 108 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 109 | } 110 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 111 | { 112 | previous_time = millis(); 113 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 114 | { 115 | if((millis() - previous_time) > 1500) 116 | { 117 | Playback(); 118 | } 119 | } 120 | if((millis() - previous_time) < 1500) 121 | { 122 | k = k + 1; 123 | itoa(k, str, 10); 124 | strcat(str,".bmp"); //Generate file name 125 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 126 | GrabImage(str); 127 | } 128 | } 129 | } 130 | } 131 | 132 | 133 | void GrabImage(char* str) 134 | { 135 | File outFile; 136 | char VH,VL; 137 | uint8_t temp; 138 | byte buf[256]; 139 | static int k = 0; 140 | int i,j = 0; 141 | 142 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 143 | if (! outFile) 144 | { 145 | Serial.println("Open File Error"); 146 | return; 147 | } 148 | 149 | //Switch to FIFO Mode 150 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 151 | //Flush the FIFO 152 | myCAM.flush_fifo(); 153 | //Start capture 154 | myCAM.start_capture(); 155 | Serial.println("Start Capture"); 156 | 157 | //Polling the capture done flag 158 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 159 | Serial.println("Capture Done!"); 160 | 161 | k = 0; 162 | //Write the BMP header 163 | for( i = 0; i < BMPIMAGEOFFSET; i++) 164 | { 165 | char ch = pgm_read_byte(&bmp_header[i]); 166 | buf[k++] = ch; 167 | } 168 | outFile.write(buf,k); 169 | //Read first dummy byte 170 | myCAM.read_fifo(); 171 | 172 | k = 0; 173 | //Read 320x240x2 byte from FIFO 174 | //Save as RGB565 bmp format 175 | for(i = 0; i < 240; i++) 176 | for(j = 0; j < 320; j++) 177 | { 178 | VH = myCAM.read_fifo(); 179 | VL = myCAM.read_fifo(); 180 | buf[k++] = VL; 181 | buf[k++] = VH; 182 | //Write image data to bufer if not full 183 | if(k >= 256) 184 | { 185 | //Write 256 bytes image data to file from buffer 186 | outFile.write(buf,256); 187 | k = 0; 188 | } 189 | } 190 | //Close the file 191 | outFile.close(); 192 | //Clear the capture done flag 193 | myCAM.clear_fifo_flag(); 194 | 195 | //Switch to LCD Mode 196 | myCAM.write_reg(ARDUCHIP_TIM, 0); 197 | return; 198 | } 199 | 200 | void Playback() 201 | { 202 | File inFile; 203 | char str[8]; 204 | int k = 0; 205 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 206 | myGLCD.InitLCD(PORTRAIT); 207 | 208 | while(1) 209 | { 210 | k = k + 1; 211 | itoa(k, str, 10); 212 | strcat(str,".bmp"); 213 | inFile = SD.open(str,FILE_READ); 214 | if (! inFile) 215 | return; 216 | myGLCD.clrScr(); 217 | //myGLCD.resetXY(); 218 | dispBitmap(inFile); 219 | inFile.close(); 220 | delay(2000); 221 | } 222 | } 223 | 224 | //Only support RGB565 bmp format 225 | void dispBitmap(File inFile) 226 | { 227 | char VH,VL; 228 | int i,j = 0; 229 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 230 | inFile.read(); 231 | for(i = 0; i < 320; i++) 232 | for(j = 0; j < 240; j++) 233 | { 234 | VL = inFile.read(); 235 | //Serial.write(VL); 236 | VH = inFile.read(); 237 | //Serial.write(VH); 238 | myGLCD.LCD_Write_DATA(VH,VL); 239 | } 240 | myGLCD.clrXY(); 241 | } 242 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV2640_Yun_WebServer/ArduCAM_Mini_OV2640_Yun_WebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | In this sketch folder is a basic webpage and a copy of zepto.js, a 3 | minimized version of jQuery. When you upload your sketch, place the 4 | ArduCAMYun floder in the /arduino/www folder on your SD card.Then you can 5 | access link such as http;//arduino.local/sd/ArduCAMYun to see the basic webpage. 6 | It can control the ArduCAM to take photos. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | const int CS1 = 10; 19 | uint8_t capture = 0; 20 | uint8_t save_done = 0; 21 | char ip[16]; 22 | int m; 23 | char filename[20]; 24 | ArduCAM myCAM1(OV2640,CS1); 25 | 26 | // Listen on default port 5555, the webserver on the Yún 27 | // will forward there all the HTTP requests for us. 28 | YunServer server; 29 | 30 | void setup() 31 | { 32 | uint8_t vid,pid; 33 | uint8_t temp; 34 | 35 | Serial.begin(115200); 36 | while (!Serial) { 37 | ; // wait for serial port to connect. Needed for Leonardo only 38 | } 39 | Serial.println("ArduCAM Start!"); 40 | 41 | // Bridge startup 42 | Bridge.begin(); 43 | 44 | // Listen for incoming connection only from localhost 45 | // (no one from the external network could connect) 46 | server.listenOnLocalhost(); 47 | server.begin(); 48 | myCAM1.begin(); 49 | //Check if the ArduCAM SPI bus is OK 50 | myCAM1.write_reg(ARDUCHIP_TEST1, 0x55); 51 | temp = myCAM1.read_reg(ARDUCHIP_TEST1); 52 | if(temp != 0x55) 53 | { 54 | Serial.println("SPI1 interface Error!"); 55 | } 56 | //Check if the camera module type is OV2640 57 | myCAM1.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 58 | myCAM1.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 59 | 60 | if((vid != 0x26) || (pid != 0x42)) 61 | Serial.println("Can't find OV2640 module!"); 62 | else 63 | Serial.println("OV2640 detected"); 64 | 65 | //Change to JPEG capture mode and initialize the OV2640 module 66 | myCAM1.set_format(JPEG); 67 | myCAM1.InitCAM(); 68 | myCAM1.OV2640_set_JPEG_size(OV2640_320x240); 69 | myCAM1.clear_fifo_flag(); 70 | myCAM1.write_reg(ARDUCHIP_FRAMES,0x00); 71 | 72 | //Initialize SD Card 73 | if (! FileSystem.begin()) 74 | { 75 | Serial.println("SD Card Error!"); 76 | //while(1); 77 | } 78 | else 79 | { 80 | Serial.println("SD Card detected!"); 81 | } 82 | if(!FileSystem.exists("/mnt/sda1/arduino/"))//chick if arduino floder exist 83 | { 84 | if(FileSystem.mkdir("/mnt/sda1/arduino")) 85 | { 86 | Serial.println("Make arduino floder done."); 87 | } 88 | else 89 | { 90 | Serial.println("Make arduino floder failed!"); 91 | //while(1); 92 | } 93 | } 94 | else 95 | { 96 | Serial.println("The arduino floder is already existed."); 97 | } 98 | if(!FileSystem.exists("/mnt/sda1/DCIM/"))//chick is DCIM floder exist 99 | { 100 | if(FileSystem.mkdir("/mnt/sda1/DCIM")) 101 | { 102 | Serial.println("Make DCIM floder done."); 103 | } 104 | else 105 | { 106 | Serial.println("Make DCIM floder failed!"); 107 | //while(1); 108 | } 109 | } 110 | else 111 | { 112 | Serial.println("The DCIM floder is already existed."); 113 | } 114 | Process p; 115 | p.runShellCommand("ln -s /mnt/sda1/DCIM /www/DCIM"); 116 | p.running(); 117 | Process q; 118 | //if you use wlan, change the eth1 to wlan0 119 | q.runShellCommand("/sbin/ifconfig wlan0 | awk '/inet addr/ {print $2}' | cut -f2 -d ':'"); 120 | q.running(); 121 | m = 0; 122 | while (q.available()) 123 | { 124 | ip[m] = q.read(); 125 | m += 1; 126 | } 127 | Serial.print("IP address is "); 128 | Serial.println(ip); 129 | } 130 | 131 | void loop() 132 | { 133 | uint8_t temp,temp_last; 134 | char path[40]; 135 | byte buf[256]; 136 | 137 | 138 | // Get clients coming from server 139 | YunClient client = server.accept(); 140 | 141 | // There is a new client? 142 | if (client) 143 | { 144 | // Process request 145 | process(client); 146 | 147 | // Close connection and free resources. 148 | client.stop(); 149 | } 150 | if(capture==1) 151 | { 152 | //Clear the capture done flag 153 | myCAM1.clear_fifo_flag(); 154 | //Start capture 155 | myCAM1.start_capture(); 156 | capture=0; 157 | } 158 | if(myCAM1.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) 159 | { 160 | Serial.println("CAM1 Capture Done!"); 161 | memset(path,0,40); 162 | memset(filename,0,20); 163 | String time = gettime(); 164 | strcat(filename,time.c_str()); 165 | filename[strlen(filename)-1]=0; 166 | //Serial.println(filename); 167 | strcat(filename,".jpg"); 168 | strcat(path,"/mnt/sda1/DCIM/"); 169 | strcat(path,filename); 170 | Serial.println(path); 171 | //Open the new file 172 | File outFile = FileSystem.open(path,FILE_WRITE); 173 | if (! outFile) 174 | { 175 | Serial.println("open file failed"); 176 | myCAM1.clear_fifo_flag(); 177 | return; 178 | } 179 | 180 | temp = 0; 181 | int i=0; 182 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 183 | { 184 | temp_last = temp; 185 | temp = myCAM1.read_fifo(); 186 | if(i < 256) 187 | { 188 | buf[i] = temp; 189 | i++; 190 | } 191 | else 192 | { 193 | //Write 256 bytes image data to file 194 | outFile.write(buf,256); 195 | i = 0; 196 | buf[i] = temp; 197 | i++; 198 | } 199 | } 200 | if(i>0) 201 | outFile.write(buf,i); 202 | 203 | //Clear the capture done flag 204 | myCAM1.clear_fifo_flag(); 205 | save_done = 1; 206 | Serial.println("Save done."); 207 | } 208 | } 209 | 210 | void process(YunClient client) 211 | { 212 | // read the command 213 | String command = client.readStringUntil('/');//the url is like http ://1.1.1.1.1/command/1 214 | 215 | if (command == "capture") 216 | { 217 | capture = 1; 218 | save_done = 0; 219 | client.print(F("capture")); 220 | } 221 | else if(command == "save") 222 | { 223 | if(save_done==0) 224 | client.print("wait"); 225 | else 226 | { 227 | client.print("http://");//return the file path 228 | client.print(ip); 229 | client.print("/DCIM/"); 230 | client.print(filename); 231 | } 232 | } 233 | } 234 | 235 | String gettime() 236 | { 237 | Process ptime; 238 | String time=""; 239 | ptime.begin("date"); 240 | ptime.addParameter("+%Y%m%d%H%M%S"); 241 | ptime.run(); 242 | while(ptime.available() > 0) 243 | { 244 | char c = ptime.read(); 245 | time += c; 246 | } 247 | return time; 248 | } 249 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_MT9D111AF_Camera_Playback/ArduCAM_MT9D111AF_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Aptina MT9D111 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.1.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(MT9D111_B,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Change MCU mode 75 | myCAM.set_mode(MCU2LCD_MODE); 76 | 77 | //Initialize the LCD Module 78 | myGLCD.InitLCD(); 79 | 80 | myCAM.InitCAM(); 81 | 82 | //Initialize SD Card 83 | if (!SD.begin(SD_CS)) 84 | { 85 | //while (1); //If failed, stop here 86 | Serial.println("SD Card Error"); 87 | } 88 | else 89 | Serial.println("SD Card detected!"); 90 | } 91 | 92 | void loop() 93 | { 94 | char str[8]; 95 | unsigned long previous_time = 0; 96 | static int k = 0; 97 | uint8_t temp; 98 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 99 | 100 | while(1) 101 | { 102 | 103 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 104 | { 105 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 106 | myGLCD.resetXY(); 107 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 108 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 109 | } 110 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 111 | { 112 | previous_time = millis(); 113 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 114 | { 115 | if((millis() - previous_time) > 1500) 116 | { 117 | Playback(); 118 | } 119 | } 120 | if((millis() - previous_time) < 1500) 121 | { 122 | k = k + 1; 123 | itoa(k, str, 10); 124 | strcat(str,".bmp"); //Generate file name 125 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 126 | GrabImage(str); 127 | } 128 | } 129 | } 130 | } 131 | 132 | 133 | void GrabImage(char* str) 134 | { 135 | File outFile; 136 | char VH,VL; 137 | uint8_t temp; 138 | byte buf[256]; 139 | static int k = 0; 140 | int i,j = 0; 141 | 142 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 143 | if (! outFile) 144 | { 145 | Serial.println("Open File Error"); 146 | return; 147 | } 148 | 149 | //Switch to FIFO Mode 150 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 151 | //Flush the FIFO 152 | myCAM.flush_fifo(); 153 | //Start capture 154 | myCAM.start_capture(); 155 | Serial.println("Start Capture"); 156 | 157 | //Polling the capture done flag 158 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 159 | Serial.println("Capture Done!"); 160 | 161 | k = 0; 162 | //Write the BMP header 163 | for( i = 0; i < BMPIMAGEOFFSET; i++) 164 | { 165 | char ch = pgm_read_byte(&bmp_header[i]); 166 | buf[k++] = ch; 167 | } 168 | outFile.write(buf,k); 169 | //Read the first dummy byte 170 | myCAM.read_fifo(); 171 | 172 | k = 0; 173 | //Read 320x240x2 byte from FIFO 174 | //Save as RGB565 bmp format 175 | for(i = 0; i < 240; i++) 176 | for(j = 0; j < 320; j++) 177 | { 178 | VH = myCAM.read_fifo(); 179 | VL = myCAM.read_fifo(); 180 | buf[k++] = VL; 181 | buf[k++] = VH; 182 | //Write image data to bufer if not full 183 | if(k >= 256) 184 | { 185 | //Write 256 bytes image data to file from buffer 186 | outFile.write(buf,256); 187 | k = 0; 188 | } 189 | } 190 | //Close the file 191 | outFile.close(); 192 | //Clear the capture done flag 193 | myCAM.clear_fifo_flag(); 194 | 195 | //Switch to LCD Mode 196 | myCAM.write_reg(ARDUCHIP_TIM, 0); 197 | return; 198 | } 199 | 200 | void Playback() 201 | { 202 | File inFile; 203 | char str[8]; 204 | int k = 0; 205 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 206 | myGLCD.InitLCD(PORTRAIT); 207 | 208 | while(1) 209 | { 210 | k = k + 1; 211 | itoa(k, str, 10); 212 | strcat(str,".bmp"); 213 | inFile = SD.open(str,FILE_READ); 214 | if (! inFile) 215 | return; 216 | myGLCD.clrScr(); 217 | //myGLCD.resetXY(); 218 | dispBitmap(inFile); 219 | inFile.close(); 220 | delay(2000); 221 | } 222 | } 223 | 224 | //Only support RGB565 bmp format 225 | void dispBitmap(File inFile) 226 | { 227 | char VH,VL; 228 | int i,j = 0; 229 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 230 | inFile.read(); 231 | for(i = 0; i < 320; i++) 232 | for(j = 0; j < 240; j++) 233 | { 234 | VL = inFile.read(); 235 | //Serial.write(VL); 236 | VH = inFile.read(); 237 | //Serial.write(VH); 238 | myGLCD.LCD_Write_DATA(VH,VL); 239 | } 240 | myGLCD.clrXY(); 241 | } 242 | 243 | 244 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_MT9D111_Camera_Playback/ArduCAM_MT9D111_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Aptina MT9D111 standard camera module. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // Before use this example, please uncomment the line #define MT9D111_CAM in the memorysaver.h file. 9 | // 1. Preview the live video on LCD Screen. 10 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 11 | // 3. Store the image to Micro SD/TF card with BMP format. 12 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 13 | // This program requires the ArduCAM V3.3.0 (or above) library and Rev.C ArduCAM shield 14 | // and use Arduino IDE 1.5.8 compiler or above 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "memorysaver.h" 22 | 23 | #if defined(__arm__) 24 | #include 25 | #endif 26 | 27 | #define SD_CS 9 28 | #define BMPIMAGEOFFSET 66 29 | 30 | // set pin 10 as the slave select for the ArduCAM shield 31 | const int SPI_CS = 10; 32 | 33 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 34 | { 35 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 36 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 37 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 39 | 0x00, 0x00 40 | }; 41 | 42 | 43 | 44 | ArduCAM myCAM(MT9D111_A, SPI_CS); 45 | UTFT myGLCD(SPI_CS); 46 | 47 | void setup() 48 | { 49 | uint8_t vid, pid; 50 | uint8_t temp; 51 | 52 | #if defined (__AVR__) 53 | Wire.begin(); 54 | #endif 55 | #if defined(__arm__) 56 | Wire1.begin(); 57 | #endif 58 | Serial.begin(115200); 59 | Serial.println("ArduCAM Start!"); 60 | 61 | // set the SPI_CS as an output: 62 | pinMode(SPI_CS, OUTPUT); 63 | 64 | // initialize SPI: 65 | SPI.begin(); 66 | //Check if the ArduCAM SPI bus is OK 67 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 68 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 69 | if (temp != 0x55) 70 | { 71 | Serial.println("SPI interface Error!"); 72 | while (1); 73 | } 74 | 75 | //Change MCU mode 76 | myCAM.set_mode(MCU2LCD_MODE); 77 | 78 | //Initialize the LCD Module 79 | myGLCD.InitLCD(); 80 | 81 | myCAM.InitCAM(); 82 | 83 | //Initialize SD Card 84 | if (!SD.begin(SD_CS)) 85 | { 86 | //while (1); //If failed, stop here 87 | Serial.println("SD Card Error"); 88 | } 89 | else 90 | Serial.println("SD Card detected!"); 91 | } 92 | 93 | void loop() 94 | { 95 | char str[8]; 96 | unsigned long previous_time = 0; 97 | static int k = 0; 98 | uint8_t temp; 99 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 100 | 101 | while (1) 102 | { 103 | 104 | if (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)) //New Frame is coming 105 | { 106 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 107 | myGLCD.resetXY(); 108 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 109 | while (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)); //Wait for VSYNC is gone 110 | } 111 | else if (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 112 | { 113 | previous_time = millis(); 114 | while (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 115 | { 116 | if ((millis() - previous_time) > 1500) 117 | { 118 | Playback(); 119 | } 120 | } 121 | if ((millis() - previous_time) < 1500) 122 | { 123 | k = k + 1; 124 | itoa(k, str, 10); 125 | strcat(str, ".bmp"); //Generate file name 126 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 127 | GrabImage(str); 128 | } 129 | } 130 | } 131 | } 132 | 133 | 134 | void GrabImage(char* str) 135 | { 136 | File outFile; 137 | char VH, VL; 138 | uint8_t temp; 139 | byte buf[256]; 140 | static int k = 0; 141 | int i, j = 0; 142 | 143 | outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); 144 | if (! outFile) 145 | { 146 | Serial.println("Open File Error"); 147 | return; 148 | } 149 | 150 | //Switch to FIFO Mode 151 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 152 | //Flush the FIFO 153 | myCAM.flush_fifo(); 154 | //Start capture 155 | myCAM.start_capture(); 156 | Serial.println("Start Capture"); 157 | 158 | //Polling the capture done flag 159 | while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)); 160 | Serial.println("Capture Done!"); 161 | 162 | k = 0; 163 | //Write the BMP header 164 | for ( i = 0; i < BMPIMAGEOFFSET; i++) 165 | { 166 | char ch = pgm_read_byte(&bmp_header[i]); 167 | buf[k++] = ch; 168 | } 169 | outFile.write(buf, k); 170 | //Read the first dummy byte 171 | myCAM.read_fifo(); 172 | 173 | k = 0; 174 | //Read 320x240x2 byte from FIFO 175 | //Save as RGB565 bmp format 176 | for (i = 0; i < 240; i++) 177 | for (j = 0; j < 320; j++) 178 | { 179 | VH = myCAM.read_fifo(); 180 | VL = myCAM.read_fifo(); 181 | buf[k++] = VL; 182 | buf[k++] = VH; 183 | //Write image data to bufer if not full 184 | if (k >= 256) 185 | { 186 | //Write 256 bytes image data to file from buffer 187 | outFile.write(buf, 256); 188 | k = 0; 189 | } 190 | } 191 | //Close the file 192 | outFile.close(); 193 | //Clear the capture done flag 194 | myCAM.clear_fifo_flag(); 195 | 196 | //Switch to LCD Mode 197 | myCAM.write_reg(ARDUCHIP_TIM, 0); 198 | return; 199 | } 200 | 201 | void Playback() 202 | { 203 | File inFile; 204 | char str[8]; 205 | int k = 0; 206 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 207 | myGLCD.InitLCD(PORTRAIT); 208 | 209 | while (1) 210 | { 211 | k = k + 1; 212 | itoa(k, str, 10); 213 | strcat(str, ".bmp"); 214 | inFile = SD.open(str, FILE_READ); 215 | if (! inFile) 216 | return; 217 | myGLCD.clrScr(); 218 | //myGLCD.resetXY(); 219 | dispBitmap(inFile); 220 | inFile.close(); 221 | delay(2000); 222 | } 223 | } 224 | 225 | //Only support RGB565 bmp format 226 | void dispBitmap(File inFile) 227 | { 228 | char VH, VL; 229 | int i, j = 0; 230 | for (i = 0 ; i < BMPIMAGEOFFSET; i++) 231 | inFile.read(); 232 | for (i = 0; i < 320; i++) 233 | for (j = 0; j < 240; j++) 234 | { 235 | VL = inFile.read(); 236 | //Serial.write(VL); 237 | VH = inFile.read(); 238 | //Serial.write(VH); 239 | myGLCD.LCD_Write_DATA(VH, VL); 240 | } 241 | myGLCD.clrXY(); 242 | } 243 | 244 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_Yun_OV2640_Digital_Camera/ArduCAM_Yun_OV2640_Digital_Camera.ino.bak: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules, and run on Arduino Yun. 5 | // 6 | // This demo was made for Omnivision OV2640 2MP sensor. 7 | // It will run the ArduCAM as a real 2MP digital camera, provide both preview and JPEG capture. 8 | // The demo sketch will do the following tasks: 9 | // 1. Set the sensor to BMP preview output mode. 10 | // 2. Switch to JPEG mode when shutter buttom pressed. 11 | // 3. Capture and buffer the image to FIFO. 12 | // 4. Store the image to Micro SD/TF card with JPEG format. 13 | // 5. Resolution can be changed by myCAM.set_JPEG_size() function. 14 | // This program requires the ArduCAM V3.4.0 (or later) library and Rev.C ArduCAM shield 15 | // and use Arduino IDE 1.5.8 compiler or above 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "memorysaver.h" 24 | 25 | #define SD_CS 9 26 | // set pin 10 as the slave select for SPI: 27 | const int SPI_CS = 10; 28 | 29 | ArduCAM myCAM(OV2640,SPI_CS); 30 | UTFT myGLCD(SPI_CS); 31 | boolean isShowFlag = true; 32 | 33 | void setup() 34 | { 35 | uint8_t vid,pid; 36 | uint8_t temp; 37 | 38 | #if defined (__AVR__) 39 | Wire.begin(); 40 | #endif 41 | 42 | Serial.begin(9600); 43 | Serial.println("ArduCAM Start!"); 44 | // set the SPI_CS as an output: 45 | pinMode(SPI_CS, OUTPUT); 46 | Bridge.begin(); 47 | // initialize SPI: 48 | SPI.begin(); 49 | //Check if the ArduCAM SPI bus is OK 50 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 51 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 52 | if(temp != 0x55) 53 | { 54 | Serial.println("SPI interface Error!"); 55 | while(1); 56 | } 57 | 58 | //Change MCU mode 59 | myCAM.set_mode(MCU2LCD_MODE); 60 | 61 | myGLCD.InitLCD(); 62 | 63 | //Check if the camera module type is OV2640 64 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 65 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 66 | if((vid != 0x26) || (pid != 0x42)) 67 | Serial.println("Can't find OV2640 module!"); 68 | else 69 | Serial.println("OV2640 detected!"); 70 | 71 | //Change to BMP capture mode and initialize the OV2640 module 72 | myCAM.set_format(BMP); 73 | 74 | myCAM.InitCAM(); 75 | 76 | //Initialize SD Card 77 | if (! FileSystem.begin()) 78 | { 79 | //while (1); //If failed, stop here 80 | Serial.println("SD Card Error!"); 81 | while(1); 82 | } 83 | else 84 | { 85 | Serial.println("SD Card detected!"); 86 | } 87 | if(!FileSystem.exists("/mnt/sd/DCIM/")) 88 | { 89 | if(FileSystem.mkdir("/mnt/sd/DCIM")) 90 | { 91 | Serial.println("Make DCIM floder done."); 92 | } 93 | else 94 | { 95 | Serial.println("Make DCIM floder failed!"); 96 | while(1); 97 | } 98 | } 99 | else 100 | { 101 | Serial.println("The DCIM floder is already existed."); 102 | } 103 | } 104 | 105 | void loop() 106 | { 107 | char str[8]; 108 | char path[40]; 109 | char filename[20]; 110 | memset(path,0,40); 111 | memset(filename,0,20); 112 | byte buf[256]; 113 | static int i = 0; 114 | static int k = 0; 115 | static int n = 0; 116 | uint8_t temp,temp_last; 117 | uint8_t start_capture = 0; 118 | int total_time = 0; 119 | 120 | //Wait trigger from shutter buttom 121 | if(myCAM.get_bit(ARDUCHIP_TRIG , SHUTTER_MASK)) 122 | { 123 | isShowFlag = false; 124 | myCAM.set_mode(MCU2LCD_MODE); 125 | myCAM.set_format(JPEG); 126 | myCAM.InitCAM(); 127 | 128 | myCAM.OV2640_set_JPEG_size(OV2640_640x480); 129 | //myCAM.OV2640_set_JPEG_size(OV2640_1600x1200); 130 | //Wait until buttom released 131 | while(myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)); 132 | delay(1000); 133 | start_capture = 1; 134 | 135 | } 136 | else 137 | { 138 | if(isShowFlag ) 139 | { 140 | 141 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 142 | { 143 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 144 | myGLCD.resetXY(); 145 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 146 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 147 | } 148 | } 149 | } 150 | if(start_capture) 151 | { 152 | //Flush the FIFO 153 | myCAM.flush_fifo(); 154 | //Clear the capture done flag 155 | myCAM.clear_fifo_flag(); 156 | //Start capture 157 | myCAM.start_capture(); 158 | Serial.println("Start Capture"); 159 | } 160 | 161 | if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK) 162 | { 163 | 164 | Serial.println("Capture Done!"); 165 | String time = gettime(); 166 | strcat(filename,time.c_str()); 167 | filename[strlen(filename)-1]=0; 168 | //Serial.println(filename); 169 | strcat(filename,".jpg"); 170 | strcat(path,"/mnt/sd/DCIM/"); 171 | strcat(path,filename); 172 | Serial.println(path); 173 | //Open the new file 174 | File outFile = FileSystem.open(path,FILE_WRITE); 175 | if (! outFile) 176 | { 177 | Serial.println("open file failed"); 178 | myCAM.clear_fifo_flag(); 179 | return; 180 | } 181 | total_time = millis(); 182 | i = 0; 183 | temp = myCAM.read_fifo(); 184 | //Write first image data to buffer 185 | buf[i++] = temp; 186 | 187 | //Read JPEG data from FIFO 188 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 189 | { 190 | temp_last = temp; 191 | temp = myCAM.read_fifo(); 192 | //Write image data to buffer if not full 193 | if(i < 256) 194 | buf[i++] = temp; 195 | else 196 | { 197 | //Write 256 bytes image data to file 198 | outFile.write(buf,256); 199 | i = 0; 200 | buf[i++] = temp; 201 | } 202 | } 203 | //Write the remain bytes in the buffer 204 | if(i > 0) 205 | outFile.write(buf,i); 206 | 207 | //Close the file 208 | outFile.close(); 209 | total_time = millis() - total_time; 210 | Serial.print("Total time used:"); 211 | Serial.print(total_time, DEC); 212 | Serial.println(" millisecond"); 213 | //Clear the capture done flag 214 | myCAM.clear_fifo_flag(); 215 | //Clear the start capture flag 216 | start_capture = 0; 217 | 218 | myCAM.set_format(BMP); 219 | myCAM.InitCAM(); 220 | isShowFlag = true; 221 | } 222 | } 223 | 224 | String gettime() 225 | { 226 | Process ptime; 227 | String time=""; 228 | ptime.begin("date"); 229 | ptime.addParameter("+%Y%m%d%H%M%S"); 230 | ptime.run(); 231 | while(ptime.available() > 0) 232 | { 233 | char c = ptime.read(); 234 | time += c; 235 | } 236 | return time; 237 | } 238 | 239 | -------------------------------------------------------------------------------- /examples/mini/ArduCAM_Mini_OV5642_Yun_WebServer/ArduCAM_Mini_OV5642_Yun_WebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | In this sketch folder is a basic webpage and a copy of zepto.js, a 3 | minimized version of jQuery. When you upload your sketch, place the 4 | ArduCAMYun floder in the /arduino/www folder on your SD card.Then you can 5 | access link such as http;//arduino.local/sd/ArduCAMYun to see the basic webpage. 6 | It can control the ArduCAM to take photos. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "memorysaver.h" 18 | 19 | const int CS1 = 4; 20 | uint8_t capture = 0; 21 | uint8_t save_done = 0; 22 | char ip[16]; 23 | int m; 24 | char filename[20]; 25 | ArduCAM myCAM1(OV5642,CS1); 26 | 27 | // Listen on default port 5555, the webserver on the Yún 28 | // will forward there all the HTTP requests for us. 29 | YunServer server; 30 | 31 | void setup() 32 | { 33 | uint8_t vid,pid; 34 | uint8_t temp; 35 | 36 | Serial.begin(115200); 37 | while (!Serial) { 38 | ; // wait for serial port to connect. Needed for Leonardo only 39 | } 40 | Serial.println("ArduCAM Start!"); 41 | 42 | // Bridge startup 43 | Bridge.begin(); 44 | 45 | // Listen for incoming connection only from localhost 46 | // (no one from the external network could connect) 47 | server.listenOnLocalhost(); 48 | server.begin(); 49 | 50 | Wire.begin(); 51 | 52 | pinMode(CS1, OUTPUT); 53 | 54 | SPI.begin(); 55 | //Check if the ArduCAM SPI bus is OK 56 | myCAM1.write_reg(ARDUCHIP_TEST1, 0x55); 57 | temp = myCAM1.read_reg(ARDUCHIP_TEST1); 58 | //Serial.println(temp); 59 | if(temp != 0x55) 60 | { 61 | Serial.println("SPI1 interface Error!"); 62 | //while(1); 63 | } 64 | //Check if the camera module type is OV5642 65 | myCAM1.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); 66 | myCAM1.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); 67 | 68 | if((vid != 0x56) || (pid != 0x42)) 69 | Serial.println("Can't find OV5642 module!"); 70 | else 71 | Serial.println("OV5642 detected"); 72 | 73 | //Change to JPEG capture mode and initialize the OV2640 module 74 | myCAM1.set_format(JPEG); 75 | myCAM1.InitCAM(); 76 | myCAM1.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); 77 | 78 | myCAM1.clear_fifo_flag(); 79 | myCAM1.write_reg(ARDUCHIP_FRAMES,0x00); 80 | 81 | //Initialize SD Card 82 | if (! FileSystem.begin()) 83 | { 84 | Serial.println("SD Card Error!"); 85 | //while(1); 86 | } 87 | else 88 | { 89 | Serial.println("SD Card detected!"); 90 | } 91 | if(!FileSystem.exists("/mnt/sda1/arduino/"))//chick if arduino floder exist 92 | { 93 | if(FileSystem.mkdir("/mnt/sda1/arduino")) 94 | { 95 | Serial.println("Make arduino floder done."); 96 | } 97 | else 98 | { 99 | Serial.println("Make arduino floder failed!"); 100 | //while(1); 101 | } 102 | } 103 | else 104 | { 105 | Serial.println("The arduino floder is already existed."); 106 | } 107 | if(!FileSystem.exists("/mnt/sda1/DCIM/"))//chick is DCIM floder exist 108 | { 109 | if(FileSystem.mkdir("/mnt/sda1/DCIM")) 110 | { 111 | Serial.println("Make DCIM floder done."); 112 | } 113 | else 114 | { 115 | Serial.println("Make DCIM floder failed!"); 116 | //while(1); 117 | } 118 | } 119 | else 120 | { 121 | Serial.println("The DCIM floder is already existed."); 122 | } 123 | Process p; 124 | p.runShellCommand("ln -s /mnt/sda1/DCIM /www/DCIM"); 125 | p.running(); 126 | Process q; 127 | //if you use wlan, change the eth1 to wlan0 128 | q.runShellCommand("/sbin/ifconfig wlan0 | awk '/inet addr/ {print $2}' | cut -f2 -d ':'"); 129 | q.running(); 130 | m = 0; 131 | while (q.available()) 132 | { 133 | ip[m] = q.read(); 134 | m += 1; 135 | } 136 | Serial.print("IP address is "); 137 | Serial.println(ip); 138 | } 139 | 140 | void loop() 141 | { 142 | uint8_t temp,temp_last; 143 | char path[40]; 144 | byte buf[256]; 145 | 146 | 147 | // Get clients coming from server 148 | YunClient client = server.accept(); 149 | 150 | // There is a new client? 151 | if (client) 152 | { 153 | // Process request 154 | process(client); 155 | 156 | // Close connection and free resources. 157 | client.stop(); 158 | } 159 | if(capture==1) 160 | { 161 | //Clear the capture done flag 162 | myCAM1.clear_fifo_flag(); 163 | //Start capture 164 | myCAM1.start_capture(); 165 | capture=0; 166 | } 167 | if(myCAM1.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) 168 | { 169 | Serial.println("CAM1 Capture Done!"); 170 | memset(path,0,40); 171 | memset(filename,0,20); 172 | String time = gettime(); 173 | strcat(filename,time.c_str()); 174 | filename[strlen(filename)-1]=0; 175 | //Serial.println(filename); 176 | strcat(filename,".jpg"); 177 | strcat(path,"/mnt/sda1/DCIM/"); 178 | strcat(path,filename); 179 | Serial.println(path); 180 | //Open the new file 181 | File outFile = FileSystem.open(path,FILE_WRITE); 182 | if (! outFile) 183 | { 184 | Serial.println("open file failed"); 185 | myCAM1.clear_fifo_flag(); 186 | return; 187 | } 188 | 189 | temp = 0; 190 | int i=0; 191 | while( (temp != 0xD9) | (temp_last != 0xFF) ) 192 | { 193 | temp_last = temp; 194 | temp = myCAM1.read_fifo(); 195 | if(i < 256) 196 | { 197 | buf[i] = temp; 198 | i++; 199 | } 200 | else 201 | { 202 | //Write 256 bytes image data to file 203 | outFile.write(buf,256); 204 | i = 0; 205 | buf[i] = temp; 206 | i++; 207 | } 208 | } 209 | if(i>0) 210 | outFile.write(buf,i); 211 | 212 | //Clear the capture done flag 213 | myCAM1.clear_fifo_flag(); 214 | save_done = 1; 215 | Serial.println("Save done."); 216 | } 217 | } 218 | 219 | void process(YunClient client) 220 | { 221 | // read the command 222 | String command = client.readStringUntil('/');//the url is like http ://1.1.1.1.1/command/1 223 | 224 | if (command == "capture") 225 | { 226 | capture = 1; 227 | save_done = 0; 228 | client.print(F("capture")); 229 | } 230 | else if(command == "save") 231 | { 232 | if(save_done==0) 233 | client.print("wait"); 234 | else 235 | { 236 | client.print("http://");//return the file path 237 | client.print(ip); 238 | client.print("/DCIM/"); 239 | client.print(filename); 240 | } 241 | } 242 | } 243 | 244 | String gettime() 245 | { 246 | Process ptime; 247 | String time=""; 248 | ptime.begin("date"); 249 | ptime.addParameter("+%Y%m%d%H%M%S"); 250 | ptime.run(); 251 | while(ptime.available() > 0) 252 | { 253 | char c = ptime.read(); 254 | time += c; 255 | } 256 | return time; 257 | } 258 | 259 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV7660_Camera_Playback/ArduCAM_OV7660_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV7660 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.2.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(OV7660,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Check if the camera module type is OV7660 75 | myCAM.rdSensorReg8_8(0x0A, &vid); 76 | myCAM.rdSensorReg8_8(0x0B, &pid); 77 | if((vid != 0x76) || (pid != 0x60)) 78 | Serial.println("Can't find OV7660 module!"); 79 | else 80 | Serial.println("OV7660 detected"); 81 | 82 | //Change MCU mode 83 | myCAM.set_mode(MCU2LCD_MODE); 84 | 85 | //Initialize the LCD Module 86 | myGLCD.InitLCD(); 87 | 88 | myCAM.InitCAM(); 89 | 90 | //Initialize SD Card 91 | if (!SD.begin(SD_CS)) 92 | { 93 | //while (1); //If failed, stop here 94 | Serial.println("SD Card Error"); 95 | } 96 | else 97 | Serial.println("SD Card detected!"); 98 | } 99 | 100 | void loop() 101 | { 102 | char str[8]; 103 | unsigned long previous_time = 0; 104 | static int k = 0; 105 | uint8_t temp; 106 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 107 | 108 | while(1) 109 | { 110 | 111 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 112 | { 113 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 114 | myGLCD.resetXY(); 115 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 116 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 117 | } 118 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 119 | { 120 | previous_time = millis(); 121 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 122 | { 123 | if((millis() - previous_time) > 1500) 124 | { 125 | Playback(); 126 | } 127 | } 128 | if((millis() - previous_time) < 1500) 129 | { 130 | k = k + 1; 131 | itoa(k, str, 10); 132 | strcat(str,".bmp"); //Generate file name 133 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 134 | GrabImage(str); 135 | } 136 | } 137 | } 138 | } 139 | 140 | 141 | void GrabImage(char* str) 142 | { 143 | File outFile; 144 | char VH,VL; 145 | uint8_t temp; 146 | byte buf[256]; 147 | static int k = 0; 148 | int i,j = 0; 149 | 150 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 151 | if (! outFile) 152 | { 153 | Serial.println("Open File Error"); 154 | return; 155 | } 156 | 157 | //Switch to FIFO Mode 158 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 159 | //Flush the FIFO 160 | myCAM.flush_fifo(); 161 | //Start capture 162 | myCAM.start_capture(); 163 | Serial.println("Start Capture"); 164 | 165 | //Polling the capture done flag 166 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 167 | Serial.println("Capture Done!"); 168 | 169 | k = 0; 170 | //Write the BMP header 171 | for( i = 0; i < BMPIMAGEOFFSET; i++) 172 | { 173 | char ch = pgm_read_byte(&bmp_header[i]); 174 | buf[k++] = ch; 175 | } 176 | outFile.write(buf,k); 177 | 178 | k = 0; 179 | //Read 320x240x2 byte from FIFO 180 | //Save as RGB565 bmp format 181 | for(i = 0; i < 240; i++) 182 | for(j = 0; j < 320; j++) 183 | { 184 | VH = myCAM.read_fifo(); 185 | VL = myCAM.read_fifo(); 186 | buf[k++] = VL; 187 | buf[k++] = VH; 188 | //Write image data to bufer if not full 189 | if(k >= 256) 190 | { 191 | //Write 256 bytes image data to file from buffer 192 | outFile.write(buf,256); 193 | k = 0; 194 | } 195 | } 196 | //Close the file 197 | outFile.close(); 198 | //Clear the capture done flag 199 | myCAM.clear_fifo_flag(); 200 | 201 | //Switch to LCD Mode 202 | myCAM.write_reg(ARDUCHIP_TIM, 0); 203 | return; 204 | } 205 | 206 | void Playback() 207 | { 208 | File inFile; 209 | char str[8]; 210 | int k = 0; 211 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 212 | myGLCD.InitLCD(PORTRAIT); 213 | 214 | while(1) 215 | { 216 | k = k + 1; 217 | itoa(k, str, 10); 218 | strcat(str,".bmp"); 219 | inFile = SD.open(str,FILE_READ); 220 | if (! inFile) 221 | return; 222 | myGLCD.clrScr(); 223 | //myGLCD.resetXY(); 224 | dispBitmap(inFile); 225 | inFile.close(); 226 | delay(2000); 227 | } 228 | } 229 | 230 | //Only support RGB565 bmp format 231 | void dispBitmap(File inFile) 232 | { 233 | char VH,VL; 234 | int i,j = 0; 235 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 236 | inFile.read(); 237 | for(i = 0; i < 320; i++) 238 | for(j = 0; j < 240; j++) 239 | { 240 | VL = inFile.read(); 241 | //Serial.write(VL); 242 | VH = inFile.read(); 243 | //Serial.write(VH); 244 | myGLCD.LCD_Write_DATA(VH,VL); 245 | } 246 | myGLCD.clrXY(); 247 | } 248 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV7725_Camera_Playback/ArduCAM_OV7725_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV7725 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.2.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(OV7725,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Check if the camera module type is OV7725 75 | myCAM.rdSensorReg8_8(0x0A, &vid); 76 | myCAM.rdSensorReg8_8(0x0B, &pid); 77 | if((vid != 0x77) || (pid != 0x21)) 78 | Serial.println("Can't find OV7725 module!"); 79 | else 80 | Serial.println("OV7725 detected"); 81 | 82 | //Change MCU mode 83 | myCAM.set_mode(MCU2LCD_MODE); 84 | 85 | //Initialize the LCD Module 86 | myGLCD.InitLCD(); 87 | 88 | myCAM.InitCAM(); 89 | 90 | //Initialize SD Card 91 | if (!SD.begin(SD_CS)) 92 | { 93 | //while (1); //If failed, stop here 94 | Serial.println("SD Card Error"); 95 | } 96 | else 97 | Serial.println("SD Card detected!"); 98 | } 99 | 100 | void loop() 101 | { 102 | char str[8]; 103 | unsigned long previous_time = 0; 104 | static int k = 0; 105 | uint8_t temp; 106 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 107 | 108 | while(1) 109 | { 110 | 111 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 112 | { 113 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 114 | myGLCD.resetXY(); 115 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 116 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 117 | } 118 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 119 | { 120 | previous_time = millis(); 121 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 122 | { 123 | if((millis() - previous_time) > 1500) 124 | { 125 | Playback(); 126 | } 127 | } 128 | if((millis() - previous_time) < 1500) 129 | { 130 | k = k + 1; 131 | itoa(k, str, 10); 132 | strcat(str,".bmp"); //Generate file name 133 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 134 | GrabImage(str); 135 | } 136 | } 137 | } 138 | } 139 | 140 | 141 | void GrabImage(char* str) 142 | { 143 | File outFile; 144 | char VH,VL; 145 | uint8_t temp; 146 | byte buf[256]; 147 | static int k = 0; 148 | int i,j = 0; 149 | 150 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 151 | if (! outFile) 152 | { 153 | Serial.println("Open File Error"); 154 | return; 155 | } 156 | 157 | //Switch to FIFO Mode 158 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 159 | //Flush the FIFO 160 | myCAM.flush_fifo(); 161 | //Start capture 162 | myCAM.start_capture(); 163 | Serial.println("Start Capture"); 164 | 165 | //Polling the capture done flag 166 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 167 | Serial.println("Capture Done!"); 168 | 169 | k = 0; 170 | //Write the BMP header 171 | for( i = 0; i < BMPIMAGEOFFSET; i++) 172 | { 173 | char ch = pgm_read_byte(&bmp_header[i]); 174 | buf[k++] = ch; 175 | } 176 | outFile.write(buf,k); 177 | 178 | k = 0; 179 | //Read 320x240x2 byte from FIFO 180 | //Save as RGB565 bmp format 181 | for(i = 0; i < 240; i++) 182 | for(j = 0; j < 320; j++) 183 | { 184 | VH = myCAM.read_fifo(); 185 | VL = myCAM.read_fifo(); 186 | buf[k++] = VL; 187 | buf[k++] = VH; 188 | //Write image data to bufer if not full 189 | if(k >= 256) 190 | { 191 | //Write 256 bytes image data to file from buffer 192 | outFile.write(buf,256); 193 | k = 0; 194 | } 195 | } 196 | //Close the file 197 | outFile.close(); 198 | //Clear the capture done flag 199 | myCAM.clear_fifo_flag(); 200 | 201 | //Switch to LCD Mode 202 | myCAM.write_reg(ARDUCHIP_TIM, 0); 203 | return; 204 | } 205 | 206 | void Playback() 207 | { 208 | File inFile; 209 | char str[8]; 210 | int k = 0; 211 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 212 | myGLCD.InitLCD(PORTRAIT); 213 | 214 | while(1) 215 | { 216 | k = k + 1; 217 | itoa(k, str, 10); 218 | strcat(str,".bmp"); 219 | inFile = SD.open(str,FILE_READ); 220 | if (! inFile) 221 | return; 222 | myGLCD.clrScr(); 223 | //myGLCD.resetXY(); 224 | dispBitmap(inFile); 225 | inFile.close(); 226 | delay(2000); 227 | } 228 | } 229 | 230 | //Only support RGB565 bmp format 231 | void dispBitmap(File inFile) 232 | { 233 | char VH,VL; 234 | int i,j = 0; 235 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 236 | inFile.read(); 237 | for(i = 0; i < 320; i++) 238 | for(j = 0; j < 240; j++) 239 | { 240 | VL = inFile.read(); 241 | //Serial.write(VL); 242 | VH = inFile.read(); 243 | //Serial.write(VH); 244 | myGLCD.LCD_Write_DATA(VH,VL); 245 | } 246 | myGLCD.clrXY(); 247 | } 248 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV7725_Camera_Playback/ArduCAM_OV7725_Camera_Playback.ino.bak: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV7725 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.2.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(OV7725,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Check if the camera module type is OV7725 75 | myCAM.rdSensorReg8_8(0x0A, &vid); 76 | myCAM.rdSensorReg8_8(0x0B, &pid); 77 | if((vid != 0x77) || (pid != 0x21)) 78 | Serial.println("Can't find OV7725 module!"); 79 | else 80 | Serial.println("OV7725 detected"); 81 | 82 | //Change MCU mode 83 | myCAM.set_mode(MCU2LCD_MODE); 84 | 85 | //Initialize the LCD Module 86 | myGLCD.InitLCD(); 87 | 88 | myCAM.InitCAM(); 89 | 90 | //Initialize SD Card 91 | if (!SD.begin(SD_CS)) 92 | { 93 | //while (1); //If failed, stop here 94 | Serial.println("SD Card Error"); 95 | } 96 | else 97 | Serial.println("SD Card detected!"); 98 | } 99 | 100 | void loop() 101 | { 102 | char str[8]; 103 | unsigned long previous_time = 0; 104 | static int k = 0; 105 | uint8_t temp; 106 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 107 | 108 | while(1) 109 | { 110 | 111 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 112 | { 113 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 114 | myGLCD.resetXY(); 115 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 116 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 117 | } 118 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 119 | { 120 | previous_time = millis(); 121 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 122 | { 123 | if((millis() - previous_time) > 1500) 124 | { 125 | Playback(); 126 | } 127 | } 128 | if((millis() - previous_time) < 1500) 129 | { 130 | k = k + 1; 131 | itoa(k, str, 10); 132 | strcat(str,".bmp"); //Generate file name 133 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 134 | GrabImage(str); 135 | } 136 | } 137 | } 138 | } 139 | 140 | 141 | void GrabImage(char* str) 142 | { 143 | File outFile; 144 | char VH,VL; 145 | uint8_t temp; 146 | byte buf[256]; 147 | static int k = 0; 148 | int i,j = 0; 149 | 150 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 151 | if (! outFile) 152 | { 153 | Serial.println("Open File Error"); 154 | return; 155 | } 156 | 157 | //Switch to FIFO Mode 158 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 159 | //Flush the FIFO 160 | myCAM.flush_fifo(); 161 | //Start capture 162 | myCAM.start_capture(); 163 | Serial.println("Start Capture"); 164 | 165 | //Polling the capture done flag 166 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 167 | Serial.println("Capture Done!"); 168 | 169 | k = 0; 170 | //Write the BMP header 171 | for( i = 0; i < BMPIMAGEOFFSET; i++) 172 | { 173 | char ch = pgm_read_byte(&bmp_header[i]); 174 | buf[k++] = ch; 175 | } 176 | outFile.write(buf,k); 177 | 178 | k = 0; 179 | //Read 320x240x2 byte from FIFO 180 | //Save as RGB565 bmp format 181 | for(i = 0; i < 240; i++) 182 | for(j = 0; j < 320; j++) 183 | { 184 | VH = myCAM.read_fifo(); 185 | VL = myCAM.read_fifo(); 186 | buf[k++] = VL; 187 | buf[k++] = VH; 188 | //Write image data to bufer if not full 189 | if(k >= 256) 190 | { 191 | //Write 256 bytes image data to file from buffer 192 | outFile.write(buf,256); 193 | k = 0; 194 | } 195 | } 196 | //Close the file 197 | outFile.close(); 198 | //Clear the capture done flag 199 | myCAM.clear_fifo_flag(); 200 | 201 | //Switch to LCD Mode 202 | myCAM.write_reg(ARDUCHIP_TIM, 0); 203 | return; 204 | } 205 | 206 | void Playback() 207 | { 208 | File inFile; 209 | char str[8]; 210 | int k = 0; 211 | myCAM.write_reg(ARDUCHIP_MODE, 0x00); //Switch to MCU 212 | myGLCD.InitLCD(PORTRAIT); 213 | 214 | while(1) 215 | { 216 | k = k + 1; 217 | itoa(k, str, 10); 218 | strcat(str,".bmp"); 219 | inFile = SD.open(str,FILE_READ); 220 | if (! inFile) 221 | return; 222 | myGLCD.clrScr(); 223 | //myGLCD.resetXY(); 224 | dispBitmap(inFile); 225 | inFile.close(); 226 | delay(2000); 227 | } 228 | } 229 | 230 | //Only support RGB565 bmp format 231 | void dispBitmap(File inFile) 232 | { 233 | char VH,VL; 234 | int i,j = 0; 235 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 236 | inFile.read(); 237 | for(i = 0; i < 320; i++) 238 | for(j = 0; j < 240; j++) 239 | { 240 | VL = inFile.read(); 241 | //Serial.write(VL); 242 | VH = inFile.read(); 243 | //Serial.write(VH); 244 | myGLCD.LCD_Write_DATA(VH,VL); 245 | } 246 | myGLCD.clrXY(); 247 | } 248 | -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_MT9D112_Camera_Playback/ArduCAM_MT9D112_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Aptina MT9D112 standard camera module. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // Before use this example, please uncomment the line #define MT9D112_CAM in the memorysaver.h file. 9 | // 1. Preview the live video on LCD Screen. 10 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 11 | // 3. Store the image to Micro SD/TF card with BMP format. 12 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 13 | // This program requires the ArduCAM V3.4.7 (or above) library and Rev.C ArduCAM shield 14 | // and use Arduino IDE 1.5.8 compiler or above 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "memorysaver.h" 22 | 23 | #if defined(__arm__) 24 | #include 25 | #endif 26 | 27 | #define SD_CS 9 28 | #define BMPIMAGEOFFSET 66 29 | 30 | // set pin 10 as the slave select for the ArduCAM shield 31 | const int SPI_CS = 10; 32 | 33 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 34 | { 35 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 36 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 37 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 39 | 0x00, 0x00 40 | }; 41 | 42 | 43 | 44 | ArduCAM myCAM(MT9D112, SPI_CS); 45 | UTFT myGLCD(SPI_CS); 46 | 47 | void setup() 48 | { 49 | uint16_t vid; 50 | uint8_t temp; 51 | 52 | #if defined (__AVR__) 53 | Wire.begin(); 54 | #endif 55 | #if defined(__arm__) 56 | Wire1.begin(); 57 | #endif 58 | Serial.begin(115200); 59 | Serial.println("ArduCAM Start!"); 60 | 61 | // set the SPI_CS as an output: 62 | pinMode(SPI_CS, OUTPUT); 63 | 64 | // initialize SPI: 65 | SPI.begin(); 66 | //Check if the ArduCAM SPI bus is OK 67 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 68 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 69 | if (temp != 0x55) 70 | { 71 | Serial.println("SPI interface Error!"); 72 | while (1); 73 | } 74 | 75 | //Check if the camera module type is MT9D112 76 | myCAM.rdSensorReg16_16(0x0000, &vid); 77 | if ((vid != 0x1580)) 78 | Serial.println("Can't find MT9D112 module!"); 79 | else 80 | Serial.println("MT9D112 detected"); 81 | 82 | //Change MCU mode 83 | myCAM.set_mode(MCU2LCD_MODE); 84 | 85 | //Initialize the LCD Module 86 | myGLCD.InitLCD(); 87 | 88 | myCAM.InitCAM(); 89 | 90 | //Initialize SD Card 91 | if (!SD.begin(SD_CS)) 92 | { 93 | //while (1); //If failed, stop here 94 | Serial.println("SD Card Error"); 95 | } 96 | else 97 | Serial.println("SD Card detected!"); 98 | } 99 | 100 | void loop() 101 | { 102 | char str[8]; 103 | unsigned long previous_time = 0; 104 | static int k = 0; 105 | uint8_t temp; 106 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 107 | 108 | while (1) 109 | { 110 | 111 | if (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)) //New Frame is coming 112 | { 113 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 114 | myGLCD.resetXY(); 115 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 116 | while (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)); //Wait for VSYNC is gone 117 | } 118 | else if (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 119 | { 120 | previous_time = millis(); 121 | while (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 122 | { 123 | if ((millis() - previous_time) > 1500) 124 | { 125 | Playback(); 126 | } 127 | } 128 | if ((millis() - previous_time) < 1500) 129 | { 130 | k = k + 1; 131 | itoa(k, str, 10); 132 | strcat(str, ".bmp"); //Generate file name 133 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 134 | GrabImage(str); 135 | } 136 | } 137 | } 138 | } 139 | 140 | 141 | void GrabImage(char* str) 142 | { 143 | File outFile; 144 | char VH, VL; 145 | uint8_t temp; 146 | byte buf[256]; 147 | static int k = 0; 148 | int i, j = 0; 149 | 150 | outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); 151 | if (! outFile) 152 | { 153 | Serial.println("Open File Error"); 154 | return; 155 | } 156 | 157 | //Switch to FIFO Mode 158 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 159 | //Flush the FIFO 160 | myCAM.flush_fifo(); 161 | //Start capture 162 | myCAM.start_capture(); 163 | Serial.println("Start Capture"); 164 | 165 | //Polling the capture done flag 166 | while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)); 167 | Serial.println("Capture Done!"); 168 | 169 | k = 0; 170 | //Write the BMP header 171 | for ( i = 0; i < BMPIMAGEOFFSET; i++) 172 | { 173 | char ch = pgm_read_byte(&bmp_header[i]); 174 | buf[k++] = ch; 175 | } 176 | outFile.write(buf, k); 177 | //Read the first dummy byte 178 | //myCAM.read_fifo(); 179 | 180 | k = 0; 181 | //Read 320x240x2 byte from FIFO 182 | //Save as RGB565 bmp format 183 | for (i = 0; i < 240; i++) 184 | for (j = 0; j < 320; j++) 185 | { 186 | VH = myCAM.read_fifo(); 187 | VL = myCAM.read_fifo(); 188 | buf[k++] = VL; 189 | buf[k++] = VH; 190 | 191 | //Write image data to bufer if not full 192 | if (k >= 256) 193 | { 194 | //Write 256 bytes image data to file from buffer 195 | outFile.write(buf, 256); 196 | k = 0; 197 | } 198 | } 199 | //Close the file 200 | outFile.close(); 201 | //Clear the capture done flag 202 | myCAM.clear_fifo_flag(); 203 | 204 | //Switch to LCD Mode 205 | myCAM.write_reg(ARDUCHIP_TIM, 0); 206 | return; 207 | } 208 | 209 | void Playback() 210 | { 211 | File inFile; 212 | char str[8]; 213 | int k = 0; 214 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 215 | myGLCD.InitLCD(PORTRAIT); 216 | 217 | while (1) 218 | { 219 | k = k + 1; 220 | itoa(k, str, 10); 221 | strcat(str, ".bmp"); 222 | inFile = SD.open(str, FILE_READ); 223 | if (! inFile) 224 | return; 225 | myGLCD.clrScr(); 226 | //myGLCD.resetXY(); 227 | dispBitmap(inFile); 228 | inFile.close(); 229 | delay(2000); 230 | } 231 | } 232 | 233 | //Only support RGB565 bmp format 234 | void dispBitmap(File inFile) 235 | { 236 | char VH, VL; 237 | int i, j = 0; 238 | for (i = 0 ; i < BMPIMAGEOFFSET; i++) 239 | inFile.read(); 240 | for (i = 0; i < 320; i++) 241 | for (j = 0; j < 240; j++) 242 | { 243 | VL = inFile.read(); 244 | //Serial.write(VL); 245 | VH = inFile.read(); 246 | //Serial.write(VH); 247 | myGLCD.LCD_Write_DATA(VH, VL); 248 | } 249 | myGLCD.clrXY(); 250 | } -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_MT9T112_Camera_Playback/ArduCAM_MT9T112_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Aptina MT9T112 standard camera module. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // Before use this example, please uncomment the line #define MT9T112_CAM in the memorysaver.h file. 9 | // 1. Preview the live video on LCD Screen. 10 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 11 | // 3. Store the image to Micro SD/TF card with BMP format. 12 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 13 | // This program requires the ArduCAM V3.4.6 (or above) library and Rev.C ArduCAM shield 14 | // and use Arduino IDE 1.5.8 compiler or above 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "memorysaver.h" 22 | 23 | #if defined(__arm__) 24 | #include 25 | #endif 26 | 27 | #define SD_CS 9 28 | #define BMPIMAGEOFFSET 66 29 | 30 | // set pin 10 as the slave select for the ArduCAM shield 31 | const int SPI_CS = 10; 32 | 33 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 34 | { 35 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 36 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 37 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 39 | 0x00, 0x00 40 | }; 41 | 42 | 43 | 44 | ArduCAM myCAM(MT9T112, SPI_CS); 45 | UTFT myGLCD(SPI_CS); 46 | 47 | void setup() 48 | { 49 | uint16_t vid; 50 | uint8_t temp; 51 | 52 | #if defined (__AVR__) 53 | Wire.begin(); 54 | #endif 55 | #if defined(__arm__) 56 | Wire1.begin(); 57 | #endif 58 | Serial.begin(115200); 59 | Serial.println("ArduCAM Start!"); 60 | 61 | // set the SPI_CS as an output: 62 | pinMode(SPI_CS, OUTPUT); 63 | 64 | // initialize SPI: 65 | SPI.begin(); 66 | //Check if the ArduCAM SPI bus is OK 67 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 68 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 69 | if (temp != 0x55) 70 | { 71 | Serial.println("SPI interface Error!"); 72 | while (1); 73 | } 74 | 75 | //Check if the camera module type is MT9T112 76 | myCAM.rdSensorReg16_16(0x0000, &vid); 77 | if ((vid != 0x2682)) 78 | Serial.println("Can't find MT9T112 module!"); 79 | else 80 | Serial.println("MT9T112 detected"); 81 | 82 | //Change MCU mode 83 | myCAM.set_mode(MCU2LCD_MODE); 84 | 85 | //Initialize the LCD Module 86 | myGLCD.InitLCD(); 87 | 88 | myCAM.InitCAM(); 89 | 90 | //Initialize SD Card 91 | if (!SD.begin(SD_CS)) 92 | { 93 | //while (1); //If failed, stop here 94 | Serial.println("SD Card Error"); 95 | } 96 | else 97 | Serial.println("SD Card detected!"); 98 | } 99 | 100 | void loop() 101 | { 102 | char str[8]; 103 | unsigned long previous_time = 0; 104 | static int k = 0; 105 | uint8_t temp; 106 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 107 | 108 | while (1) 109 | { 110 | 111 | if (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)) //New Frame is coming 112 | { 113 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 114 | myGLCD.resetXY(); 115 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 116 | while (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)); //Wait for VSYNC is gone 117 | } 118 | else if (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 119 | { 120 | previous_time = millis(); 121 | while (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 122 | { 123 | if ((millis() - previous_time) > 1500) 124 | { 125 | Playback(); 126 | } 127 | } 128 | if ((millis() - previous_time) < 1500) 129 | { 130 | k = k + 1; 131 | itoa(k, str, 10); 132 | strcat(str, ".bmp"); //Generate file name 133 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 134 | GrabImage(str); 135 | } 136 | } 137 | } 138 | } 139 | 140 | 141 | void GrabImage(char* str) 142 | { 143 | File outFile; 144 | char VH, VL; 145 | uint8_t temp; 146 | byte buf[256]; 147 | static int k = 0; 148 | int i, j = 0; 149 | 150 | outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); 151 | if (! outFile) 152 | { 153 | Serial.println("Open File Error"); 154 | return; 155 | } 156 | 157 | //Switch to FIFO Mode 158 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 159 | //Flush the FIFO 160 | myCAM.flush_fifo(); 161 | //Start capture 162 | myCAM.start_capture(); 163 | Serial.println("Start Capture"); 164 | 165 | //Polling the capture done flag 166 | while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)); 167 | Serial.println("Capture Done!"); 168 | 169 | k = 0; 170 | //Write the BMP header 171 | for ( i = 0; i < BMPIMAGEOFFSET; i++) 172 | { 173 | char ch = pgm_read_byte(&bmp_header[i]); 174 | buf[k++] = ch; 175 | } 176 | outFile.write(buf, k); 177 | //Read the first dummy byte 178 | //myCAM.read_fifo(); 179 | 180 | k = 0; 181 | //Read 320x240x2 byte from FIFO 182 | //Save as RGB565 bmp format 183 | for (i = 0; i < 240; i++) 184 | for (j = 0; j < 320; j++) 185 | { 186 | VH = myCAM.read_fifo(); 187 | VL = myCAM.read_fifo(); 188 | buf[k++] = VL; 189 | buf[k++] = VH; 190 | 191 | //Write image data to bufer if not full 192 | if (k >= 256) 193 | { 194 | //Write 256 bytes image data to file from buffer 195 | outFile.write(buf, 256); 196 | k = 0; 197 | } 198 | } 199 | //Close the file 200 | outFile.close(); 201 | //Clear the capture done flag 202 | myCAM.clear_fifo_flag(); 203 | 204 | //Switch to LCD Mode 205 | myCAM.write_reg(ARDUCHIP_TIM, 0); 206 | return; 207 | } 208 | 209 | void Playback() 210 | { 211 | File inFile; 212 | char str[8]; 213 | int k = 0; 214 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 215 | myGLCD.InitLCD(PORTRAIT); 216 | 217 | while (1) 218 | { 219 | k = k + 1; 220 | itoa(k, str, 10); 221 | strcat(str, ".bmp"); 222 | inFile = SD.open(str, FILE_READ); 223 | if (! inFile) 224 | return; 225 | myGLCD.clrScr(); 226 | //myGLCD.resetXY(); 227 | dispBitmap(inFile); 228 | inFile.close(); 229 | delay(2000); 230 | } 231 | } 232 | 233 | //Only support RGB565 bmp format 234 | void dispBitmap(File inFile) 235 | { 236 | char VH, VL; 237 | int i, j = 0; 238 | for (i = 0 ; i < BMPIMAGEOFFSET; i++) 239 | inFile.read(); 240 | for (i = 0; i < 320; i++) 241 | for (j = 0; j < 240; j++) 242 | { 243 | VL = inFile.read(); 244 | //Serial.write(VL); 245 | VH = inFile.read(); 246 | //Serial.write(VH); 247 | myGLCD.LCD_Write_DATA(VH, VL); 248 | } 249 | myGLCD.clrXY(); 250 | } -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_MT9M112_Camera_Playback/ArduCAM_MT9M112_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Aptina MT9M112 standard camera module. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // Before use this example, please uncomment the line #define MT9M112_CAM in the memorysaver.h file. 9 | // 1. Preview the live video on LCD Screen. 10 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 11 | // 3. Store the image to Micro SD/TF card with BMP format. 12 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 13 | // This program requires the ArduCAM V3.4.2 (or above) library and Rev.C ArduCAM shield 14 | // and use Arduino IDE 1.5.8 compiler or above 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "memorysaver.h" 22 | 23 | #if defined(__arm__) 24 | #include 25 | #endif 26 | 27 | #define SD_CS 9 28 | #define BMPIMAGEOFFSET 66 29 | 30 | // set pin 10 as the slave select for the ArduCAM shield 31 | const int SPI_CS = 10; 32 | 33 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 34 | { 35 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 36 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 37 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 39 | 0x00, 0x00 40 | }; 41 | 42 | 43 | 44 | ArduCAM myCAM(MT9M112, SPI_CS); 45 | UTFT myGLCD(SPI_CS); 46 | 47 | void setup() 48 | { 49 | uint16_t vid; 50 | uint8_t temp; 51 | 52 | #if defined (__AVR__) 53 | Wire.begin(); 54 | #endif 55 | #if defined(__arm__) 56 | Wire1.begin(); 57 | #endif 58 | Serial.begin(115200); 59 | Serial.println("ArduCAM Start!"); 60 | 61 | // set the SPI_CS as an output: 62 | pinMode(SPI_CS, OUTPUT); 63 | 64 | // initialize SPI: 65 | SPI.begin(); 66 | //Check if the ArduCAM SPI bus is OK 67 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 68 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 69 | if (temp != 0x55) 70 | { 71 | Serial.println("SPI interface Error!"); 72 | while (1); 73 | } 74 | 75 | //Check if the camera module type is MT9M112 76 | myCAM.wrSensorReg8_16(0xf0, 0x00); 77 | myCAM.rdSensorReg8_16(0x00, &vid); 78 | if ((vid != 0x148C)) 79 | Serial.println("Can't find MT9M112 module!"); 80 | else 81 | Serial.println("MT9M112 detected"); 82 | 83 | //Change MCU mode 84 | myCAM.set_mode(MCU2LCD_MODE); 85 | 86 | //Initialize the LCD Module 87 | myGLCD.InitLCD(); 88 | 89 | myCAM.InitCAM(); 90 | 91 | //Initialize SD Card 92 | if (!SD.begin(SD_CS)) 93 | { 94 | //while (1); //If failed, stop here 95 | Serial.println("SD Card Error"); 96 | } 97 | else 98 | Serial.println("SD Card detected!"); 99 | } 100 | 101 | void loop() 102 | { 103 | char str[8]; 104 | unsigned long previous_time = 0; 105 | static int k = 0; 106 | uint8_t temp; 107 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 108 | 109 | while (1) 110 | { 111 | 112 | if (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)) //New Frame is coming 113 | { 114 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 115 | myGLCD.resetXY(); 116 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 117 | while (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)); //Wait for VSYNC is gone 118 | } 119 | else if (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 120 | { 121 | previous_time = millis(); 122 | while (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 123 | { 124 | if ((millis() - previous_time) > 1500) 125 | { 126 | Playback(); 127 | } 128 | } 129 | if ((millis() - previous_time) < 1500) 130 | { 131 | k = k + 1; 132 | itoa(k, str, 10); 133 | strcat(str, ".bmp"); //Generate file name 134 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 135 | GrabImage(str); 136 | } 137 | } 138 | } 139 | } 140 | 141 | 142 | void GrabImage(char* str) 143 | { 144 | File outFile; 145 | char VH, VL; 146 | uint8_t temp; 147 | byte buf[256]; 148 | static int k = 0; 149 | int i, j = 0; 150 | 151 | outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); 152 | if (! outFile) 153 | { 154 | Serial.println("Open File Error"); 155 | return; 156 | } 157 | 158 | //Switch to FIFO Mode 159 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 160 | //Flush the FIFO 161 | myCAM.flush_fifo(); 162 | //Start capture 163 | myCAM.start_capture(); 164 | Serial.println("Start Capture"); 165 | 166 | //Polling the capture done flag 167 | while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)); 168 | Serial.println("Capture Done!"); 169 | 170 | k = 0; 171 | //Write the BMP header 172 | for ( i = 0; i < BMPIMAGEOFFSET; i++) 173 | { 174 | char ch = pgm_read_byte(&bmp_header[i]); 175 | buf[k++] = ch; 176 | } 177 | outFile.write(buf, k); 178 | //Read the first dummy byte 179 | //myCAM.read_fifo(); 180 | 181 | k = 0; 182 | //Read 320x240x2 byte from FIFO 183 | //Save as RGB565 bmp format 184 | for (i = 0; i < 240; i++) 185 | for (j = 0; j < 320; j++) 186 | { 187 | VH = myCAM.read_fifo(); 188 | VL = myCAM.read_fifo(); 189 | buf[k++] = VL; 190 | buf[k++] = VH; 191 | 192 | //Write image data to bufer if not full 193 | if (k >= 256) 194 | { 195 | //Write 256 bytes image data to file from buffer 196 | outFile.write(buf, 256); 197 | k = 0; 198 | } 199 | } 200 | //Close the file 201 | outFile.close(); 202 | //Clear the capture done flag 203 | myCAM.clear_fifo_flag(); 204 | 205 | //Switch to LCD Mode 206 | myCAM.write_reg(ARDUCHIP_TIM, 0); 207 | return; 208 | } 209 | 210 | void Playback() 211 | { 212 | File inFile; 213 | char str[8]; 214 | int k = 0; 215 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 216 | myGLCD.InitLCD(PORTRAIT); 217 | 218 | while (1) 219 | { 220 | k = k + 1; 221 | itoa(k, str, 10); 222 | strcat(str, ".bmp"); 223 | inFile = SD.open(str, FILE_READ); 224 | if (! inFile) 225 | return; 226 | myGLCD.clrScr(); 227 | //myGLCD.resetXY(); 228 | dispBitmap(inFile); 229 | inFile.close(); 230 | delay(2000); 231 | } 232 | } 233 | 234 | //Only support RGB565 bmp format 235 | void dispBitmap(File inFile) 236 | { 237 | char VH, VL; 238 | int i, j = 0; 239 | for (i = 0 ; i < BMPIMAGEOFFSET; i++) 240 | inFile.read(); 241 | for (i = 0; i < 320; i++) 242 | for (j = 0; j < 240; j++) 243 | { 244 | VL = inFile.read(); 245 | //Serial.write(VL); 246 | VH = inFile.read(); 247 | //Serial.write(VH); 248 | myGLCD.LCD_Write_DATA(VH, VL); 249 | } 250 | myGLCD.clrXY(); 251 | } -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_MT9V111_Camera_Playback/ArduCAM_MT9V111_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2015 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Aptina MT9V111 standard camera module. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // Before use this example, please uncomment the line #define MT9V111_CAM in the memorysaver.h file. 9 | // 1. Preview the live video on LCD Screen. 10 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 11 | // 3. Store the image to Micro SD/TF card with BMP format. 12 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 13 | // This program requires the ArduCAM V3.4.3 (or above) library and Rev.C ArduCAM shield 14 | // and use Arduino IDE 1.5.8 compiler or above 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "memorysaver.h" 22 | 23 | #if defined(__arm__) 24 | #include 25 | #endif 26 | 27 | #define SD_CS 9 28 | #define BMPIMAGEOFFSET 66 29 | 30 | // set pin 10 as the slave select for the ArduCAM shield 31 | const int SPI_CS = 10; 32 | 33 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 34 | { 35 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 36 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 37 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 39 | 0x00, 0x00 40 | }; 41 | 42 | 43 | 44 | ArduCAM myCAM(MT9V111, SPI_CS); 45 | UTFT myGLCD(SPI_CS); 46 | 47 | void setup() 48 | { 49 | uint16_t vid; 50 | uint8_t temp; 51 | 52 | #if defined (__AVR__) 53 | Wire.begin(); 54 | #endif 55 | #if defined(__arm__) 56 | Wire1.begin(); 57 | #endif 58 | Serial.begin(115200); 59 | Serial.println("ArduCAM Start!"); 60 | 61 | // set the SPI_CS as an output: 62 | pinMode(SPI_CS, OUTPUT); 63 | 64 | // initialize SPI: 65 | SPI.begin(); 66 | //Check if the ArduCAM SPI bus is OK 67 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 68 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 69 | if (temp != 0x55) 70 | { 71 | Serial.println("SPI interface Error!"); 72 | while (1); 73 | } 74 | 75 | //Check if the camera module type is MT9V111 76 | myCAM.wrSensorReg8_16(0x01, 0x04); 77 | myCAM.rdSensorReg8_16(0x36, &vid); 78 | if ((vid != 0x823A)) 79 | Serial.println("Can't find MT9V111 module!"); 80 | else 81 | Serial.println("MT9V111 detected"); 82 | 83 | //Change MCU mode 84 | myCAM.set_mode(MCU2LCD_MODE); 85 | 86 | //Initialize the LCD Module 87 | myGLCD.InitLCD(); 88 | 89 | myCAM.InitCAM(); 90 | 91 | //Initialize SD Card 92 | if (!SD.begin(SD_CS)) 93 | { 94 | //while (1); //If failed, stop here 95 | Serial.println("SD Card Error"); 96 | } 97 | else 98 | Serial.println("SD Card detected!"); 99 | } 100 | 101 | void loop() 102 | { 103 | char str[8]; 104 | unsigned long previous_time = 0; 105 | static int k = 0; 106 | uint8_t temp; 107 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 108 | 109 | while (1) 110 | { 111 | 112 | if (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)) //New Frame is coming 113 | { 114 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 115 | myGLCD.resetXY(); 116 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 117 | while (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)); //Wait for VSYNC is gone 118 | } 119 | else if (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 120 | { 121 | previous_time = millis(); 122 | while (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK)) 123 | { 124 | if ((millis() - previous_time) > 1500) 125 | { 126 | Playback(); 127 | } 128 | } 129 | if ((millis() - previous_time) < 1500) 130 | { 131 | k = k + 1; 132 | itoa(k, str, 10); 133 | strcat(str, ".bmp"); //Generate file name 134 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 135 | GrabImage(str); 136 | } 137 | } 138 | } 139 | } 140 | 141 | 142 | void GrabImage(char* str) 143 | { 144 | File outFile; 145 | char VH, VL; 146 | uint8_t temp; 147 | byte buf[256]; 148 | static int k = 0; 149 | int i, j = 0; 150 | 151 | outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); 152 | if (! outFile) 153 | { 154 | Serial.println("Open File Error"); 155 | return; 156 | } 157 | 158 | //Switch to FIFO Mode 159 | myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK); 160 | //Flush the FIFO 161 | myCAM.flush_fifo(); 162 | //Start capture 163 | myCAM.start_capture(); 164 | Serial.println("Start Capture"); 165 | 166 | //Polling the capture done flag 167 | while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)); 168 | Serial.println("Capture Done!"); 169 | 170 | k = 0; 171 | //Write the BMP header 172 | for ( i = 0; i < BMPIMAGEOFFSET; i++) 173 | { 174 | char ch = pgm_read_byte(&bmp_header[i]); 175 | buf[k++] = ch; 176 | } 177 | outFile.write(buf, k); 178 | //Read the first dummy byte 179 | //myCAM.read_fifo(); 180 | 181 | k = 0; 182 | //Read 320x240x2 byte from FIFO 183 | //Save as RGB565 bmp format 184 | for (i = 0; i < 240; i++) 185 | for (j = 0; j < 320; j++) 186 | { 187 | VH = myCAM.read_fifo(); 188 | VL = myCAM.read_fifo(); 189 | buf[k++] = VL; 190 | buf[k++] = VH; 191 | 192 | //Write image data to bufer if not full 193 | if (k >= 256) 194 | { 195 | //Write 256 bytes image data to file from buffer 196 | outFile.write(buf, 256); 197 | k = 0; 198 | } 199 | } 200 | //Close the file 201 | outFile.close(); 202 | //Clear the capture done flag 203 | myCAM.clear_fifo_flag(); 204 | 205 | //Switch to LCD Mode 206 | myCAM.write_reg(ARDUCHIP_TIM, 0); 207 | return; 208 | } 209 | 210 | void Playback() 211 | { 212 | File inFile; 213 | char str[8]; 214 | int k = 0; 215 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 216 | myGLCD.InitLCD(PORTRAIT); 217 | 218 | while (1) 219 | { 220 | k = k + 1; 221 | itoa(k, str, 10); 222 | strcat(str, ".bmp"); 223 | inFile = SD.open(str, FILE_READ); 224 | if (! inFile) 225 | return; 226 | myGLCD.clrScr(); 227 | //myGLCD.resetXY(); 228 | dispBitmap(inFile); 229 | inFile.close(); 230 | delay(2000); 231 | } 232 | } 233 | 234 | //Only support RGB565 bmp format 235 | void dispBitmap(File inFile) 236 | { 237 | char VH, VL; 238 | int i, j = 0; 239 | for (i = 0 ; i < BMPIMAGEOFFSET; i++) 240 | inFile.read(); 241 | for (i = 0; i < 320; i++) 242 | for (j = 0; j < 240; j++) 243 | { 244 | VL = inFile.read(); 245 | //Serial.write(VL); 246 | VH = inFile.read(); 247 | //Serial.write(VH); 248 | myGLCD.LCD_Write_DATA(VH, VL); 249 | } 250 | myGLCD.clrXY(); 251 | } -------------------------------------------------------------------------------- /examples/REVC/ArduCAM_OV2640_Camera_Playback/ArduCAM_OV2640_Camera_Playback.ino: -------------------------------------------------------------------------------- 1 | // ArduCAM demo (C)2014 Lee 2 | // web: http://www.ArduCAM.com 3 | // This program is a demo of how to use most of the functions 4 | // of the library with a supported camera modules. 5 | // 6 | // This demo was made for Omnivision OV2640 sensor. 7 | // It will turn the ArduCAM into a real digital camera with capture and playback functions. 8 | // 1. Preview the live video on LCD Screen. 9 | // 2. Capture and buffer the image to FIFO when shutter pressed quickly. 10 | // 3. Store the image to Micro SD/TF card with BMP format. 11 | // 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds. 12 | // This program requires the ArduCAM V3.1.0 (or above) library and Rev.C ArduCAM shield 13 | // and use Arduino IDE 1.5.2 compiler or above 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "memorysaver.h" 21 | 22 | #if defined(__arm__) 23 | #include 24 | #endif 25 | 26 | #define SD_CS 9 27 | #define BMPIMAGEOFFSET 66 28 | 29 | // set pin 10 as the slave select for the ArduCAM shield 30 | const int SPI_CS = 10; 31 | 32 | const char bmp_header[BMPIMAGEOFFSET] PROGMEM = 33 | { 34 | 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 35 | 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 36 | 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 38 | 0x00, 0x00 39 | }; 40 | 41 | 42 | 43 | ArduCAM myCAM(OV2640,SPI_CS); 44 | UTFT myGLCD(SPI_CS); 45 | 46 | void setup() 47 | { 48 | uint8_t vid,pid; 49 | uint8_t temp; 50 | 51 | #if defined (__AVR__) 52 | Wire.begin(); 53 | #endif 54 | #if defined(__arm__) 55 | Wire1.begin(); 56 | #endif 57 | Serial.begin(115200); 58 | Serial.println("ArduCAM Start!"); 59 | 60 | // set the SPI_CS as an output: 61 | pinMode(SPI_CS, OUTPUT); 62 | 63 | // initialize SPI: 64 | SPI.begin(); 65 | //Check if the ArduCAM SPI bus is OK 66 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); 67 | temp = myCAM.read_reg(ARDUCHIP_TEST1); 68 | if(temp != 0x55) 69 | { 70 | Serial.println("SPI interface Error!"); 71 | while(1); 72 | } 73 | 74 | //Change MCU mode 75 | myCAM.set_mode(MCU2LCD_MODE); 76 | 77 | //Initialize the LCD Module 78 | myGLCD.InitLCD(); 79 | 80 | //Check if the camera module type is OV2640 81 | myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); 82 | myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); 83 | if((vid != 0x26) || (pid != 0x42)) 84 | Serial.println("Can't find OV2640 module!"); 85 | else 86 | Serial.println("OV2640 detected"); 87 | 88 | //Change to BMP capture mode and initialize the OV2640 module 89 | myCAM.set_format(BMP); 90 | myCAM.InitCAM(); 91 | 92 | //Initialize SD Card 93 | if (!SD.begin(SD_CS)) 94 | { 95 | //while (1); //If failed, stop here 96 | Serial.println("SD Card Error"); 97 | } 98 | else 99 | Serial.println("SD Card detected!"); 100 | } 101 | 102 | void loop() 103 | { 104 | char str[8]; 105 | unsigned long previous_time = 0; 106 | static int k = 0; 107 | uint8_t temp; 108 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 109 | 110 | while(1) 111 | { 112 | 113 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming 114 | { 115 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 116 | myGLCD.resetXY(); 117 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM 118 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone 119 | } 120 | else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 121 | { 122 | previous_time = millis(); 123 | while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK)) 124 | { 125 | if((millis() - previous_time) > 1500) 126 | { 127 | Playback(); 128 | } 129 | } 130 | if((millis() - previous_time) < 1500) 131 | { 132 | k = k + 1; 133 | itoa(k, str, 10); 134 | strcat(str,".bmp"); //Generate file name 135 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU, freeze the screen 136 | GrabImage(str); 137 | } 138 | } 139 | } 140 | } 141 | 142 | 143 | void GrabImage(char* str) 144 | { 145 | File outFile; 146 | char VH,VL; 147 | uint8_t temp; 148 | byte buf[256]; 149 | static int k = 0; 150 | int i,j = 0; 151 | 152 | outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC); 153 | if (! outFile) 154 | { 155 | Serial.println("Open File Error"); 156 | return; 157 | } 158 | 159 | //Switch to FIFO Mode 160 | myCAM.set_bit(ARDUCHIP_TIM, MODE_MASK); 161 | //Flush the FIFO 162 | myCAM.flush_fifo(); 163 | //Start capture 164 | myCAM.start_capture(); 165 | Serial.println("Start Capture"); 166 | 167 | //Polling the capture done flag 168 | while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)); 169 | Serial.println("Capture Done!"); 170 | 171 | k = 0; 172 | //Write the BMP header 173 | for( i = 0; i < BMPIMAGEOFFSET; i++) 174 | { 175 | char ch = pgm_read_byte(&bmp_header[i]); 176 | buf[k++] = ch; 177 | } 178 | outFile.write(buf,k); 179 | 180 | k = 0; 181 | //Read 320x240x2 byte from FIFO 182 | //Save as RGB565 bmp format 183 | for(i = 0; i < 240; i++) 184 | for(j = 0; j < 320; j++) 185 | { 186 | VH = myCAM.read_fifo(); 187 | VL = myCAM.read_fifo(); 188 | buf[k++] = VL; 189 | buf[k++] = VH; 190 | //Write image data to bufer if not full 191 | if(k >= 256) 192 | { 193 | //Write 256 bytes image data to file from buffer 194 | outFile.write(buf,256); 195 | k = 0; 196 | } 197 | } 198 | //Close the file 199 | outFile.close(); 200 | //Clear the capture done flag 201 | myCAM.clear_fifo_flag(); 202 | 203 | //Switch to LCD Mode 204 | myCAM.clear_bit(ARDUCHIP_TIM, MODE_MASK); 205 | return; 206 | } 207 | 208 | void Playback() 209 | { 210 | File inFile; 211 | char str[8]; 212 | int k = 0; 213 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU 214 | myGLCD.InitLCD(PORTRAIT); 215 | 216 | while(1) 217 | { 218 | k = k + 1; 219 | itoa(k, str, 10); 220 | strcat(str,".bmp"); 221 | inFile = SD.open(str,FILE_READ); 222 | if (! inFile) 223 | return; 224 | myGLCD.clrScr(); 225 | //myGLCD.resetXY(); 226 | dispBitmap(inFile); 227 | inFile.close(); 228 | delay(2000); 229 | } 230 | } 231 | 232 | //Only support RGB565 bmp format 233 | void dispBitmap(File inFile) 234 | { 235 | char VH,VL; 236 | int i,j = 0; 237 | for(i = 0 ;i < BMPIMAGEOFFSET; i++) 238 | inFile.read(); 239 | for(i = 0; i < 320; i++) 240 | for(j = 0; j < 240; j++) 241 | { 242 | VL = inFile.read(); 243 | //Serial.write(VL); 244 | VH = inFile.read(); 245 | //Serial.write(VH); 246 | myGLCD.LCD_Write_DATA(VH,VL); 247 | } 248 | myGLCD.clrXY(); 249 | } 250 | 251 | --------------------------------------------------------------------------------