Go Down

Topic: Arduino + TTL Camera +SD (Read 2 times) previous topic - next topic

Cybernetician

Quote
Cybernetician
thx for your advice and i'll try it
the reason why i have the different delay time because I try to figure out the reason of this problem
I try to change the baudrate, the delay time in different part!


Most probably your Problem: "int a" 8)

Solution:change the definition of starting address variable "a" from int to long int.

cheers
From Idea To Invention

PaulS

If you want to take one picture, and capture the output, why is the code in loop()? Put the code in setup() and leave loop() empty. Get rid of that while(1) loop.

There should be NO delay()s. You know how much data you need to read. Keep looping until you have read the required amount of data. Do not diddle around with delay(). The delay()s are causing the serial buffer to overflow before you get around to reading all the data.

As you can see from the results, you can keep up for a while, but, eventually you fall behind and start loosing data.

citysite102

pauls,thanks for your advice and i''ll pay more attention on this,i should think more clearly and carefully about that,but not just try to use some weird ways to find out the solution,thanks a lot!!
Cybernetician,you are right and i get the right picture that i need,thank you very much: )


Cybernetician

It's my pleasure 8)

Enjoy "Art of Logic"
From Idea To Invention

shaikhmuneer23

#9
Feb 14, 2013, 01:22 pm Last Edit: Feb 14, 2013, 01:26 pm by shaikhmuneer23 Reason: 1
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.

Code: [Select]
#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.

Go Up