Jump to content


Photo

Jpeg Camera TTL interface 2MP - resolution issue

resolution problems freezes

  • Please log in to reply
1 reply to this topic

#1 npw14

npw14

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 29 September 2016 - 08:39 AM

I have an Arduino Mega, LCD Plus (incuding SD card slot) and a LinkSprite JEPG Color Camera TTL interface - 2MP and most of the time it works fine. Unfortunately on occasions the camera freezes doesn't do anything mid way through taking a picture. I think it may be connected to settting one of the high resolutions such as 1024x768 or higher, although on occasions when I set a lower resolution i.e. 800x600 it still occasionally freezes during taking the image. I have looked at the manual for the operation of the camera by Linksprite but wonder if anyone can advise ?

 

Can anyone spot a problem or supply an alternate version of reliable code ?

My feeling is that it is caused by the image packet size sometimes being too high and causing it too freeze e.g. packet size greater than 2000 x 16 bits = 32000. The camera buffer register is only 16 bit with 1 bit signed and so cant be greater than 32768.

 

//==================================================================
//              MAIN CAMERA ROUTINE - TAKE PICTURE
//==================================================================
void activatePhotoCamera()
{
  bool takePiccy;
 
//  Serial.println("Sending Take Photo Command"); 
  lcd.setCursor(0,0);
  lcd.print("  Taking Photo !");
  lcd.setCursor(0,1);
  lcd.print(" Wait...25 Secs ");
  //  delay(1000);
 
  //------ CAMERA SNAPSHOT START ---------------
  takePiccy = SendTakePhotoCmd();  // Take Photo i.e. SNAPSHOT COMMAND
 
  Serial.print("takePiccy = ");
  Serial.println(takePiccy);

 

 //------------------- READ JPG CONTENTS DATA ---------------------------------------
   // Now, Read the JPEG file content
      // Response (5 Bytes) 76 00 32 00 00
      // (32 Bytes) of image data
      // (5 Byes) 76 00 32 00 00
      byte packet[42]; // 5 bytes + 32 Bytes + 5 Bytes response
     
      // Setup for a nice, clean reading of the packets
      a=0x0000;  // This is our buffer address!
      EndFlag = 0;
      bytesRead = 0; // total data bytes read (i.e. Byte 5 to 37
      packetCount = 0; // Packet Size is multiple of 8

 

 while(!EndFlag)
      { 
 
        // Sometimes there might be gook in the buffer after the last packet and before
        // we ask it for more data... Ignore that.
        dumpCameraInput(false);  // Do this in silent mode!
       
        // Tell the camera we would like to read an image and explain to it our buffer size and requested delay...
        SendReadDataCmd();
                    
        i = 0;
        // Notice we read 42 bytes from the serial buffer.  That is:
        // 5 Byte preamble (76 00 32 00 00)
        // 32 Bytes of data (that is what we asked for)
        // 5 Byte postamble (76 00 32 00 00)      
        while(i < 42)    // Read 42 bytes in from serial buffer
        {                 
          while(Serial2.available() > 0)
           {     
             incomingbyte = Serial2.read();
             packet[i] = incomingbyte;
             i++;
           }
         }

         // We have now read one packet
         packetCount++; // i.e. 1 packet = 42 Bytes of information
             
        
         //  Test each packet to see if preamble 5 bytes equals the postamble 5 bytes
         // (This is a pretty lame test but it is a start)
         for (i=0; i<5; i++) 
          {
            if( !(packet[i] == packet[i+37]) )
              {
                // Checks i[0] = 76 matches i[37] = 76 (Should be same - camera response)
                badPackets++;
                // TODO: Could you ever re-ask for data?
              }
          }
  
          // Now, loop through the useful bytes of the data packet (Bytes 5 to 37) and write to the card
          // We do this in a self-incremented loop from 5 to < 37 because we need to bail out
          // immediately when we see the end of the JPG data
          i = 5;
          while (!EndFlag && i < 37)    
          {
            bytesRead++; // increment bytes data read
           
            //  Write data to packet to SD card
            if (dataFileCamera)
            {
              dataFileCamera.write(packet[i]); // Write 32 Data Bytes to SD Card
            }
            else
            {
              Serial.println("FILE ERROR - ABORTING PICTURE");
              // It will never recover from this error, so just bail on this picture
              EndFlag = 1;
            }
           
            // Check if end of JPEG
            if((packet[i-1] == 0xFF) && (packet[i] == 0xD9))  //Check if the picture is over (a JPEG ends with FF D9)
            {
              dataFileCamera.close();
              Serial.println("File is closed");
              EndFlag = 1;
              pictureTaken++;
            }
            
             // If we got this far, we are still good to continue processing this packet
             i++;
            
          } // end looping through useful bytes of packet

 

 }// end of reading the packets until finished    

      Serial.print("Packets: ");
      Serial.println( packetCount);
      Serial.print("Bad packets: ");
      Serial.println( badPackets);
      Serial.print("Bytes read: ");
      Serial.println(bytesRead); // Only Bytes of data i.e. Byte 5-37
      //Serial.print("Bytes remaining: ");            
    // Serial.println(imageSize-bytesRead);
      Serial.println("Issuing Stop Taking Pictures command");
     
     SendStopTakingPicturesCmd();
     lcd.clear();
     lcd.setCursor(5,0);
     lcd.print("Camera");
     lcd.setCursor(1,1);
     lcd.print("Photo Complete");

 

}

 

//========================================================
//                  SNAPSHOT PICTURE START
//=========================================================
//  Send take picture command. Tells the camera to take a picture, and analyzes the response
boolean SendTakePhotoCmd()
{    // Send: 56 00 36 01 00
     // Response: 76 00 36 00  (4 Bytes:  v  6  )
    
     dumpCameraInput(true);
    
      // Send the take picture command
      Serial2.write(0x56);
      Serial2.write((uint8_t)0x00);
      Serial2.write(0x36);
      Serial2.write(0x01);
      Serial2.write((uint8_t)0x00); 
     
      return successIfContains(0x76, 0, 0x36, 2); // Check response is correct
      
}

 

//======================================================
//            Read data of SNAPSHOT Picture
//======================================================
void SendReadDataCmd()
{
      // SEND 56 00 32 0c 00 0a 00 00 Addr0 00 00 Data0 Data1 00 0a
      MH=a/0x100;  // divide by 0x100 (256 Decimal)
      ML=a%0x100;  // Modulus of that division

      Serial2.write(0x56);
      Serial2.write((uint8_t)0x00);
      Serial2.write(0x32);
      Serial2.write(0x0c);
      Serial2.write((uint8_t)0x00);
      Serial2.write(0x0a);
      Serial2.write((uint8_t)0x00);
      Serial2.write((uint8_t)0x00);

      // This is the "Init Address" from which we want to read
      Serial2.write(MH); // Addr0 is 0x0000
      Serial2.write(ML); // Addr1
     
      Serial2.write((uint8_t)0x00); // pad
      Serial2.write((uint8_t)0x00); // pad

      // This is the "Data Length" (KK KK)  In our case 0x20 = 32 Bytes
      Serial2.write((uint8_t)0x00);
      Serial2.write(0x20); // 32 bytes
     
      // This is the "Spacing Interval" we want which is recommended to be small such as 00 0A
      Serial2.write((uint8_t)0x00); 
      Serial2.write(0x0a);

      // Each time we Read Data, increase the starting address by 0x20 (32 Decimal)...
      // This is our buffer size.
      a += 0x20; // increase by 32 (32 bytes) for address each time to read data
}

 



#2 npw14

npw14

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 03 November 2016 - 12:40 PM

I have to say I am very disappointed with the overall response from my technical problem even when going direct to technical support at Linksprite.

I can only assume that there is an actual problem with the Linksprite camera firmware or hardware that doesn't allow pictures to be taken at the higher resolutions e.g. 1920x1280 as claimed.

Shame because it is a decent product otherwise.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users