TTL Serial Camera not sending jpeg format

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
philippbraun95
 
Posts: 4
Joined: Sat Dec 01, 2012 3:16 pm

TTL Serial Camera not sending jpeg format

Post by philippbraun95 »

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

#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() {
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: TTL Serial Camera not sending jpeg format

Post by adafruit_support_rick »

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?

philippbraun95
 
Posts: 4
Joined: Sat Dec 01, 2012 3:16 pm

Re: TTL Serial Camera not sending jpeg format

Post by philippbraun95 »

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

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.
-----------------
ÿØÿþ$^à€2QQÿÛ„
	
" ! #&#&  ÿþÿÀà€!ÿÄ¢	
	
}!1AQa"q2‘¡#B±ÁRÑð$3br‚	
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢BANNED¤¥¦§¨©ª²³´µ¶·¸BANNED×BANNED÷BANNED!1AQaq"2B‘¡±Á	#3RðbrÑ
$4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢BANNED¤¥¦§¨©ª²³´µ¶·¸BANNED×BANNED÷BANNED(BANNED?ù}œùh¥˜BANNED§I·BANNED:óT©Ê.ÝŠOu=®ðJ¹À	­5]˜äœ(éëþy«•%º/žñ¸BANNED`äghV8 qž¼TÆ-/A)Ý.aªªù9qü8<þ4,­åàðó¨Qm;Nmîà(BANNED#©BANNED.k!NÕŒ*»BANNED"BANNED îçæèÕ>BANNED››BANNED[’À’BANNED±±)€äsšsæqQ@ç÷•€“N1š‡å®$Ÿ+².BANNED<@ÄtäVpR”yN¯QŒx#v;÷BANNED'†$ç 5Ó+jµ2sÙˆ¥†HÎ=©BANNED;€8QÓ·BANNED
R»pÁطʸ'BANNED BANNED\jY°‰Àp”BANNED¤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[[BANNED)2	&Cä
9TŒŒ”ù‡g€Áæ£@Ccýy¡TVÑ‹™-BANNED!xÁϧ֛‚2ryÎx\SROv%%BANNED
@ÇrsƒM
Iê6ž9=)óEu'šî÷@Üey#BANNED¥U Ø<g­6ák&54´`S–BANNED‘Ðïç¦:Ts+Zås­…BANNEDƒÎxîzqTånLe­˜Ý¸2H§"BANNED'(BANNED÷4ç[
U†~QÈÏZk!èc­J’ÞæwA(8ã¦*@v1•BANNED
¸½ŽiJ¶BANNED-»1FIEÊÀîÀ§½#ƒ×BANNED”BANNED®ã™8èri 6âzj¤BANNED†BANNED~´âd¨BANNED‹]7Œü{Ñå“ L“ßµBœZ³e·uî
wsBANNED¥D,Ä–ç®9tã9÷ÿ%©Au'™&(G“BANNED`¤BANNED©rŠWOR¹—BANNED¡çã8Û}Lå=AQ‹nÈÆpsšEVÇÓž´œâ÷eó*BANNEDFØ<àO8â®3‡p”Ó¶¢BANNED$/ãó¤El¶F;Žzš—5°ÓˆÕR8éž{Ó•	à`ƒŒäö#ÿ×M¸·¹1šˆÝ„䎝?Ͻ*©ätç½)N/¨s!vñœû@§§BANNED¨BANNED°oóùR"62;÷­BANNED*M;½„eù¸ó‘õ¥
sŒŒ}Gó¨æ·.êª1åˆÏ@	ëL
{óCš¶BANNED›…÷ëŠ@„Àõ<T©ÆÖ¸]7¨"ØÇ9õëJªsÆ:c“BANNED«š6³cN";±Ž1ž¸BANNED¤F§9É?BANNED‡Q5kš¸%9ã<”±«BANNED¥ÎՍ¶BANNED¤.‹ÐPU¶‚8èqšµ8½n‚VéÐœtÏãI‚BANNED{	µ#J[°qÿê©s‹ê]×qYxéÓ=iQ!8]Ç€g¹ªS…®ØÛ‹²A°ƒŒóœuãŠP˜Ý»BANNED –Œ•-uTãQœu8 B¹?Þ>BANNED)C¹Nz†Ö!Ž2|Ž(¹PÀ€ “BANNED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???

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: TTL Serial Camera not sending jpeg format

Post by adafruit_support_rick »

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

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.

philippbraun95
 
Posts: 4
Joined: Sat Dec 01, 2012 3:16 pm

Re: TTL Serial Camera not sending jpeg format

Post by philippbraun95 »

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?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: TTL Serial Camera not sending jpeg format

Post by adafruit_support_rick »

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

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: TTL Serial Camera not sending jpeg format

Post by floresta »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”