[vc_row][vc_column width=”1/1″][vc_column_text]LS-Y201-2MP is LinkSprite’s new generation high resolution serial port camera module. Its resolution is 2 million pixel. It can captures high resolution pictures using the serial port. LS-Y201-2MP is a modular design that outputs JPEG images through UART, and can be easily integrated into existing design.
This tutorial shows how to use this 2MP JPEG camera on Arduino.
[/vc_column_text][vc_tour][vc_tab title=”Specification ” tab_id=”1394579405-1-55″][vc_column_text]
- Number of pixels: 2 million
- Interface: UART (defaults with 115200)
- Working voltage: 5VDC
- Working Current:80-100MA
- Dimension:32mm x 32mm
[/vc_column_text][/vc_tab][vc_tab title=”Parts List” tab_id=”1394579405-2-79″][vc_column_text]
- 1 x Arduino UNO
- 1 x 2M_TTL_Camera
- 1 x SD Card Breakout Board
- 1 x SD card
- Several jumper wires
[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1394579697038-2-3″][vc_column_text](1)SD Card Breakout Board:
- MOSI of SD card breakout –> D11 of Arduino
- MISO of SD card breakout –> D12 of Arduino
- SCK of SD card breakout –> D13 of Arduino
- CS of SD card breakout –> D4 of Arduino
- VCC of SD card breakout –> 5v of Arduino
(2)2M_TTL_Camera:
- RXD of 2MP JPEG camera –> D6 of Arduino
- TXD of 2MP JPEG camera –> D5 of Arduino
- VCC of 2MP JPEG camera –> 5v of Arduino
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1394579835649-3-9″][vc_column_text]
//******************************************************* // 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; long int j=0,k=0,count=0,i=0x0000; uint8_t MH,ML; boolean EndFlag=0; File myFile; void SendResetCmd() { 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 /************************************/ void SetImageSizeCmd(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 /*************************************/ void SetBaudRateCmd(byte baudrate) { mySerial.write(0x56); mySerial.write(ZERO); mySerial.write(0x24); mySerial.write(0x03); mySerial.write(0x01); mySerial.write(baudrate); } void SendTakePhotoCmd() { mySerial.write(0x56); mySerial.write(ZERO); mySerial.write(0x36); mySerial.write(0x01); mySerial.write(ZERO); } void SendReadDataCmd() { 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; } void StopTakePhotoCmd() { mySerial.write(0x56); mySerial.write(ZERO); mySerial.write(0x36); mySerial.write(0x01); mySerial.write(0x03); } void setup() { 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); } void loop() { byte a[32]; int ii; 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); }
[/vc_column_text][/vc_tab][vc_tab title=”Test” tab_id=”1394579887023-4-2″][vc_column_text]Connect everything according to the wire diagram:
Launch Arduino IDE, copy and paste the sample code, compile and run the code. Open the serial monitor at the same time:
After we hit the load button, the serial port will begin to print out hex numbers. When it outputs “Finish writing data to file’, it means that the image is stored into the SD card.
Note: The data should begin with ‘FF D8’ and ends with ‘FF D9’. Otherwise, it means that data is corrupted, and the jpeg file is not valid.
Take the SD card from the SD breakout board and insert into a computer, we can see the newly captured picture:
[/vc_column_text][/vc_tab][vc_tab title=”Examples of Captured Pictures” tab_id=”1394580300815-5-4″][vc_column_text]
[/vc_column_text][/vc_tab][vc_tab title=”Update” tab_id=”1415579438830-6-0″][vc_column_text]Some users have difficulty with 1600×1200. We updated the sample code so that it works with 1600×1200:
//******************************************************* // 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; long int j=0,k=0,count=0,i=0x0000; uint8_t MH,ML; boolean EndFlag=0; File myFile; void SendResetCmd() { 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 /************************************/ void SetImageSizeCmd(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 /*************************************/ void SetBaudRateCmd(byte baudrate) { mySerial.write(0x56); mySerial.write(ZERO); mySerial.write(0x24); mySerial.write(0x03); mySerial.write(0x01); mySerial.write(baudrate); } void SendTakePhotoCmd() { mySerial.write(0x56); mySerial.write(ZERO); mySerial.write(0x36); mySerial.write(0x01); mySerial.write(ZERO); } void SendReadDataCmd() { 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; } void StopTakePhotoCmd() { mySerial.write(0x56); mySerial.write(ZERO); mySerial.write(0x36); mySerial.write(0x01); mySerial.write(0x03); } void setup() { Serial.begin(115200); 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. if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); Serial.println("please waiting ...."); } void loop() { byte a[32]; int ii; mySerial.begin(115200); delay(200); SendResetCmd();//Wait 2-3 second to send take picture command delay(2000); SetBaudRateCmd(0x2A); delay(100); mySerial.begin(38400); delay(100); SetImageSizeCmd(0x21); delay(100); SendTakePhotoCmd(); delay(3000); while(mySerial.available()>0) { incomingbyte=mySerial.read(); } myFile = SD.open("pic.jpg", FILE_WRITE); //<strong><span style="color: #ff0000;">The file name should not be too long</span></strong> while(!EndFlag) { j=0; k=0; count=0; SendReadDataCmd(); delay(5); while(mySerial.available()>0) { incomingbyte=mySerial.read(); k++; delayMicroseconds(100); 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); }
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
September 1, 2014 at 2:42 pm
What frame rate do you get from the camera, using the Arduino board ?
I’m tempted to try one of these cameras for a project I have in mind with an Arduino compatible board, but I’ll probably need about 5 fps
Thanks,
Gary.
October 10, 2014 at 10:34 pm
I have a camera like this tutorial, but it does nothing and no communication Reproduce the way and I can not answer me, you can do tests to find out if it works or not since I just do not get me unpack and respond, to the terminal to read the com port only initializes the SD but everything else leave it blank I hope I can help
Greetings
October 12, 2014 at 2:37 am
i was trying to run LS Y201 module using mbed LPC1768, i followed the commands in the datasheet but it did not work. is there any idea to solve my problem?