hi there,
i have serial camera connected arduino using following code:
by using code hexadecimal numbers. problem can't convert these hexadecimal numbers jpeg file. what's pretty weird jpeg file starts "ff d8", there no "ff d8" in data. there mistake?
i have serial camera connected arduino using following code:
code: [select]
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 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 picture 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 on 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 code hexadecimal numbers. problem can't convert these hexadecimal numbers jpeg file. what's pretty weird jpeg file starts "ff d8", there no "ff d8" in data. there mistake?
i don't understand question. .jpg file format has defined structure specific , required header information, , part of may looking at.
however, should understand hexadecimal 1 way of representing binary number.
this line prints out binary data in hexadecimal representation:
however, should understand hexadecimal 1 way of representing binary number.
this line prints out binary data in hexadecimal representation:
code: [select]
serial.print(a[j],hex);
Arduino Forum > Using Arduino > Programming Questions > LinkSprite JPEG Color Camera TTL - error with hexadecimal numbers
arduino
Comments
Post a Comment