3D point cloud scanner with OV7670 camera and line laser.

Dependencies:   ADXL345_I2C_ HMC5843_ OV7670_ok SDFileSystem ST7735_TFT Servo mbed

Fork of OV7670_edm_full by angelo mottolese

3D point cloud scanner with OV7670 FIFO camera and line laser. I take the brightest pixels in an image, I measure their horizontal displacement to deduce a depth value, and I generate XYZ coordinates. The camera is rotating, and I know the angle, so I can map 3D space in cylindrical coordinates. The home of the project is http://angelomottolese.eu.ai/sitoScanner.html

Revision:
1:c98598814170
Parent:
0:aabbf2286bf2
Child:
2:4ebec58ffaca
--- a/main.cpp	Tue Mar 27 19:10:18 2012 +0000
+++ b/main.cpp	Sat Mar 31 10:05:59 2012 +0000
@@ -14,16 +14,20 @@
 OV7670 camera(
     p28,p27,       // SDA,SCL(I2C / SCCB)
     p21,p22,p20,   // VSYNC,HREF,WEN(FIFO)
-    p19,p18,p17,p16,p15,p14,p13,p12, // D7-D0
+    Port0,0x07800033,
     p23,p24,p25) ; // RRST,OE,RCLK
 
 // the TFT is connected to SPI pin 5-7
-SPI_TFT TFT(p5, p6, p7, p8, p9,"TFT"); // mosi, miso, sclk, cs, reset
+SPI_TFT TFT(p5, p6, p7, p8, p14,"TFT"); // mosi, miso, sclk, cs, reset
 
 Serial pc(USBTX,USBRX);
 
 #define SIZEX (160)
 #define SIZEY (120)
+#define SIZE 19200
+
+unsigned char bank0 [SIZE];
+unsigned char *bank1 = (unsigned char *)(0x2007C000);
 
 int main() {
 
@@ -35,72 +39,50 @@
     TFT.set_font((unsigned char*) Arial12x12);  // Select the font
     TFT.set_orientation(3);                     // Select orientation
 
-    printf("Testing...");
-
-    int i ;
-    pc.baud(115200) ;
-    pc.printf("Camera resetting..\r\n") ;
-
+    // Reset camera on power up
     camera.Reset() ;
 
-    pc.printf("Before Init...\r\n") ;
-    pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") ;
-    for (i=0; i<OV7670_REGMAX; i++) {
-        int data ;
-        data = camera.ReadReg(i) ; // READ REG
-        if ((i & 0x0F) == 0) {
-            pc.printf("\r\n%02X : ",i) ;
-        }
-        pc.printf("%02X ",data) ;
-    }
-    pc.printf("\r\n") ;
-
+    // Set up for 160*120 pixels RGB565
     camera.InitQQVGA() ;
+    
+    // Print message to screen
+    pc.printf("Hit Any Key to stop RGBx160x120 Capture Data.\r\n");
+          
+    // Kick things off by capturing an image
+    camera.CaptureNext() ;
+    while (camera.CaptureDone() == false) ;
 
-    pc.printf("After Init...\r\n") ;
-    pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") ;
-    for (i=0; i<OV7670_REGMAX; i++) {
-        int data ;
-        data = camera.ReadReg(i) ; // READ REG
-        if ((i & 0x0F) == 0) {
-            pc.printf("\r\n%02X : ",i) ;
+    // Now enter the main loop
+    while (!pc.readable()) {
+
+        // Start reading in the image data from the camera hardware buffer                   
+        camera.ReadStart();
+
+        // Read in the first half of the image
+        for (int i = 0; i < SIZE; i++) {
+            bank0[i] =  camera.ReadOneByte();
         }
-        pc.printf("%02X ",data) ;
-    }
-    pc.printf("\r\n") ;
 
-    // CAPTURE and SEND LOOP
-    while (1) {
-        pc.printf("Hit Any Key to send RGBx160x120 Capture Data.\r\n") ;
-        while (!pc.readable()) ;
-        pc.getc() ;
+        // Read in the second half of the image
+        for (int i = 0; i < SIZE ; i++) {
+            bank1[i] =  camera.ReadOneByte();
+        }  
+        
+        // Stop reading the image
+        camera.ReadStop() ; 
+        
+        // Immediately request the next image to be captured (takes around 45ms)
         camera.CaptureNext() ;
-        while (camera.CaptureDone() == false) ;
-        pc.printf("*\r\n") ;
-        camera.ReadStart() ;
-        i = 0 ;
-        int colour;
         
-        for (int y = 0; y < SIZEY; y++) {
-            int r,g,b,d1,d2 ;
-            for (int x = 0; x < SIZEX; x++) {
-                d1 = camera.ReadOneByte() ; // upper nibble is XXX , lower nibble is B
-                d2 = camera.ReadOneByte() ; // upper nibble is G   , lower nibble is R
-                b = (d1 & 0x0F) ;
-                g = (d2 & 0xF0) >> 4 ;
-                r = (d2 & 0x0F) ;
-                pc.printf ("%1X%1X%1X",r,g,b) ;
-    
-                // Calculate colour
-                colour = r << 11;
-                colour += g << 5;
-                colour += b;
-                
-                // Display pixel on TFT screen
-                TFT.pixel(x, y, colour);
-            }
-            pc.printf("\r\n") ;
-        }
-        camera.ReadStop() ;
+        // Use this time to display the image on the screen
+        // Display the top half
+        TFT.Bitmap(0,0,160,60,bank1);
+        // Display the bottom half
+        TFT.Bitmap(0,60,160,60,bank0);
+        
+        /* Note: we still have around 15ms left here to do other stuff */
+        
+        // Now wait for the image to finish being captured
+        while (camera.CaptureDone() == false) ;
     }
 }