You are viewing an older revision! See the latest version

Camera_LS_Y201

Overview

http://mbed.org/media/uploads/shintamainjp/ls_y201_overview.png

You can get this camera from SparkFun. http://www.sparkfun.com/products/10061

DataSheet

The document is not so good. There are so many bugs in it. So please check the camera protocols with my library sources. http://www.sparkfun.com/datasheets/Sensors/Imaging/1274419957.pdf

Connection

Here is the connection of the sample program.

You can change the PinName at the constructor.

  • mbed to LS-Y201
  • p13(TX) to RxD
  • p14(RX) to TxD

http://mbed.org/media/uploads/shintamainjp/_scaled_dsc04198.jpg

Library

Test program

#include "mbed.h"
#include "Camera_LS_Y201.h"
#include "SDFileSystem.h"

SDFileSystem fs_sd(p5, p6, p7, p8, "sd");
Camera_LS_Y201 cam1(p13, p14);

FILE *fp = NULL;
int datcnt = 0;

/**
 * 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, fp);

    static int n = 0;
    int tmp = done * 100 / total;
    if (n != tmp) {
        n = tmp;
        // You can print the progress to LCD here.
    }
}

int capture(int n) {
    /*
     * Take a picture.(L)
     */
    if (cam1.takePicture() != 0) {
        return -1;
    }
    lcd.locate(0, 1);
    lcd.printf("Captured.");

    char fname[64];
    
    /*
     * Open file.
     * Read the content.
     */
    snprintf(fname, sizeof(fname) - 1, "/sd/IMG_%04d.jpg", n);
    fp = fopen(fname, "wb");
    if (fp == NULL) {
        return -2;
    }
    lcd.locate(0, 0);
    lcd.printf("Capture: %04d", n);
    datcnt = 0;
    if (cam1.readJpegFileContent(callback_func) != 0) {
        fclose(fp);
        return -3;
    }
    fclose(fp);

    /*
     * Stop taking pictures.
     */
    cam1.stopTakingPictures();

    return 0;
}

/**
 * Entry point.
 */
int main(void) {
    wait(1);

    if (cam1.reset() == 0) {
        printf("Reset OK.   ");
    }
    wait(1);

    int cnt = 0;
    // for (int i = 0; i < 10; i++) {
    while (1) {
        int r = capture(cnt);
        if (r == 0) {
            printf("[%04d]:OK.\n", cnt);
        } else {
            printf("[%04d]:NG. (code=%d)\n", cnt, r);
        }
        cnt++;
    }

    return 0;
}

The output

http://mbed.org/media/uploads/shintamainjp/test.jpg


All wikipages