Jump to content
Sign in to follow this  
sam-r-91

LinkSprite JPEG Color Camera TTL Interface - 2MP problems

Recommended Posts

I am using the following camera: https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/JPEG%20camera%202M%20UM.pdf

with an arduino due and a SD card shield. My aim is to get the camera to take a picture and to save it on the SD card and also see the "output" on the Serial Monitor.  I am having a bit of trouble, and i'm not sure where i am going wrong, at the moment it has no errors, but there are only blank jpeg files on the SD card. It says that they don't contain anything. Could anyone point me to the section of code which needs work on, i'm assuming it is either the commands (which i have checked against the data sheet) or the transfer of bytes.

 

I am following this tutorial:

http://learn.linksprite.com/jpeg-camera/use-linksprite-jpeg-camera-to-take-picture-and-store-to-a-sd-card/

I have changed a few things, taken out soft serial and used the hard serial on my DUE. Added in SPI.h as i am using a SD shield. 

Here is the code:



#include <SD.h>
#include <SPI.h> 
 
byte ZERO = 0x00;
 
byte incomingbyte;         
 
long int a=0x0000,j=0,k=0,count=0,i=0;
uint8_t MH,ML;
boolean EndFlag=0;
 
File  myFile;
 
void SendResetCmd();
void SetBaudRateCmd();
void SetImageSizeCmd();
void SendTakePhotoCmd();
void SendReadDataCmd();
void StopTakePhotoCmd();
 
void setup()
{
 
Serial.begin(38400);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
 
Serial1.begin(38400);
 
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.");
 
}
 
void loop()
{
 
byte a[32];
int ii;
 
SendResetCmd();
delay(4000);                            //Wait 2-3 second to send take picture command
 
SendTakePhotoCmd();
 
while(Serial1.available()>0)
{
incomingbyte=Serial1.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(20); //250 for regular
 
while(Serial1.available()>0)
{
incomingbyte=Serial1.read();
k++;
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();
 
i++;
 
}
 
myFile.close();
 
Serial.print("Finished writing data to file");
 
while(1);
 
}
 
void SendResetCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x26);
Serial1.write(ZERO);
}
 
void SetImageSizeCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x31);
Serial1.write(0x05);
Serial1.write(0x04);
Serial1.write(0x01);
Serial1.write(ZERO);
Serial1.write(0x19);
Serial1.write(0x11);
}
 
void SetBaudRateCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x24);
Serial1.write(0x03);
Serial1.write(0x01);
Serial1.write(0x2A);
Serial1.write(0xC8);
 
}
 
void SendTakePhotoCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x36);
Serial1.write(0x01);
Serial1.write(ZERO);
}
 
void SendReadDataCmd()
{
MH=a/0x100;
ML=a%0x100;
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x32);
Serial1.write(0x0c);
Serial1.write(ZERO);
Serial1.write(0x0a);
Serial1.write(ZERO);
Serial1.write(ZERO);
Serial1.write(MH);
Serial1.write(ML);
Serial1.write(ZERO);
Serial1.write(ZERO);
Serial1.write(ZERO);
Serial1.write(0x20);
Serial1.write(ZERO);
Serial1.write(0x0a);
a+=0x20;
}
 
void StopTakePhotoCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x36);
Serial1.write(0x01);
Serial1.write(0x03);
}

This is what i get in my serial monitor:

$�
`��%���)��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������$�
`��%��������������������������������������������������������


On the SD card it does make a file but it is empty. I was expecting HEX in my serial monitor but all i get are these question marks? Why is this?

Share this post


Link to post
Share on other sites

I am using Arduino UNO as well and I get empty data from the camera.  Ive seen many posts about this but linksprite admins dont seem to have an explanation, much less a solution to this very common issue.  Do you guys know what is going on?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×