OV7670 with both arduino uno and now mega

Wow! Well done! You done it wit an STM32 too!

Hello everyone,

Sorry for my little knowledge, but I have a little problem.

I started using the OV7670 camera with the arduino UNO, but not very well on the registers of the atmega 328P.

Or any command line type these:

while (! (PIND & 4));
while ((PIND & 4));
while (! (PIND & 4));

Hi,

PIND ( like PINB and PINC ) is the Port D Input Pins Register which is read only.

8 pins of your Arduino will be mapped to register D.

Port D registers control Arduino UNO digital pins 0 to 7

so 'PIND & 4' is same as 'PIND & 0000100'

it returns whether pin 2 is HIGH (or LOW).

Hello,
I'm very new to use arduino board.
I has been upload the program into arduino but the LED (13) always blinking. So I test to disconnect OV7670 module with arduino and check pin A4 and A5 was no signal (always 0).
What’s wrong?

@ bajingan

If you are running the code exactly as it is LED 13 reports I2C is not working or has errors.

However you must see 3.3V on A4 and A5 before you go forward.....

Have you done below ( copied from page 1) , if not you should.


  1. Make sure you have a 10k resistor on both A4 and A5 to pull up 3.3v not 5v.

  2. Also edit twi.c in the arduino ide folder/libraries/Wire/utility search for these lines and comment them out or remove them

// activate internal pullups for twi.
  digitalWrite(SDA, 1);
  digitalWrite(SCL, 1);

This is to remove the internel pullup resistor by not removing these 2 lines you could cause damage to the sensor,( because A4 (SDA) and A5 (SCL) will pull up to 5V).


@ jlsilicon,

THANK YOU !!!!!!

for link to

It has an RGB565 register set up set that WORKS !!!!!! (for me)

I am now sitting watching the output of the OV7670 ( my second one, first had faulty I2C )
powered by a MEGA being displayed in glorious .. muted ... colours on a 2 inch TFT.

All my other attempts were 'psychedelic' LOL !!!!!!

Oh - the joy of one frame every 13 seconds

I can not find twi.c in the arduino ide folder/libraries/Wire/utility . Whats problem with my arduino ide? How to made it?

@ bajingan

your twi.c might be in the main Arduino directory like mine was......

See attachment

I found two files twi.c and I edit both. After I compile and upload to board is same A4 and A5 nothing pulse, event I rename the twi.c my program OV7670_test.ino still can compile. Any hint?

I has been tried a simple program to use twi, I just copy

// Example 20.1

int dt = 2000; // used for delay duration
byte rval = 0x00; // used for value sent to potentiometer
#include "Wire.h"
#define pot_address 0x2F // each I2C object has a unique bus address, the MCP4018 is 0x2F or 0101111 in binary

void setup()
{
  Wire.begin();
  Serial.begin(9600); 
}

void potLoop()
// sends values of 0x00 to 0x7F to pot in order to change the resistance
// equates to 0~127
{
  for (rval=0; rval<128; rval++)
  {
    Wire.beginTransmission(pot_address);
    Wire.write(rval); // 
    Wire.endTransmission();
    Serial.print(" sent - ");
    Serial.println(rval, HEX);
    delay(dt);
  }
}

void loop()
{
  potLoop();
}

there is pulse on pin A5 and I still confuse about program test for OV7670

@ bajingan

  1. There should have been only one twi.c and one twi.h file in that directory. I am GUESSING there might be two versions of IDE installed. I would reinstall IDE and let it delete the previous installation.

Then do the twi.c edit again.

  1. Also if you have the following pins on OV7670 tie them as follows...

RST - tie to 3.3V
OE - tie to GND
PWDN - tie to GND

if you do not do above, the OV7670 will not respond.

  1. Search and download a simple sketch called I2C scanner for Arduino. it is almost like what you posted.

When you run this you should see the camera at address 0x21. I2C scanner looks for anything on the I2C bus. Until you see the OV7670 on address 0x21 I would not bother with mr-arduino code.

I have had lots of problems with I2C, my first OV7670 would not respond to standard wire library.

I test with I2Cscanner program but not found in address 0x21. I do not know or maybe my OV7670 was defect from store. I'm sure to wiring carefully... :sob:

OK I will purchase the ov7670 module one more, but I want to make a test program for my arduino board. Regarding the circuit for this project I has been measure on pin A4 and A5 with logic probe, without connected the OV7670 module

There is difference between two program OV7670_test.ino and I2Cscanner.ino
In first program no pulse in A4 & A5 pin but in second one there is pulse in both pin.
Why?

@ bajingan

Q) There is difference between two program OV7670_test.ino and I2Cscanner.ino
In first program no pulse in A4 & A5 pin but in second one there is pulse in both pin.
Why?

A) Is it that OV7670_test.ino stops if an error is seen (so you miss the pulses) and I2C scanner keeps scanning - (so you see the pulses).

One last thing - I have been assuming you have a FIFO version of OV7670 and there is no XCLK pin.

If you have the non-FIFO version it will have an XCLK pin. In this case you MUST supply at least a 8 MHz clock input. I have never done this as I only have FIFO version.

@cblx5,
I assume if error led blinking mean TWI still accessed.
Would you like to show me which program to stoping TWI?
I'm sure my ov7670 module is non fifo
Thank

Q) I assume if error led blinking mean TWI still accessed. ----- A) no !!!

See here ......

static void error_led(void){
  DDRB|=32;//make sure led is output
  while(1){//wait for reset          <<<<   BLINK FOREVER AFTER AN ERROR UNTIL ARDUINO iS RESET
    PORTB^=32;// toggle led
    _delay_ms(100);
  }
}

Q) I'm sure my ov7670 module is non fifo, A) Then OV7670 needs at least 8Mhz on XCLK for I2C to work, it is like a system clock.

Ok I understand now about the blinking led :slight_smile:
About the clock pulse I saw in program has been equipped in "arduinoUnoInut" routine, it's described about setup 8MHz PWM clock on pin 11 so I verify to checking pin 11 has pulse but I don't know the exact of frequency. In the circuit it's divided by two resistors before connected to xclock in ov7670 module. Is external clock still needed?
Thank

@cblx5
You told my about ov7670 need external clock for the system clock. I check pin 11 has clock pulse so I just thinking about the circuit. I change the divider resistors from 4k7 ohm to 680 ohm and finally I don't have blinking error and I able to read data from camera.

Thank you for helping me
Best regards

@cblx5,

Do you have some Code or Mods from the LiveOv7670 for the Mega Brd

  • that you used ?

I don't have any mods in the strictest sense , but I did have to 'glue' 3 pieces of code.

  1. see XnPlater code about 2 pages earlier, I took functions from that ( but its for a DUE).
    For my Mega, I uncommented the 'avr' lines .ie. UNO/MEGA and commented out the DUE lines.

  2. I replaced all I2C code with mr_arduino code, which I have posted about a page above. This worked quite easily with my second OV7670 (but failed with my first).

You already, in effect, have items 1 and 2 working on your mini.

  1. I then stripped out all register defs and values in my code and replaced with live0V7670 defs and values and ran in following sequence....
     Serial.println(F("----------------------------- Camera Default Registers ----------------------------"));
     wrSensorRegs8_8(regsDefault);
     
     Serial.println(F("----------------------------- Camera Register Set Up RGB565-----------"));
     wrSensorRegs8_8(regsRGB565);
     
     Serial.println(F("----------------------------- Camera Register Set Up QVGA -----------"));
     wrSensorRegs8_8(regsQVGA);
     
     Serial.println(F("----------------------------- Camera Register Set Up OTHER -----------"));
     //registers.setDisablePixelClockDuringBlankLines();
     //registers.setInternalClockPreScaler(internalClockPreScaler);

Note as I have a FIFO version I (luckily) commented out last two setups and it worked right away (after some syntax errors).

The whole program then ported nicely back to a DUE which was my original target... (for speed), but using SDA1 and SCL1.

All my pins are non-standard as I kept pins 22-53 unused for a UTFT compatible 16bit TFT (again for speed).