Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Backup of some arduino code to handle OV7670
#define SIO_C 2
#define SIO_D 4
#define SIO_CLOCK_DELAY 100
void setup()
{
pinMode(8,OUTPUT);
// while(1)
// {
// digitalWrite(8,HIGH);
// delayMicroseconds(SIO_CLOCK_DELAY);
// digitalWrite(8,LOW);
// delayMicroseconds(SIO_CLOCK_DELAY);
// }
Serial.begin(9600);
Serial.println("Start InitOV7670 test program");
digitalWrite(8,HIGH);delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(8,LOW);delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(8,HIGH);delayMicroseconds(SIO_CLOCK_DELAY);
if(InitOV7670())
Serial.println("InitOV7670 OK");
else
Serial.println("InitOV7670 NG");
}
void loop()
{
}
void InitSCCB(void) //SCCB初期化
{
pinMode(SIO_C,OUTPUT);
pinMode(SIO_D,OUTPUT);
digitalWrite(SIO_C,HIGH);
digitalWrite(SIO_D,HIGH);
Serial.println("InitSCCB - PortDirectionSet & Set High OK");
}
void StartSCCB(void) //SCCBスタート
{
Serial.println("StartSCCB");
digitalWrite(SIO_D,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_D,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
}
void StopSCCB(void) //SCCBストップ
{
//Serial.println("StopSCCB");
digitalWrite(SIO_D,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_D,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
}
char SCCBWrite(byte m_data)
{
unsigned char j,tem;
//Serial.print("SCCBWrite 0x");
//Serial.println(m_data,HEX);
//Serial.print("SCCBWrite");
for(j=0;j<8;j++) //循环8次发送数据
{
if((m_data<<j)&0x80)
{
digitalWrite(SIO_D,HIGH);
}
else
{
digitalWrite(SIO_D,LOW);
}
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
}
//Serial.println("");
//delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(8,LOW); //debug
pinMode(SIO_D,INPUT); //SIO_Dのバスをスレーブ(OV7670)に渡す
digitalWrite(SIO_D,LOW); //プルアップ防止
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(8,HIGH); //debug
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
//Serial.println(" Write done");
digitalWrite(8,LOW); //debug
if(digitalRead(SIO_D)==HIGH)
{
//SIO_D=Hなら失敗
tem=0;
Serial.println("SCCBWrite NG");
}
else
{
//SIO_D=Lなら成功
tem=1;
//Serial.println("SCCBWrite OK");
}
digitalWrite(SIO_C,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
pinMode(SIO_D,OUTPUT); //SIO_Dのバスをマスター(Arduino)に戻す
//delayMicroseconds(SIO_CLOCK_DELAY);
//digitalWrite(SIO_D,LOW);
//delayMicroseconds(SIO_CLOCK_DELAY);
//pinMode(SIO_C,OUTPUT); //SIO_Cのバスをマスター(Arduino)に戻す
return tem;
}
int InitOV7670(void)
{
char temp;
int i=0;
InitSCCB();
temp=0x80;
if(WriteOV7670(0x12, temp)==0) //Reset SCCB
{
Serial.println("Resetting SCCB NG");
return 0 ;
}
//Serial.println("Resetting SCCB OK");
//delayMicroseconds(10);
// for(i=0;i<CHANGE_REG_NUM;i++)
// {
// if( 0==wrOV7670Reg(pgm_read_byte( &change_reg[i][0]),pgm_read_byte( &change_reg[i][1]) ))
// {
// return 0;
// }
// }
return 0x01; //ok
}
////////////////////////////
//機能:OV7660レジスタに書き込む
//返値:成功=1 失敗=0
int WriteOV7670(char regID, char regDat)
{
StartSCCB();
if(SCCBWrite(0x42)==0)
{
Serial.println(" Write Error 0x42");
StopSCCB();
return(0);
}
delayMicroseconds(SIO_CLOCK_DELAY);
if(SCCBWrite(regID)==0)
{
StopSCCB();
return(0);
}
delayMicroseconds(SIO_CLOCK_DELAY);
if(SCCBWrite(regDat)==0)
{
StopSCCB();
return(0);
}
StopSCCB();
return(1);
}

zvika commented Dec 17, 2012

Hi! did you manage to activate the OV7670 from an Arduino? I am looking for a way to get pictures onto an SD card. Thanks!

iWayne commented Apr 22, 2013

So could you tell me how to connect 0v7670 to Arduino Uno?

I am just starting out with this camera. After looking over your code, I assume you are using pins 2 and 4 for data and clock for the IO pins on the camera. Am I correct that pin 8 appears to generate a 10mhz XCLK signal for the module? Also, does this sketch simply initialize the camera and it's registers or does it handle the D0 thru D7 parallel data pins as well?

It works!!
After over 100+hrs of squeezing life out of this camera, today for once, I get an 'InitOV7670 OK'! Next step, raw pixel data... (I also love how clean and easy your code is to follow - arigato)

lahsen commented Jun 12, 2014

Hello,
Is there any tutorial witch can help me to make connection Arduino and this camera and their code?.

Thank You very macht...

Hey guys do you have any expample with this library? Otherwise we have to go through all the code.
Thanks

hello all, can you help me on OV7670 camera interface with Arduino?
Please give me reference this it.
Can give me send my email. slamet.rianto@live.com
thanks you very much

Near32 commented Jul 22, 2014

Hello everyone,
Has anybody tried to implement the ReadOV7670 function and ReadSCCB ?
I am having issue with the first writing of 0x43 on the SCCB :
https://gist.github.com/Near32/225cdca19ad55c6d8306

The rest of it seems to be working fine...
By the way, thank you very much, I might have not gotten that far without this starting code..

Why bitbang when the hardware i2c works just fine? I have a few examples that you can check out that use the avr's hardware i2c. The code is simpler.

Hi,
i want to interface arduino with camera and then want to save the taken picture on SD card. Can anyone help me out in this regards ?

Thanks

Owner

freespace commented Sep 26, 2014

Oh boy... I completely forgot about this.

This is NOT MY CODE. I found it on the Internet randomly, and felt it should be backed up somewhere, so I put it here so it doesn't disappear into the memory hole.

I am very happy for those that have managed to get it to work, and I can't help anyone having trouble with it because I don't have one of these modules any more. Sorry!

Ne0ratek commented Nov 2, 2014

hello,

I would use your code because i find it good, but i have a electronical problem..
Please can you give me a diagram of the electrical system required.

thanks.
Ne0ratek

Shagas commented Jul 20, 2015

What voltages are you guys using on the Arduino? The OV7670 IO voltages are rated at 3V max (uno,nano etc). In my opinion this will only work on a Due Arduino because the avr is just way too slow.

Can you give me a full code about interface between ov7670 and Uno R3 or Mega2560. (and wiring circuit please) Thanks!

Can you give me a full code about interface between ov7670
. (and wiring circuit please) Thanks!

hello all, can you help me on OV7670 camera interface with Arduino?

hi i dont know a bout interface ov7670 and arduino uno? mail: azadehasadi27@gmail.com

TekuConcept, could you tell me how you did it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment