Arduino + TTL Camera +SD

shaikhmuneer23:
I am not able to generate the image :0
Below is my code.. Now since the manual says the image is JPEG format.. what other processing is required.

#include <NewSoftSerial.h>

byte incomingbyte;
NewSoftSerial mySerial(2,3);                     //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(38400);
 mySerial.begin(38400);
}

void loop()
{
    SendResetCmd();
    delay(3000);                               //After reset, wait 2-3 second to send take picture command
     
     SendTakePhotoCmd();

while(mySerial.available()>0)  //I DONT UNDERTAND !!!!!! wont this return the last byte in incomingbyte ??
     {
       incomingbyte=mySerial.read();

}  
     byte a[32];
     
     while(!EndFlag)
     {  
        j=0;
        k=0;
        count=0;
        SendReadDataCmd();

delay(25);
         while(mySerial.available()>0)
         {
              incomingbyte=mySerial.read();
              k++;
              if((k>5)&&(j<32)&&(!EndFlag)) //why is it k<5 ??
              {
              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)         //why 0x10 ? why do we check for this (>16) condition
             Serial.print("0");    //why print this 0
             Serial.print(a[j],HEX);
             Serial.print(" ");           //why print this " space "
         }                                       //Send jpeg picture over the serial port
         Serial.println();
     }      
    while(1);   // ??? is that even necessary its already in void loop()
}

//Send Reset command
void SendResetCmd()
{
     mySerial.print(0x56, BYTE);
     mySerial.print(0x00, BYTE);
     mySerial.print(0x26, BYTE);
     mySerial.print(0x00, BYTE);
}

//Send take picture command
void SendTakePhotoCmd()
{
     mySerial.print(0x56, BYTE);
     mySerial.print(0x00, BYTE);
     mySerial.print(0x36, BYTE);
     mySerial.print(0x01, BYTE);
     mySerial.print(0x00, BYTE);  
}

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

void StopTakePhotoCmd()
{
     mySerial.print(0x56, BYTE);
     mySerial.print(0x00, BYTE);
     mySerial.print(0x36, BYTE);
     mySerial.print(0x01, BYTE);
     mySerial.print(0x03, BYTE);        
}




The output in the serial monitor is displayed in HEX which is presumably the JPEG format.
So what do I do next ??

What do i do with the HEX data obtained now (See the attached file for the serial output). Once i am able to construct an JPEG image out of this I want to transmit it on wireless radio (however that is in the later stage)

Does anyone have a routine/code written that can change these HEX values to required JPEG values and all we would have to do is to change the extension and the JPEG should appear.

"Hello Paul :slight_smile:

Just found that you were online so dropping a line.
I posted a question in the JPEG camera post, if you find time please take a look and help me out.

Thanks again.
Muneer"

I am not Paul. But i know he can solve your question. 8)