Advertisement
Guest User

My TTL Linksprite Camera Code

a guest
Dec 8th, 2012
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.14 KB | None | 0 0
  1. #include <JPEGCamera.h>
  2. #include <SoftwareSerial.h>
  3. //#include <SD.h>
  4.  
  5. //File picture;
  6.  
  7. //Create a character array to store the cameras response to commands
  8. char response[42];
  9.  
  10. //Count is used to store the number of characters in the response string.
  11. unsigned int count = 0;
  12.  
  13. //Size will be set to the size of the jpeg image.
  14. int size = 0;
  15.  
  16. //This will keep track of the data address being read from the camera
  17. int address = 0;
  18.  
  19. //eof is a flag for the sketch to determine when the end of a file is detected
  20. //while reading the file data from the camera.
  21. int eof=0;
  22.  
  23. JPEGCamera camera;
  24.  
  25. void setup()
  26. {
  27.     //Setup serial port, as well as the SD card
  28.     Serial.begin(9600);
  29.     Serial.println("BEGUN");
  30.     //SD.begin(9);
  31.     //pinMode(10, OUTPUT);
  32.    
  33.     //Open a new picture file on the SD card
  34.    // picture = SD.open("pic06", FILE_WRITE);
  35.    
  36.     //Setup the Camera
  37.     camera.begin();
  38.    
  39.     Serial.println("Camera finished intializing.");
  40.      
  41.     //camera.resize(response, 1);
  42.     //camera.setBaud(response, 1);
  43.    
  44.     Serial.println("Resetting Camera");
  45.     count = camera.reset(response);
  46.     Serial.println("Finished Resetting Camera");
  47.     Serial.println("Response: ");
  48.     hexdump(response, count);
  49.     delay(3000);
  50.    
  51.     //take a picture
  52.     Serial.println("Taking picture");
  53.     count = camera.takePicture(response);
  54.     Serial.println("Finished taking picture.");
  55.     Serial.println("Response: ");
  56.     hexdump(response, count);
  57.  
  58.     delay(2000);
  59.     Serial.println("");
  60.  
  61.     //Get + print the size of the picture
  62.     Serial.println("Size");
  63.     count = camera.getSize(response, &size);
  64.     Serial.println("Response ");
  65.     hexdump(response, count);
  66.    
  67.     Serial.println(size);
  68.     Serial.println("");
  69.    
  70.     Serial.println("Data");
  71.     Serial.println("{");
  72.    
  73.     while(address < size)
  74.     {              
  75.         //int startTime = millis();//pull the data out that we requested earlier
  76.         count = camera.readData(response, address);
  77.         //int endTime = millis();
  78.         //Serial.print(count);
  79.         //Serial.print(" ");
  80.         //Serial.println(endTime - startTime);
  81.         //camera.wait();
  82.  
  83.         for(int i = 0; i < count; i++)
  84.         {
  85.           //If not end of file
  86.           if((response[i] == (char)0xD9) && (response[i-1]==(char)0xFF)) eof = 1;
  87.           //picture.write(uint8_t(response[i]));
  88.           //Serial.print("0x");
  89.           Serial.print(uint8_t(response[i]), HEX);
  90.           //Serial.print(", ");
  91.           if(eof == 1) break;
  92.        }
  93.      
  94.        
  95.         Serial.println();
  96.         address += count;
  97.         //int end2 = millis();
  98.         //Serial.println(end2 - endTime);
  99.        
  100.         if(eof == 1) break;
  101.     }
  102.     Serial.println("}");
  103.     //picture.close();
  104.  
  105. }
  106.  
  107. void loop()
  108. {
  109. }
  110.  
  111. void hexdump( char *binaryBuf, int len )
  112. {
  113.     for (int i=0; i<len; i++)
  114.     {
  115.         if ( i != 0 && i % 8 == 0 )
  116.         {
  117.             Serial.println("");
  118.         }
  119.        
  120.         Serial.print((unsigned char)(*(binaryBuf+i)), HEX);
  121.         Serial.print(" ");
  122.        
  123.     }
  124.    
  125.     Serial.println("");  // print final newline
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement