Linksprite 2M TTL Camera For Arduino

酸酸苹果汁 发布于 2014/03/12 14:53
阅读 1K+
收藏 0

图片1

LS-Y201-2MPLinkSprite分辨率为200万像素串口摄像头模块。LS-Y201-2MP是模块化设计,通过UART输出JPEG图像,并可以很容易地集成到现有的设计上。

产品特点

  • 像素大小:200万像素
  • 通讯方式:UART(默认波特率115200) 
  • 工作电压:5VDC
  • 工作电流:80-100MA  
  • 尺寸大小:32mm x 32mm 
硬件清单

  • Arduino UNO                       x1
  • 2M_TTL_Camera                x1
  • SD Card Breakout Board   x1
  • SD卡                   x1
  • 导线若干
接线说明

(1)SD Card Breakout Board

  • MOSI  –>  D11
  • MISO  –>  D12
  • SCK   –>  D13
  • CS     –>  D4
  • VCC   –>  5v

(2)2M_TTL_Camera

  • RXD –> D6
  • TXD –> D5
  • VCC –> 5v

图片2

测试代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//*******************************************************
//              www.linksprite.com
// Note:
// 1. SD must be formated to FAT16
// 2. As the buffer of softserial has 64 bytes,
//    so the code read 32 bytes each time
// 3. Please add the libaray to the lib path
//
// * SD card attached to SPI bus as follows:
// * MOSI - pin 11
// * MISO - pin 12
// * CLK - pin 13
// * CS - pin 4
//*******************************************************
#include<SoftwareSerial.h>
#include<SPI.h>
#include<SD.h>
 
SoftwareSerial mySerial(5,6);         // Set Arduino pin 4 and 5 as softserial
 
byte ZERO =0x00;
byte incomingbyte;
longintj=0,k=0,count=0,i=0x0000;
uint8_t MH,ML;
boolean EndFlag=0;
File  myFile;
 
voidSendResetCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x26);
    mySerial.write(ZERO);
}
 
/*************************************/
/* Set ImageSize :
/* <1> 0x22 : 160*120
/* <2> 0x11 : 320*240
/* <3> 0x00 : 640*480
/* <4> 0x1D : 800*600
/* <5> 0x1C : 1024*768
/* <6> 0x1B : 1280*960
/* <7> 0x21 : 1600*1200
/************************************/
voidSetImageSizeCmd(byte Size)
{
    mySerial.write(0x56);
    mySerial.write(ZERO);  
    mySerial.write(0x54);
    mySerial.write(0x01);
    mySerial.write(Size);
}
 
/*************************************/
/* Set BaudRate :
/* <1>¡¡0xAE  :   9600
/* <2>¡¡0x2A  :   38400
/* <3>¡¡0x1C  :   57600
/* <4>¡¡0x0D  :   115200
/* <5>¡¡0xAE  :   128000
/* <6>¡¡0x56  :   256000
/*************************************/
voidSetBaudRateCmd(byte baudrate)
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x24);
    mySerial.write(0x03);
    mySerial.write(0x01);
    mySerial.write(baudrate);
}
 
voidSendTakePhotoCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x36);
    mySerial.write(0x01);
    mySerial.write(ZERO); 
}
 
voidSendReadDataCmd()
{
    MH=i/0x100;
    ML=i%0x100;
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x32);
    mySerial.write(0x0c);
    mySerial.write(ZERO);
    mySerial.write(0x0a);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(MH);
    mySerial.write(ML);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(0x20);
    mySerial.write(ZERO);
    mySerial.write(0x0a);
    i+=0x20;
}
 
voidStopTakePhotoCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x36);
    mySerial.write(0x01);
    mySerial.write(0x03);
}
 
voidsetup()
{
    Serial.begin(38400);
    while(!Serial)
    {
        ;// wait for serial port to connect. Needed for Leonardo only
    }
 
    Serial.print("Initializing SD card...");
    // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
    // Note that even if it's not used as the CS pin, the hardware SS pin
    // (10 on most Arduino boards, 53 on the Mega) must be left as an output
    // or the SD library functions will not work.
    pinMode(10, OUTPUT);
    if(!SD.begin(4))
    {
        Serial.println("initialization failed!");
        return;
    }
    Serial.println("initialization done.");
    Serial.println("please waiting ....");
 
    mySerial.begin(115200);
    delay(100);
    SendResetCmd();
    delay(2000);
    SetBaudRateCmd(0x2A);
    delay(500);
    mySerial.begin(38400);
    delay(100);
}
 
voidloop()
{
    byte a[32];
    intii;
 
    SendResetCmd();
    delay(2000);                           //Wait 2-3 second to send take picture command
    SendTakePhotoCmd();
    delay(1000);
    while(mySerial.available()>0)
    {
        incomingbyte=mySerial.read();
    }
 
    myFile = SD.open("pic.jpg", FILE_WRITE);//The file name should not be too long
 
    while(!EndFlag)
    {
        j=0;
        k=0;
        count=0;
        //mySerial.flush();
        SendReadDataCmd();
        delay(20);
        while(mySerial.available()>0)
        {
            incomingbyte=mySerial.read();
            k++;
            delay(1);//250 for regular
            if((k>5)&&(j<32)&&(!EndFlag))
            {
                a[j]=incomingbyte;
                if((a[j-1]==0xFF)&&(a[j]==0xD9))    //tell if the picture is finished
                {
                    EndFlag=1;
                }
                j++;
                count++;
            }
        }
 
        for(j=0;j<count;j++)
        {
            if(a[j]<0x10)  Serial.print("0");
            Serial.print(a[j],HEX);          // observe the image through serial port
            Serial.print(" ");
        }
 
        for(ii=0; ii<count; ii++)
        myFile.write(a[ii]);
        Serial.println();
    }
 
    myFile.close();
    Serial.print("Finished writing data to file");
    while(1);
}
测试运行

(1)按照接线图接线:

图片3

(2)打开arduino IDE,输入测试代码,编译下载,并打开串口监视器:

图片4

(3)此时串口会打印许多十六进制的数据,当串口打印出”Finisher writing dara to file”,表示数据已经写入到SD卡中:(注意数据的开始应为FF D8,结尾为FF D9,若不是以FF D8开始,则数据丢失,保存的图片将不能正常打开

图片5

图片6

(4)将SD卡插到电脑上打开文件夹,就可以看到刚刚拍摄的照片PIC.JPG

图片7

效果显示


图片9

图片8



linksprite学习中心

加载中
0
Stormer
Stormer

非常感谢您分享的教程!对我有很大的帮助~~

我现在有两个问题,不知道您可以解答一下吗?

1:SetImageSizeCmd 这个函数应该放在什么位置?

2:这个摄像头模块是否可以设置拍照的具体参数,比如快门、光圈、ISO之类的。


返回顶部
顶部