Go Down

Topic: Need help using linksprite IR Camera with arduino uno (Read 619 times) previous topic - next topic

ttbccthelegend

I am currently working on a project that will utilize this camera:

https://www.sparkfun.com/products/11610

The code that sparkfun provides is a bit outdated, so after looking a while for updates I currently have the code below. The problem with this however is that it seems as though nothing is happening, and mySerial.available() always ends up as 0 so the loops never do anything. If anyone can please provide some help as to what I can do to get this working I would greatly appreciate it. Thanks everyone.

Code: [Select]

#include <SoftwareSerial.h>

 byte incomingbyte;
 SoftwareSerial mySerial(4,5);                     //RX 4, TX 5
 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(19200);
   mySerial.begin(38400);
   Serial.println("Serial has begun");
 }

 void loop()
 {
   //Print what's in the Serial port and Reset
     SendResetCmd();
     Serial.println("Sent Reset Command");
     
      delay(4000);                       

      //After reset, wait 2-3 second to send take picture command, check again
           Serial.println("BEfore send tak photo command");
      SendTakePhotoCmd();
           Serial.println("After sendtakephotocommand");
      int numOfSer=mySerial.available();
      Serial.println(numOfSer);

     while(mySerial.available()>0)
      {
        incomingbyte=mySerial.read();
        Serial.println(incomingbyte, HEX);
      }   
     
      byte a[32];
      Serial.println("Byte Array Initialized");
     
      while(!EndFlag)
      { 
        Serial.println("Entering While Loop");
         j=0;
         k=0;
         count=0;
         SendReadDataCmd();
         Serial.println("Read Data Command Sent");
         
         delay(25);
          while(mySerial.available()>0)
          {
               incomingbyte=mySerial.read();
               k++;
               if((k>5)&&(j<32)&&(!EndFlag))
               {
               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)
              Serial.print("0");
              Serial.print(a[j],HEX);
              Serial.print(" ");
          }                                       //Send jpeg picture over the serial port
          Serial.println();
      }     
     while(1);
 }

 //Send Reset command
void SendResetCmd()
{
  Serial.println("in send reset cmnd");
      mySerial.write(0x56);
      mySerial.write(byte(0x00));
      mySerial.write(0x26);
      mySerial.write(byte(0x00));
}

//Send take picture command
void SendTakePhotoCmd()
{
    Serial.println("in send take photo cmnd");
      mySerial.write(0x56);
      mySerial.write(byte(0x00));
      mySerial.write(0x36);
      mySerial.write(0x01);
      mySerial.write(byte(0x00)); 
}

//Read data
 void SendReadDataCmd()
 {
     Serial.println("in send read data cmnd");
      MH=a/0x100;
      ML=a%0x100;
      mySerial.write(0x56);
      mySerial.write(byte(0x00));
      mySerial.write(0x32);
      mySerial.write(0x0c);
      mySerial.write(byte(0x00));
      mySerial.write(0x0a);
      mySerial.write(byte(0x00));
      mySerial.write(byte(0x00));
      mySerial.write(MH);
      mySerial.write(ML);   
      mySerial.write(byte(0x00));
      mySerial.write(byte(0x00));
      mySerial.write(byte(0x00));
      mySerial.write(0x20);
      mySerial.write(byte(0x00)); 
      mySerial.write(0x0a);
      a+=0x20;                            //address increases 32£¬set according to buffer size
 }

 void StopTakePhotoCmd()
 {
     Serial.println("in send stop    take photo cmnd");
      mySerial.write(0x56);
      mySerial.write(byte(0x00));
      mySerial.write(0x36);
      mySerial.write(0x01);
      mySerial.write(0x03);       
 }

Go Up