Jump to content
quique

JPEG Camera returning 00 bytes

Recommended Posts

Hi,

 

I bought this linksprite camera here:

 

http://www.tinyosshop.com/index.php?route=product/product&filter_name=jpeg&filter_description=true&filter_sub_category=true&product_id=586

 

There is a tutorial for it on this page which links to a sketch like this:

/* Linksprite */
//SPITS OUT WHITE SCREEN SERIAL MONITOR SCROLLING DOWN BUT NO DATA SAVED TO SD
// could white spaces on monitor be the data?  if i let it run then it should show up as an image on sd car

#include <SoftwareSerial.h>

byte incomingbyte;
SoftwareSerial mySerial(4,5);                     //Configure pin 4 and 5 as soft serial port
long int a=0x0000,j=0,k=0,count=0;                    //Read Starting address       
uint8_t MH,ML;
boolean EndFlag=0;
                               
void SendResetCmd();
void SendTakePhotoCmd();
void SendReadDataCmd();
void StopTakePhotoCmd();

void setup(){ 
  Serial.begin(19200);
  mySerial.begin(38400);
}

void loop() {
     SendResetCmd();
     delay(4000);      //After reset, wait 4 second to send take picture command
      
      SendTakePhotoCmd();

     while(mySerial.available()>0)
      {
        incomingbyte=mySerial.read();
        Serial.print(incomingbyte);
      }   
      byte a[32];
      
      while(!EndFlag)
      {  
         j=0;
         k=0;
         count=0;
         SendReadDataCmd();

         delay(5000);
          while(mySerial.available()>0)
          {
               incomingbyte=mySerial.read();
               k++;
               if((k>5)&&(j<32)&&(!EndFlag))
               {
               a[j]=incomingbyte;
               if((a[j-1]==0xFF)&&(a[j]==0xD9))      //Check if the picture is over
               EndFlag=1;                           
               j++;
	       count++;
               }
          }
         
          for(j=0;j<count;j++)
          {   if(a[j]<0x10)
              Serial.print("0");
              Serial.print(a[j],HEX);
              Serial.print(" ");
          }                                       //Send jpeg picture over the serial port
          Serial.println();
      }      
     while(1);
}

//Send Reset command
void SendResetCmd()
{
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x26);
      mySerial.write((byte)0x00);
}

//Send take picture command
void SendTakePhotoCmd()
{
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x36);
      mySerial.write((byte)0x01);
      mySerial.write((byte)0x00);  
}

//Read data
void SendReadDataCmd()
{
      MH=a/0x100;
      ML=a%0x100;
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x32);
      mySerial.write((byte)0x0c);
      mySerial.write((byte)0x00); 
      mySerial.write((byte)0x0a);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write(MH);
      mySerial.write(ML);   
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x20);
      mySerial.write((byte)0x00);  
      mySerial.write((byte)0x0a);
      a+=0x20;                            //address increases 32£¬set according to buffer size
}

void StopTakePhotoCmd(){
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x36);
      mySerial.write((byte)0x01);
      mySerial.write((byte)0x03);        
}

As you can see the code has been updated with:

 

1.  (byte) cast

2.  SoftwareSerial library instead of the old NewSoftSerial one.

 

The sketch doesnt write the file anywhere but it does spit out the data to the serial monitor.  Unfortunately Im getting 00 bytes.

I added this line: Serial.print(incomingbyte); but there is already one that prints out the array contents here: Serial.print(a[j],HEX);

 

Both are 0.  So then I found this one which saves the file to a microSD and the file gets written but of course the file is 0 bytes:

//*******************************************************
//              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);          // 5,6 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(2000);
        while(mySerial.available()>0)
        {
            incomingbyte=mySerial.read();
            Serial.print("incoming...");
            Serial.print(incomingbyte);
            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);
}

What am I missing here?  Why is the camera returning 00?

Share this post


Link to post
Share on other sites

Oh nice!  Ive been posting in this forum for the past few days about being unable to work the camera I bought from you and nobody but you has answered and the only answer has been to download an evaluation software that Im unable to run on my computer.

Share this post


Link to post
Share on other sites

Oh nice!  Ive been posting in this forum for the past few days about being unable to work the camera I bought from you and nobody but you has answered and the only answer has been to download an evaluation software that Im unable to run on my computer.

 

I am a Mac user as well with 4 Mac Pros in my house. Very little development or eval software in this field work on OS X. Personally I run Windows and Ubuntu with Virtualbox. Its something you should get used to.

Share this post


Link to post
Share on other sites

That may be so, the support for these products on this forum is still poor.  Support should make attempts to resolve an issue.  This is the 9th post just in this topic and no attempt has been made to even begin to address the issue.

Share this post


Link to post
Share on other sites

I have no knowledge of these boards, but the first thing I do when playing with a new board is to get it working with the default sample code. Once I was receiving data then I would start modifying the code to my needs. I looked over the manual and it seems to provide more than enough information to get it working.

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

×