TTL Serial Camera not sending jpeg format
Moderators: adafruit_support_bill, adafruit

TTL Serial Camera not sending jpeg format

by philippbraun95 on Sat Dec 01, 2012 3:34 pm

I bought the serial camera from Adafruit and everything works alright. The sample code does what it promises as well, no error messages or anything. But when I try to output a jpeg using the Serial port of my computer I get some code similar to a jpeg but without a header or so. I tried to put it into a file but it obviously doesn't work.

The only line I really changed is Serial.write(buffer, bytesToRead); to receive the jpeg on my computer instead of in the SD card.

Here is the code I tried to use:

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>

SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

void setup() {

  Serial.begin(38400);
  Serial.println("VC0706 Camera snapshot test");
 
  // Try to locate the camera
  if (cam.begin()) {
    Serial.println("Camera Found:");
  } else {
    Serial.println("No camera found?");
    return;
  }
  // Print out the camera version information (optional)
  char *reply = cam.getVersion();
  if (reply == 0) {
    Serial.print("Failed to get version");
  } else {
    Serial.println("-----------------");
    Serial.print(reply);
    Serial.println("-----------------");
  }
 
  cam.setImageSize(VC0706_640x480);

  Serial.println("Snap in 3 secs...");
  delay(3000);

  if (! cam.takePicture())
    Serial.println("Failed to snap!");
  else
    Serial.println("Picture taken!");
 
  uint16_t jpglen = cam.frameLength();
  Serial.print("Storing ");
  Serial.print(jpglen, DEC);
  Serial.println(" byte image.");
  Serial.println("-----------------");
 
  int32_t time = millis();
  byte wCount = 0; // For counting # of writes
  while (jpglen > 0) {
    // read 32 bytes at a time;
    uint8_t *buffer;
    uint8_t bytesToRead = min(32, jpglen);
    buffer = cam.readPicture(bytesToRead);
    Serial.write(buffer, bytesToRead);
    jpglen -= bytesToRead;
  }
 
  time = millis() - time;
  Serial.println();
  Serial.println("-----------------");
  Serial.println("Done!");
  Serial.println("-----------------");
  Serial.print(time); Serial.println(" ms elapsed");
}

void loop() {
}
philippbraun95
 
Posts: 4
Joined: Sat Dec 01, 2012 3:16 pm

Re: TTL Serial Camera not sending jpeg format

by adafruit_support_rick on Sat Dec 01, 2012 3:58 pm

Well, you've got all the Serial.print stuff mixed up with your picture. You are editing that stuff out manually?

How are you receiving the serial data on your computer?

adafruit_support_rick
 
Posts: 13689
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: TTL Serial Camera not sending jpeg format

by philippbraun95 on Sat Dec 01, 2012 4:35 pm

Why is the Serial.print stuff mixed up with my picture. I get the following code back from my Arduino using the usual Serial Monitor.

Output as follows:

Code: Select all | TOGGLE FULL SIZE
VC0706 Camera snapshot test
Camera Found:
-----------------
VC0703 1.00
Ctrl infr exist
User-defined sensor
525
-----------------
Snap in 3 secs...
Picture taken!
Storing 46716 byte image.
-----------------
ÿØÿþ$^à€2 QQÿÛ„
    
" ! #&#&  ÿþÿÀà€!ÿÄ¢   
   
}!1AQa"q2‘¡#B±ÁRÑð$3br‚   
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢banned¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúw!1AQaq"2B‘¡±Á   #3RðbrÑ
$4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢banned¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÝ(ÿÚ ?ù}œùh¥˜àúõ§I·vò:óT©Ê.ÝŠOu=®ðJ¹À   ­5]˜äœ(éëþy«•%º/žñ¸àÌÀ`äghV8 qž¼TÆ-/A)Ý.aªªù9qü8<þ4,­åàðó¨Qm;Nmîà(ìIÇjDbF#©ÒÒýNoi.k!NÕŒ*»0àdòM"í îçæèÕ>òŽ››JrZˆì[’À’zŽô±±)€äsšsæqQ@ç÷•€“N1š‡å®$Ÿ+².nÍ1XœîTg<@ÄtäVpR”yN¯QŒx#v;÷çÒï'†$ç 5Ó+jµ2sÙˆ¥†HÎ=©áÿxÌ;€8QÓ·øTÔƒ½ú
R»pÁطʸ'úRdí gŠÍÂMÙì\jY°‰Àp”ÎJúô¤v}ÀqÓõ®ŽEØÉT´¶±<r{

[ Here I left out some stuff because some stuff was recognized as banned spam words from the Adafruit Site]

…Áã¥k­}K•E}˜ÿv\6
‘ë@\MJ”{ŽSM ´ž
ñëøR[[¼òª)2   &Cä
9TŒŒ”ù‡g€Áæ£@Ccýy¡TVÑ‹™-Çì!xÁϧ֛‚2ryÎx\SROv%%Íp
@ÇrsƒM
Iê6ž9=)óEu'šî÷@Üey#9ô¥U Ø<g­6ák&54´`S–íÚ‘Ðïç¦:Ts+Zås­…ÚNôãސƒÎxîzqTånLe­˜Ý¸2H§"¾õÁÇùÍ'(Ú÷4ç[
U†~QÈÏZk!èc­J’ÞæwA(8ã¦*@v1•ëÍTenÓPhÞ9
¸½ŽiJ¶ïºúÓn-»1FIEÊÀîÀ§½#ƒ×ÏÒ”gÔm®ã™8èri 6âzj¤̆ìlôÎ0~´â d¨úÕNqêÊ‹]7Œü{Ñå“ L“ßµBœZ³e·uî
wsžäô¥D,Ä–ç®9tã9÷ÿ%©Au'™&(G“³ÍÏãMe`¤zóô©rŠWOR¹—0vgxôÇáAWÛÔc¡çã8Û}Lå=AQ‹nÈÆpsšEVÇÓž´œâ÷eó*ÀgҐFØ<àO8â®3‡p”Ó¶¢ì$/ãó¤El¶F;Žzš—5°ÓˆÕR8éž{Ó•   à`ƒŒäö#ÿ×M¸·¹1šˆÝ„䎝?Ͻ*©ä tç½)N/¨s!vñœû @§§ùíIJ ¨ÔÅòÙ°oóùR"62;÷­àô¹*M;½„eù¸ó‘õ¥
sŒŒ}Gó¨æ·.êª1åˆÏ@   ëL
{óCš¶âRVÔvß›…÷ëŠ@„Àõ<T©ÆÖ¸]7¨"ØÇ9õëJªsÆ:c“Ò«š6³cN";±Ž1ž¸Ï4í¤F§9É?Ò‡Q5kš¸%9ã<”±«6HíÔf¥ÎՍ¶ØÒ¤.‹ÐPU¶‚8èqšµ8½n‚VéÐœtÏãI‚yíéMNÉR{   µ#J[°qÿê©s‹ê]×qYxéÓ=iQ!8]Ç€g¹ªS…®ØÛ‹²A°ƒŒóœuãŠP˜Ý»ŸîŒÒu –Œ•-uTãQœu8 B¹?Þ>¾Ô)C¹Nz†Ö!Ž2|Ž(¹PÀ€ “ÍZœUõ3KjÿÙ
-----------------
Done!
-----------------
14943 ms elapsed


And back to the mixing up idea. How can the Serial.write or print be mixed up with my image data. The code above really seems to be part of an image. Jpeg images with comments for instance often have this alphabetic code "456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz" at the beginning.
So what's wrong with the output??? --> Why isn't it recognized as an image when I put the code into a jpg file???
philippbraun95
 
Posts: 4
Joined: Sat Dec 01, 2012 3:16 pm

Re: TTL Serial Camera not sending jpeg format

by adafruit_support_rick on Sat Dec 01, 2012 8:13 pm

philippbraun95 wrote:Why is the Serial.print stuff mixed up with my picture.

Because you're writing everything to Serial, both text and picture:
Code: Select all | TOGGLE FULL SIZE
Serial.print(jpglen, DEC);
  Serial.println(" byte image.");
  Serial.println("-----------------");
   ….  etc  ….
    buffer = cam.readPicture(bytesToRead);
    Serial.write(buffer, bytesToRead);
   ….  etc  ….


If you want to only write the picture data, you'll have to take out all of the Serial.print and Serial.println statements.

adafruit_support_rick
 
Posts: 13689
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: TTL Serial Camera not sending jpeg format

by philippbraun95 on Sun Dec 02, 2012 11:21 am

I took out all my serial.print stuff and the ascii output really changed a little bit. But putting all the ascii code into a jpeg file still doesn't work out. I tried to get the hex output from the camera and convert it afterwards to a binary file. But it still doesn't work.

If you have any ideas how to fix my problems please write me back!! I basically just want to have a jpg image on my pc at the end of my project. So is there any possiblity to get the ascii ouptut and convert it to an image?
philippbraun95
 
Posts: 4
Joined: Sat Dec 01, 2012 3:16 pm

Re: TTL Serial Camera not sending jpeg format

by adafruit_support_rick on Mon Dec 03, 2012 10:51 am

How are you receiving the image data on your computer? What program are you using?

adafruit_support_rick
 
Posts: 13689
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: TTL Serial Camera not sending jpeg format

by floresta on Mon Dec 03, 2012 11:58 am

I took out all my serial.print stuff and the ascii output really changed a little bit. But putting all the ascii code into a jpeg file still doesn't work out. I tried to get the hex output from the camera and convert it afterwards to a binary file. But it still doesn't work.

I hate to be the one who breaks the news to you, but you really have no concept of what is going on.

Digital data is always binary and all files contain only binary data. At a glance it is hard to distinguish one string of ones and zeroes from another so the binary data is frequently displayed as an equivalent hexadecimal value. The data is still the same, it is just expressed differently.

This digital data usually represents something else. It could represent a quantity, it could represent an instruction for a computer, it could represent a displayable character for a computer or LCD screen or it could represent something else, such as a bit pattern for a picture.

Example: The binary data 00110111 can be expressed in hexadecimal as 37, in octal as 067, or in decimal as 55. It is still the same data, just expressed differently.
As a quantity it represents 55 of something.
As an instruction for an ATmega microprocessor it is the first part of a compare instruction (I think).
As a displayable character it is the ASCII code that results in the display of the number 7.
As the bit pattern for a picture it could represent eight pixels three of which are off and five of which are on (or vice versa).

Since we are dealing with a camera here I would expect that most (or all) of the data coming out of the camera somehow represents pixels that are on or off.

Many JPEG files contain additional data in addition to that representing the picture itself. That data consists largely of ASCII codes since it is information that is frequently going to be displayed on a screen. I believe that the string "*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz" may be a placeholder for some of that data. If the camera does not provide for such additional data then the string probably will not appear.

Don
floresta
 
Posts: 221
Joined: Thu Jul 31, 2008 10:27 am
Location: Western New York, USA