Advertisement
safwan092

JPEG IR Camera for Arduino

May 21st, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.49 KB | None | 0 0
  1. /******************************************************************************
  2. LinkSprite_Cam
  3. Ryan Owens @ SparkFun Electronics>
  4. Revised by Joel Bartlett on 03/25/15 for compilation on Arduino 1.6+
  5.  
  6. This code allows you to control the LinkSprite IR Camera (SEN-11610) with an Arduino microcontroller
  7.  
  8. Development environment specifics:
  9. Arduino 1.6.0
  10.  
  11. This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!
  12.  
  13. Distributed as-is; no warranty is given.
  14. *********************************************************************************/
  15. #include <SoftwareSerial.h>
  16.  
  17. /* Linksprite */
  18. byte incomingbyte;
  19. SoftwareSerial mySerial(4,5); // RX, TX         //Configure pin 4 and 5 as soft serial port
  20.  
  21. int a=0x0000,j=0,k=0,count=0;                    //Read Starting address      
  22. uint8_t MH,ML;
  23. boolean EndFlag=0;
  24.                                
  25. void SendResetCmd();
  26. void SendTakePhotoCmd();
  27. void SendReadDataCmd();
  28. void StopTakePhotoCmd();
  29.  
  30. void setup()
  31. {
  32.   Serial.begin(19200);
  33.   mySerial.begin(38400);
  34. }
  35.  
  36. void loop()
  37. {
  38.      SendResetCmd();
  39.      delay(4000);                               //After reset, wait 2-3 second to send take picture command
  40.      
  41.       SendTakePhotoCmd();
  42.  
  43.      while(mySerial.available()>0)
  44.       {
  45.         incomingbyte=mySerial.read();
  46.  
  47.       }  
  48.       byte a[32];
  49.      
  50.       while(!EndFlag)
  51.       {  
  52.          j=0;
  53.          k=0;
  54.          count=0;
  55.          SendReadDataCmd();
  56.  
  57.          delay(25);
  58.           while(mySerial.available()>0)
  59.           {
  60.                incomingbyte=mySerial.read();
  61.                k++;
  62.                if((k>5)&&(j<32)&&(!EndFlag))
  63.                {
  64.                a[j]=incomingbyte;
  65.                if((a[j-1]==0xFF)&&(a[j]==0xD9))      //Check if the picture is over
  66.                EndFlag=1;                          
  67.                j++;
  68.            count++;
  69.                }
  70.           }
  71.          
  72.           for(j=0;j<count;j++)
  73.           {   if(a[j]<0x10)
  74.               Serial.print("0");
  75.               Serial.print(a[j],HEX);
  76.               Serial.print(" ");
  77.           }                                       //Send jpeg picture over the serial port
  78.           Serial.println();
  79.       }      
  80.      while(1);
  81. }
  82.  
  83. //Send Reset command
  84. void SendResetCmd()
  85. {
  86.       mySerial.write(0x56);
  87.       mySerial.write((byte)0);
  88.       mySerial.write(0x26);
  89.       mySerial.write((byte)0);
  90. }
  91.  
  92. //Send take picture command
  93. void SendTakePhotoCmd()
  94. {
  95.       mySerial.write(0x56);
  96.       mySerial.write((byte)0);
  97.       mySerial.write(0x36);
  98.       mySerial.write(0x01);
  99.       mySerial.write((byte)0);  
  100. }
  101.  
  102. //Read data
  103. void SendReadDataCmd()
  104. {
  105.       MH=a/0x100;
  106.       ML=a%0x100;
  107.       mySerial.write(0x56);
  108.       mySerial.write((byte)0);
  109.       mySerial.write(0x32);
  110.       mySerial.write(0x0c);
  111.       mySerial.write((byte)0);
  112.       mySerial.write(0x0a);
  113.       mySerial.write((byte)0);
  114.       mySerial.write((byte)0);
  115.       mySerial.write(MH);
  116.       mySerial.write(ML);  
  117.       mySerial.write((byte)0);
  118.       mySerial.write((byte)0);
  119.       mySerial.write((byte)0);
  120.       mySerial.write(0x20);
  121.       mySerial.write((byte)0);  
  122.       mySerial.write(0x0a);
  123.       a+=0x20;                            //address increases 32£¬set according to buffer size
  124. }
  125.  
  126. void StopTakePhotoCmd()
  127. {
  128.       mySerial.write(0x56);
  129.       mySerial.write((byte)0);
  130.       mySerial.write(0x36);
  131.       mySerial.write(0x01);
  132.       mySerial.write(0x03);        
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement