How to Connect OV7670 to Arduino Due




Introduction: How to Connect OV7670 to Arduino Due

This instruction is a quick translation for an instruction in Russian available at

Connection of OV7670 to Arduino Due is easier than to Arduino Uno: lower operation voltage - only 3V, higher internal speed, more memory and more contacts on the board.

Step 1: Schema to Connect OV7670 to Arduino Due

Let's start from connecting wires. Schema is available on the picture. You do not need any resistors. Operation voltage on Arduino Due is 3V. It is optimal for OV7670.

Step 2: Genering Clock Signal

After valid connection we need to get clock signal more than 8MHz. It is easy to get 10.5MHz.

int32_t mask_PWM_pin = digitalPinToBitMask(7);

REG_PMC_PCER1 = 1<<4; // activate clock for PWM controller

REG_PIOC_PDR |= mask_PWM_pin; // activate peripheral functions for pin (disables all PIO functionality)

REG_PIOC_ABSR |= mask_PWM_pin; // choose peripheral option

BREG_PWM_CLK = 0; // choose clock rate, 0 -> full MCLK as reference 84MHz

REG_PWM_CMR6 = 0<<9; // select clock and polarity for PWM channel (pin7) -> (CPOL = 0)

REG_PWM_CPRD6 = 8; // initialize PWM period -> T = value/84MHz (value: up to 16bit), value=8 -> 10.5MHz

REG_PWM_CDTY6 = 4; // initialize duty cycle, REG_PWM_CPRD6 / value = duty cycle, for 8/4 = 50%

REG_PWM_ENA = 1<<6; // enable PWM on PWM channel (pin 7 = PWML6)

Step 3: Configuring Register of OV7670

After generating clock signal we need to write proper values to registers of OV7670. You need to use 0x21 as address since TWI interface support 7bit addresses. It allows to write register, but reading will be with issues.

void write(uint8_t regID, byte regDat){


Wire.write(regID & 0x00FF);

Wire.write(regDat & 0x00FF);


Serial.print("error write reg ");





values for register you will find later in the source code.

Step 4: Transmitting an Image

After generating clock signal and writing register we need to transmit image. Arduino Due provides UART interface for that purpose.




it is better to use custom function to speedup transmission.

static inline int uart_putchar(const uint8_t c) {



return 0;


We can try to prevent some artifacts by using buffer inside Arduino Due. In this case we write image to buffer and only after that transmit:

static void captureImg(uint16_t wg, uint16_t hg){

uint16_t y, x;


while (!(REG_PIOB_PDSR & (1 << 21)));//wait for high while

((REG_PIOB_PDSR & (1 << 21)));//wait for low

y = hg;

while (y--){

x = wg;

while (x--){

while ((REG_PIOD_PDSR & (1 << 10)));//wait for low

myImage[y][x] = (REG_PIOC_PDSR & 0xFF000) >> 12;

while (!(REG_PIOD_PDSR & (1 << 10)));//wait for high

while ((REG_PIOD_PDSR & (1 << 10)));//wait for low

while (!(REG_PIOD_PDSR & (1 << 10)));//wait for high



for (y = 0; y < hg; y++) {

for (x = 0; x < wg; x++) {





Step 5: Receiving

Now we need to receive the image. For this purpose the same java application as for example with Arduino Uno will be used.


How to run Framegrabber

How to connect OV7670 and Arduino Uno

Step 6: Results

The result you can see on the picture.

There is problem with Arduino Due: I wasn't able to get speed more that 460800, but it should not have impact on quality of the picture since it buffered.



    • Fix It! Contest

      Fix It! Contest
    • Metalworking Contest

      Metalworking Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    22 Discussions

    Hi, thanks for sharing this project. But I have problem with code, I am using with Arduino Mega.This code is suitable for Arduino Mega? Please help me((

    Here's a Matlab code I did very fast to read a picture :


    s = serial('COM17','BaudRate', 250000, 'Terminator', 'CR/LF');


    a = zeros(320,240);

    for i=1:240

    a(:,i) = fread(s,320);





    I changed the baud rate in the Arduino code.

    It's very noisy but I get a picture !!

    I encountered the following errors when compiling the sketch.

    Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Duemilanove or Diecimila, ATmega328"

    test_ov7670.ino: In function 'void setup()':
    test_ov7670:503: error: 'REG_PMC_PCER1' was not declared in this scope
    test_ov7670:504: error: 'REG_PIOC_PDR' was not declared in this scope
    test_ov7670:505: error: 'REG_PIOC_ABSR' was not declared in this scope
    test_ov7670:506: error: 'REG_PWM_CLK' was not declared in this scope
    test_ov7670:507: error: 'REG_PWM_CMR6' was not declared in this scope
    test_ov7670:508: error: 'REG_PWM_CPRD6' was not declared in this scope
    test_ov7670:509: error: 'REG_PWM_CDTY6' was not declared in this scope
    test_ov7670:510: error: 'REG_PWM_ENA' was not declared in this scope
    test_ov7670.ino: In function 'void captureImg(uint16_t, uint16_t)':
    test_ov7670:528: error: 'REG_PIOB_PDSR' was not declared in this scope
    test_ov7670:529: error: 'REG_PIOB_PDSR' was not declared in this scope
    test_ov7670:535: error: 'REG_PIOD_PDSR' was not declared in this scope
    test_ov7670:536: error: 'REG_PIOC_PDSR' was not declared in this scope
    test_ov7670:537: error: 'REG_PIOD_PDSR' was not declared in this scope
    test_ov7670:538: error: 'REG_PIOD_PDSR' was not declared in this scope
    test_ov7670:539: error: 'REG_PIOD_PDSR' was not declared in this scope
    test_ov7670.ino: In function 'int uart_putchar(uint8_t)':
    test_ov7670:564: error: 'UART' was not declared in this scope
    test_ov7670:564: error: 'UART_SR_TXRDY' was not declared in this scope
    test_ov7670:565: error: 'UART' was not declared in this scope
    'REG_PMC_PCER1' was not declared in this scope

    Please advise. Thanks

    1 more answer


    It looks like you are compiling the code for the atmega328, the processor in the uno. This code is specific to the processor on the arduino due, the SAM3X8E.

    Make sure that the IDE is set to the arduino due. If it doesn't show up, add it via the boards manager.

    I take the picture but it not clear , how I make it clear . Please help me

    1 reply

    Why is this Only in Black-and-White ?

    - As your Image example, same on my Camera...

    The Registers look correct.

    How to get it in Color ... ???


    1 year ago

    Here's a simpler Frame Grabber written in Processing. Processing has Serial and Image processing built-in. You have to download the Processing IDE. Here's the source code to the Processing Frame Grabber:


    1 year ago

    nice tutorial,pls ineed your help o the project am working using arduino mega with ov 7670 ,the camera snaps the picture and saves it on sd card behind the tft display and the tft displays the image on the memory card

    2 replies

    Hey Buddy! I'm working on exact same project and I'm using arduino mega with ov7670 camera to capture image and save it on sd card.....did you find any tutorials or code or libraries anything....If you did then please give me the link.....I'm really in need.

    Sorry. I didn't try with mega - it is as fast as Uno. No sence.


    1 year ago

    Due is on port 26, after run eclipse project, console shows:
    Port name: COM1

    Port name: COM26

    Looking for image
    Please help !!!

    1 reply

    1 year ago

    after run eclipse project, where will be frames shown?

    1 reply

    I am getting error while generating Clocl Signal

    REG-PMC_PCER1 was not declared in this scope

    Do you have an Arduino Due code monochromatic at the lowest resolution for this Camera?

    That's a great work and i have a question about this projec how can i save picture to sd card with button ??is it possible??

    Thanks for sharing nice tutorial. can it work on a uno or a mega?

    1 reply