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:
2:4ebec58ffaca
Parent:
1:c98598814170
Child:
3:9244869157bd
--- a/main.cpp	Sat Mar 31 10:05:59 2012 +0000
+++ b/main.cpp	Wed Nov 16 10:38:37 2016 +0000
@@ -2,87 +2,110 @@
 // OV7670 + FIFO AL422B camera board test
 //
 #include "mbed.h"
-#include "ov7670.h"
-#include "stdio.h"
-#include "SPI_TFT.h"
-#include "string"
-#include "Arial12x12.h"
-#include "Arial24x23.h"
-#include "Arial28x28.h"
-#include "font_big.h"
+#include "OV7670.h"
+ #include "ST7735_TFT.h"
 
-OV7670 camera(
+OV7670 cam(
     p28,p27,       // SDA,SCL(I2C / SCCB)
-    p21,p22,p20,   // VSYNC,HREF,WEN(FIFO)
-    Port0,0x07800033,
-    p23,p24,p25) ; // RRST,OE,RCLK
+    p23,NC,p25,   // VSYNC,HREF,WEN(FIFO)
+    Port0,0x07878000,
+    p26,p29,p30) ; // RRST,OE,RCLK
 
-// the TFT is connected to SPI pin 5-7
-SPI_TFT TFT(p5, p6, p7, p8, p14,"TFT"); // mosi, miso, sclk, cs, reset
-
+ ST7735_TFT TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, rs, reset
+ 
 Serial pc(USBTX,USBRX);
 
 #define SIZEX (160)
 #define SIZEY (120)
-#define SIZE 19200
+#define SIZE SIZEX*SIZEY
 
-unsigned char bank0 [SIZE];
-unsigned char *bank1 = (unsigned char *)(0x2007C000);
+//unsigned char bank0[SIZE];
+//unsigned char *bank1 = (unsigned char *)(0x2007C000);
+unsigned char bank0,bank1,bank2,bank3;
 
 int main() {
 
+pc.baud(115200);
+
     // Set up the TFT
+    /*
     TFT.claim(stdout);                          // Send stdout to the TFT display
     TFT.background(Black);                      // Set background to black
     TFT.foreground(White);                      // Set chars to white
     TFT.cls();                                  // Clear the screen
-    TFT.set_font((unsigned char*) Arial12x12);  // Select the font
     TFT.set_orientation(3);                     // Select orientation
-
-    // Reset camera on power up
-    camera.Reset() ;
+*/
+ TFT.set_orientation(3); 
+ 
+    cam.Reset() ;
+  pc.printf("\r\nDefault\r\n");
+  int i;
+  char data1[OV7670_REGMAX],data2[OV7670_REGMAX];
+      for (i=0;i<OV7670_REGMAX;i++) 
+                    {
+                         data1[i]=cam.ReadReg(i); // READ REG
+                        //if ((i & 0x0F) == 0) pc.printf("\r\n%02X : ",i);
+                        //pc.printf("Add %02X = %02X ,",i,data);
+                    }
+    cam.InitQQVGA() ;
+     pc.printf("\r\nDefault\r\n");
+      for (i=0;i<OV7670_REGMAX;i++) 
+                    {
+                         data2[i]=cam.ReadReg(i); // READ REG
+                       // if ((i & 0x0F) == 0) pc.printf("\r\n%02X : ",i);
+                       if(data1[i]!=data2[i]) pc.printf("Add %02X = %02X/%02X ,",i,data1[i],data2[i]);
+                    }          
+        int j=0;
+        
+        //while(j<15){
+        while(1){
+    // Kick things off by capturing an image
+    cam.CaptureNext() ;
+    while (cam.CaptureDone()==0) ;
 
-    // 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) ;
-
-    // Now enter the main loop
-    while (!pc.readable()) {
-
+       pc.printf("Done %d\n",cam.CaptureDone());
+ int x=0,y=0, r=0,g=0,b=0,colour;
+          char rr,gg,bb;
         // Start reading in the image data from the camera hardware buffer                   
-        camera.ReadStart();
-
-        // Read in the first half of the image
+        cam.ReadStart();
+        
         for (int i = 0; i < SIZE; i++) {
-            bank0[i] =  camera.ReadOneByte();
-        }
+//if(i==0) cam.ReadOneByte();
 
-        // 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() ; 
+               bank0 =  cam.ReadOneByte();
+             bank1 =  cam.ReadOneByte();    
+  //bank1=0;    
+//RGB
+          
+               rr=(bank1 & 0x1f) ;
+            gg= ((bank0<<3) & 0x38) | ((bank1>>5)&0x07);
+                 b=(bank0 & 0xf8)>>3 ;
+            //444
+            /*
+            b = (bank0 & 0x0F) ;
+                g = (bank1 & 0xF0) >> 4 ;
+                r = (bank1 & 0x0F) ;
+             */
+             colour = ((r<<11)+(g<<5)+b);
+           if(i%200==0) pc.printf("RGB %d %d %d, B0 %d, B1 %d\n",rr,gg,b,bank0,bank1);
+             //  TFT.pixel(x,y,colour);
+                TFT.pixel(x,y,rr);
+                
+            x++;
+               if(i%SIZEX==0) x=0,y++;
+        } 
         
-        // Immediately request the next image to be captured (takes around 45ms)
-        camera.CaptureNext() ;
-        
-        // 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) ;
-    }
+       cam.ReadStop() ; 
+       //TFT.Bitmap(0,0,160,60,bank1);
+        //TFT.Bitmap(0,60,160,60,bank0);
+   x=0;y=0;
+       /*
+        for (int i = 0; i <= SIZE; i++) {
+         if(i==SIZEX) x=0,y++;
+             r=(bank0[i]&0xF8)>>3;
+           // TFT.pixel(x,y,bank0[i]);
+        }    
+        */
+//j++;
 }
+}
\ No newline at end of file