Camera Module

 Camera Module is a FIFO camera Module available from different Manufacturers with different pin Configurations. TheOV7670 provides full frame, windowed 8-bit images in a wide range of formats. The image array is capable of operating at up to 30 frames per second (fps) in VGA. The OV7670 includes

 

  • Image Sensor Array(of about 656 x 488 pixels)
  • Timing Generator
  • Analog Signal Processor
  • A/D Converters
  • Test Pattern Generator
  • Digital Signal Processor(DSP)
  • Image Scalar
  • Digital Video Port
  • LED and Strobe Flash Control Output

 

The OV7670 image sensor is controlled using Serial Camera Control Bus (SCCB) which is an I2C interface (SIOC, SIOD) with a maximum clock frequency of 400 KHz.

The Camera comes with handshaking signals such as:

 

  • VSYNC:Vertical Sync Output – Low during frame
  • HREF:Horizontal Reference – High during active pixels of row
  • PCLK:Pixel Clock Output – Free running clock. Data is valid on rising edge

 

In addition to this, it has several more signals such as

  • D0-D7:8-bit YUV/RGB Video Component Digital Output
  • PWDN:Power Down Mode Selection – Normal Mode  and Power Down Mode
  • XCLK:System Clock Input
  • Reset:Reset Signal

 

The OV7670 is clocked from a 24MHz oscillator. This gives a Pixel Clock (PCLK) output of 24MHz. The FIFO provides 3Mbps of video frame buffer memory. The test pattern generator features 8-bar color bar pattern, fade-to-gray color bar patter. Now let’s start programming the Arduino UNO for testing Camera OV7670 and grabbing frames using serial port reader

Specification:

  • VGA resolution (640 x 480)
  • QVGA (320 x 240)
  • CIF (352 x 240)
  • QCIF (176 × 144);
  • Transmission speed up to 30 fps,
  • several ways to encode the image RAW RGB, RGB 565/555, YUV / YCbCr 4: 2: 2

 

 

 

Arduino Interfacing 

Code :

#include <stdint.h>
#include <avr/io.h>
#include <util/twi.h>
#include <util/delay.h>
#include <avr/pgmspace.h>

#define F_CPU 16000000UL
#define vga   0
#define qvga  1
#define qqvga   2
#define yuv422  0
#define rgb565  1
#define bayerRGB  2
#define camAddr_WR  0x42
#define camAddr_RD  0x43

void arduinoUnoInut(void) {
  cli();//disable interrupts

    /* Setup the 8mhz PWM clock
  * This will be on pin 11*/
  DDRB |= (1 << 3);//pin 11
  ASSR &= ~(_BV(EXCLK) | _BV(AS2));
  TCCR2A = (1 << COM2A0) | (1 << WGM21) | (1 << WGM20);
  TCCR2B = (1 << WGM22) | (1 << CS20);
  OCR2A = 0;//(F_CPU)/(2*(X+1))
  DDRC &= ~15;//low d0-d3 camera
  DDRD &= ~252;//d7-d4 and interrupt pins
  _delay_ms(3000);

    //set up twi for 100khz
  TWSR &= ~3;//disable prescaler for TWI
  TWBR = 72;//set to 100khz

    //enable serial
  UBRR0H = 0;
  UBRR0L = 1;//0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud rate.
  UCSR0A |= 2;//double speed aysnc
  UCSR0B = (1 << RXEN0) | (1 << TXEN0);//Enable receiver and transmitter
  UCSR0C = 6;//async 1 stop bit 8bit char no parity bits
}

void StringPgm(const char * str){
  do{
      while (!(UCSR0A & (1 << UDRE0)));//wait for byte to transmit
      UDR0 = pgm_read_byte_near(str);
      while (!(UCSR0A & (1 << UDRE0)));//wait for byte to transmit
  } while (pgm_read_byte_near(++str));
}

static void captureImg(uint16_t wg, uint16_t hg){
  uint16_t y, x;

  StringPgm(PSTR(“*RDY*”));

  while (!(PIND & 8));//wait for high
  while ((PIND & 8));//wait for low

    y = hg;
  while (y–){
        x = wg;
      //while (!(PIND & 256));//wait for high
    while (x–){
      while ((PIND & 4));//wait for low
            UDR0 = (PINC & 15) | (PIND & 240);
          while (!(UCSR0A & (1 << UDRE0)));//wait for byte to transmit
      while (!(PIND & 4));//wait for high
      while ((PIND & 4));//wait for low
      while (!(PIND & 4));//wait for high
    }
    //  while ((PIND & 256));//wait for low
  }
    _delay_ms(100);
}

void setup(){
  arduinoUnoInut();
  camInit();
  setResolution();
  setColor();
 writeReg(0x11, 10); //Earlier it had the value:writeReg(0x11, 12); New version works better for me 🙂 !!!!
}

void loop(){
  captureImg(320, 240);
}

 

Reference:

https://www.hackster.io/techmirtz/visual-capturing-with-ov7670-on-arduino-069ebb

https://maker.pro/arduino/tutorial/how-to-interface-the-ov7670-camera-module-with-arduino

https://www.electronics-lab.com/using-ov7670-camera-sensor-arduino/

https://circuitdigest.com/microcontroller-projects/how-to-use-ov7670-camera-module-with-arduino

WhatsApp us whatsapp