This is a test program for Camera Module(C328, LJ-DSC02)

Dependencies:   CameraC328 SDFileSystem mbed-src

Fork of Camera_TestProgram_2015 by Ricky Kwon

Prerequisite

This example stores the image data acquired from the camera on a micro sd card.

To implement this function, you need a Platform board, camera module.

Available camera modules are C328, LJ-DSC02. Because the cameras listed above all have similar internal protocols.

This example uses LJ-DSC02.

  • WIZwiki-W7500 from WIZnet (Platform board)
  • LJ-DSC02 (Camera module)
  • Micro SD Card

Hardware Configuration

/media/uploads/Ricky_Kwon/camera.png

  • connect Camera module

Software

Init resolution and frame of image

#define USE_JPEG_HIGH_RESOLUTION  1
static const int CAPTURE_FRAMES = 1;

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Fri Oct 10 21:48:33 2014 +0000
Child:
1:7e547bf0f166
Commit message:
The initial version of the test program.

Changed in this revision

Camera_LS_Y201.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201.lib	Fri Oct 10 21:48:33 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/shintamainjp/code/Camera_LS_Y201/#43358d40f879
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Fri Oct 10 21:48:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/mbed/code/SDFileSystem/#7b35d1709458
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 10 21:48:33 2014 +0000
@@ -0,0 +1,123 @@
+#include "mbed.h"
+#include "Camera_LS_Y201.h"
+#include "SDFileSystem.h"
+ 
+#define DEBMSG      printf
+#define NEWLINE()   printf("\r\n")
+ 
+#define USE_SDCARD 0
+ 
+#if USE_SDCARD
+#define FILENAME    "/sd/IMG_%04d.jpg"
+SDFileSystem fs(p5, p6, p7, p8, "sd");
+#else
+#define FILENAME    "/local/IMG_%04d.jpg"
+LocalFileSystem fs("local");
+#endif
+Camera_LS_Y201 cam1(p13, p14);
+ 
+typedef struct work {
+    FILE *fp;
+} work_t;
+ 
+work_t work;
+ 
+/**
+ * Callback function for readJpegFileContent.
+ *
+ * @param buf A pointer to a buffer.
+ * @param siz A size of the buffer.
+ */
+void callback_func(int done, int total, uint8_t *buf, size_t siz) {
+    fwrite(buf, siz, 1, work.fp);
+ 
+    static int n = 0;
+    int tmp = done * 100 / total;
+    if (n != tmp) {
+        n = tmp;
+        DEBMSG("Writing...: %3d%%", n);
+        NEWLINE();
+    }
+}
+ 
+/**
+ * Capture.
+ *
+ * @param cam A pointer to a camera object.
+ * @param filename The file name.
+ *
+ * @return Return 0 if it succeed.
+ */
+int capture(Camera_LS_Y201 *cam, char *filename) {
+    /*
+     * Take a picture.
+     */
+    if (cam->takePicture() != 0) {
+        return -1;
+    }
+    DEBMSG("Captured.");
+    NEWLINE();
+ 
+    /*
+     * Open file.
+     */
+    work.fp = fopen(filename, "wb");
+    if (work.fp == NULL) {
+        return -2;
+    }
+ 
+    /*
+     * Read the content.
+     */
+    DEBMSG("%s", filename);
+    NEWLINE();
+    if (cam->readJpegFileContent(callback_func) != 0) {
+        fclose(work.fp);
+        return -3;
+    }
+    fclose(work.fp);
+ 
+    /*
+     * Stop taking pictures.
+     */
+    cam->stopTakingPictures();
+ 
+    return 0;
+}
+ 
+/**
+ * Entry point.
+ */
+int main(void) {
+    DEBMSG("Camera module");
+    NEWLINE();
+    DEBMSG("Resetting...");
+    NEWLINE();
+    wait(1);
+ 
+    if (cam1.reset() == 0) {
+        DEBMSG("Reset OK.");
+        NEWLINE();
+    } else {
+        DEBMSG("Reset fail.");
+        NEWLINE();
+        error("Reset fail.");
+    }
+    wait(1);
+ 
+    int cnt = 0;
+    while (1) {
+        char fname[64];
+        snprintf(fname, sizeof(fname) - 1, FILENAME, cnt);
+        int r = capture(&cam1, fname);
+        if (r == 0) {
+            DEBMSG("[%04d]:OK.", cnt);
+            NEWLINE();
+        } else {
+            DEBMSG("[%04d]:NG. (code=%d)", cnt, r);
+            NEWLINE();
+            error("Failure.");
+        }
+        cnt++;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 10 21:48:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file