LinkSprite JPEG Color Camera TTL - error with hexadecimal numbers

Hi there,

I have a Serial camera which I connected to my Arduino using the following code:

byte incomingbyte;
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);
 Serial1.begin(38400);
}

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

    while(Serial1.available()>0)
     {
       incomingbyte=Serial1.read();

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

        delay(25);
         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))      //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()
{
     Serial1.write(0x56);
     Serial1.write(0x00);
     Serial1.write(0x26);
     Serial1.write(0x00);
}

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

//Read data
void SendReadDataCmd()
{
     MH=a/0x100;
     ML=a%0x100;
     Serial1.write(0x56);
     Serial1.write(0x00);
     Serial1.write(0x32);
     Serial1.write(0x0c);
     Serial1.write(0x00);
     Serial1.write(0x0a);
     Serial1.write(0x00);
     Serial1.write(0x00);
     Serial1.write(MH);
     Serial1.write(ML) ;  
     Serial1.write(0x00);
     Serial1.write(0x00);
     Serial1.write(0x00);
     Serial1.write(0x20);
     Serial1.write(0x00); 
     Serial1.write(0x0a);
     a+=0x20;                           
}

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

By using this code I get hexadecimal numbers. The problem is that I can’t convert these hexadecimal numbers into a jpeg file. What’s pretty weird is that a jpeg file always starts with “FF D8”, but there is no “FF D8” in my data. Is there any mistake?

camera data.txt (36.5 KB)

I don’t understand the question. The .jpg file format has a well defined structure with specific and required header information, and part of that may be what you are looking at.

However, you should understand that hexadecimal is just one way of representing a binary number.

This line prints out binary data in hexadecimal representation:

Serial.print(a[j],HEX);

The jpeg file consists of binary data, not string representations of binary data. Binary data is sent using Serial.write(). You can't make sense of binary data in the serial monitor, so don't even try.