Go Down

Topic: ov7670 with both arduino uno and now mega (Read 116642 times) previous topic - next topic

jnshadow

Mr Arduino,

Sorry, but your grabber code on that link you reference on page 1 does not compile on Ubuntu with SDL 1.2 installed.  Here is what gcc puts out:
main.c:163:8: warning: "/*" within comment [-Wcomment]
main.c:174:4: warning: "/*" within comment [-Wcomment]
main.c:189:5: warning: "/*" within comment [-Wcomment]
main.c:203:5: warning: "/*" within comment [-Wcomment]
main.c: In function 'main':
main.c:334:2: error: too few arguments to function 'RS232_OpenComport'
rs232.h:57:5: note: declared here
main.c:349:10: warning: unused variable 'yuvDat' [-Wunused-variable]
main.c:333:1: warning: label 'tryagain' defined but not used [-Wunused-label]
main.c: In function 'clampD':
main.c:236:1: warning: control reaches end of non-void function [-Wreturn-type]
rs232.c:53:24: warning: initializer-string for array of chars is too long [enabled by default]
rs232.c:53:24: warning: (near initialization for 'comports[37]') [enabled by default]

#481
Jan 31, 2015, 11:28 pm Last Edit: Jan 31, 2015, 11:29 pm by engine_develop
Hi,

I'm not sure if this thread is still active, but I thought I would give it a try. First off, I wanted to thank those who have offered their time; it has been a great help in getting this sensor working.

I have set up the wiring as detailed in Mr_Arduino's early posts, however I can't seem to write/read registers. Calls to 'Wire.endTransmission()' always return error code 2. This is similar when using 'wrReg()' from Mr_Arduino's code. Is there anything special to do during 'setup()' to initialize the sensor?

Code: [Select]

void setup()
{
    cli(); // Disable interrupts

    // Set up I2C
    //
    Wire.begin();
    disableI2CPullups();

    // Set up TWI for 100khz
    //
    TWSR &= ~3; // Disable TWI prescaler
    TWBR = 72; // Set to 100khz

    // Set up pins
    //
    DDRB  |= B00101111 /*47*/; // Clock/SPI pins as output, MISO input
    PORTB |= B00000110 /*6*/; // Set SS pins high
    DDRC &= ~B00001111 /*15*/; // D0-D3 camera as input
    DDRD &= ~B11111100 /*252*/; // D7-D4 and interrupt pins as input

    // Enable serial
    //
    Serial.begin( 9600 );

    wrReg( REG_COM7, 0x40 ); // Fails in 'twiAddr()', with error LED


Thanks for any insight you can provide.

Kind regards,
Mark Davies

Ps: I've attached my wiring diagrams in case this helps.

...and my Fritzing file, in case that is of use :)

hello,
i have some problem with the code. can you help me sir? i use the code from "https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno" but it's not working. big thanks.


  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
ov7670\main.c.o: In function `main':
C:\Users\BLIKS_000\Documents\Arduino\libraries\ov7670/main.c:102: multiple definition of `main'
sketch_feb03a.cpp.o:C:\Program Files (x86)\Arduino/sketch_feb03a.ino:102: first defined here
sketch_feb03a.cpp.o: In function `main':
sketch_feb03a.cpp:(.text.main+0x6c): undefined reference to `camInit()'
sketch_feb03a.cpp:(.text.main+0x72): undefined reference to `setRes(unsigned char)'
sketch_feb03a.cpp:(.text.main+0x78): undefined reference to `setColor(unsigned char)'
sketch_feb03a.cpp:(.text.main+0x80): undefined reference to `wrReg(unsigned char, unsigned char)'

bigsun

hi,i have ov7670 camera module with fifo.The camera has 22 pins.
this is camera's pin schema:



And i have Arduino Mega.I want to use my camera with mega on Arduino IDE.
But i dont have any information.

Do you know connection schema and arduino code ?
Hi, subscribe to the issue . Is there any progress?

Ayad

Hello guys

I spend the last weeks with OV7670 camera to get some response with Arduino Due, but I didn't get what I want.
I used this code (https://gist.github.com/franciscospaeth/8503747) but Its didn't work, then I change it to come as:

--------------------------------------------------------------------------------------------
// pin definition
byte data_p[] = {22,23,24,25,26,27,28,29}; //Data pins
#define xclock_p 8               // XCLK pin
#define pclock_p 9               // PCLK pin
#define href_p 10                // HREF pin
#define vsync_p 11               // VSYNC pin
// not used int siod = 12;
// not used int sioc = 13;

byte pixel;

void setup()
{
    Serial.begin(9600);
    Serial.println("started");
    // configure data pins as input
    for (int i = 0; i < 8; i++) pinMode(data_p, INPUT);

    // configure rest input pins
    pinMode(xclock_p, OUTPUT);
    pinMode(pclock_p, INPUT);
    pinMode(href_p, INPUT);
    pinMode(vsync_p, INPUT);
}

unsigned long control = 0;

void loop()
{
    // just take one snapshot (307200 = 600 * 480) {{{
    if (control >= 307200)
    {
          Serial.println("control >= 307200");
          return;
    }
    // }}}

    digitalWrite(xclock_p, HIGH);

    while (digitalRead(vsync_p))  {/*Serial.println("vsync == HIGH");*/}
    while (!digitalRead(href_p))   {/*Serial.println("href == LOW");*/}
    while (digitalRead(pclock_p))  {/*Serial.println("pclock_p == HIGH");*/}

    pixel = readByteFromDataInput();
    Serial.print(pixel);
    Serial.print(" , ");

    control++;
    if (control % 640 == 0)   Serial.println();
    if (control >= 307200)    Serial.println("finished");

    while(!digitalRead(pclock_p))  {/*Serial.println("pclock_p == LOW");*/}
}

byte readByteFromDataInput()
{
    byte result = 0;
    for (int i = 0; i < 8; i++) result = result << 1 | digitalRead(data_p);
    return result;
}

-----------------------------------------------------------------------------------------------

but it also didn't work correctly. What is my code mistake?

help me

sarav15

Hi,

I am using this module OV7670 + AL422 combo. I programmed the module as given in the data sheet. But for some strange reason, the value I read from the FIFO is always the same.

Could you please help me in identifying the cause (FIFO or OV7670) and how to resolve this.

Thanks.

hello,i am working on a university project interfacing non- fifo version of ov7670 camera with arduino mega 2560 rev3.
can i use this without any external ram or fifo? if i change the clock of camera to 16mhz since it is adjustable for the synchronization with arduino?

is there any verified code already written of interfacing this no external or internal ram ov7670 with mega 2560 ? any help would be appreciated since i really need to complete my project as soon as possible

hey guys! I'm using the following code on the DUE to achieve a 20Mhz clock signal
Code: [Select]

const int pin = 8;
const int freq = 20000000;

void setup()
{
  pmc_enable_periph_clk(PWM_INTERFACE_ID);
  PWMC_ConfigureClocks(freq,0,VARIANT_MCK/2);
  PIO_Configure(g_APinDescription[pin].pPort,
  g_APinDescription[pin].ulPinType,
  g_APinDescription[pin].ulPin,
  g_APinDescription[pin].ulPinConfiguration);
  int chan = g_APinDescription[pin].ulPWMChannel;
  PWMC_ConfigureChannel(PWM_INTERFACE,chan,PWM_CMR_CPRE_CLKA,0,0);
  int divider = VARIANT_MCK/2/freq;
  PWMC_SetPeriod(PWM_INTERFACE,chan,divider);
  PWMC_SetDutyCycle(PWM_INTERFACE,chan,divider/2);
  PWMC_EnableChannel(PWM_INTERFACE,chan);
}

void loop()

}


and I get the output you can see in attachment. Do you think would work as a clock even if it is 21Mhz? (1Mhz overclocked)

Peter_n

aishacs72, the ATmega2560 has a fuse for CLKOUT.
You can find the fuses here : http://www.engbedded.com/fusecalc/

However, the pin for CLKOUT is not one of the pins of the Arduino board, as you can read here : http://www.avrfreaks.net/forum/xtal2-pin-atmega-2560

I decided to try with an 8Mhz clock to see if it work with DUE but... it doesn't!

my wiring is
3v3 -> 3v3
gnd -> gnd
scl1 -> sioc
sda1 -> siod
pin7 -> xclk

attached you can see my xclk channel and pclk (this last one wired to the scope probe only) as I see on my scope

here is the code
Code: [Select]

#include <Arduino.h>
#include <Wire.h>

#define camAddr_WR 0x42
#define camAddr_RD 0x43
#define REGISTERS       0x91        // Define # of Registesr on OV7076

const int pin = 7;
const int freq = 8 *1000000;

byte wrReg(unsigned char regID, unsigned char regDat){
Wire.beginTransmission(camAddr_WR >> 1);
Wire.write(regID);
Wire.write(regDat);
if (Wire.endTransmission()){
return 0;
while (1);
}
delay(1);
return 1;
}

void readRegisterBank()
{
uint8_t count = 0x12;
int address = 0x12;

Wire.beginTransmission(camAddr_WR);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(camAddr_RD, 1);
while (!Wire.available())
{
}
int c = Wire.read();
Serial.println(c);

//while (count<REGISTERS)
// {
byte highByte = 0;
Serial.print("\r\nRegister num: ");
Serial.print(count, HEX);
Serial.print(" val: ");
Wire.beginTransmission(camAddr_WR);          //Start communication with cmps03
Wire.write(count);                        //Send the register we wish to read
Wire.endTransmission();
Wire.requestFrom(camAddr_RD, 1);             //Request high byte
while (Wire.available() < 1);              //While there is a byte to receive
highByte = Wire.read();                   //Read the byte as an integer
Serial.print(highByte, HEX);
/*delay(25);
count++;
}*/

Serial.print("\r\nRegister num: ");
Serial.print(count, HEX);
Serial.print(" val: ");
Wire.beginTransmission(camAddr_WR);
Wire.write(count);
Wire.endTransmission();
Wire.requestFrom(camAddr_RD, 2);
byte LSB = Wire.read();
byte MSB = Wire.read();
uint16_t touched = ((MSB << 8) | LSB); //16bits that make up the touch states
Serial.print(touched);

Wire.beginTransmission((uint8_t)camAddr_WR);
Wire.write(count);
Wire.endTransmission(false);

Wire.requestFrom((uint8_t)camAddr_RD, (uint8_t)1, (uint8_t)true);

if (Wire.available() >= 1)
{
int result = Wire.read();
Serial.println(result, HEX);
}
}

void i2cScanner()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }   
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
}

void setup()
{
  pmc_enable_periph_clk(PWM_INTERFACE_ID);
  PWMC_ConfigureClocks(freq * 2,0,VARIANT_MCK); //freq * period
  PIO_Configure(g_APinDescription[pin].pPort,
    g_APinDescription[pin].ulPinType,
    g_APinDescription[pin].ulPin,
    g_APinDescription[pin].ulPinConfiguration);
  uint32_t channel = g_APinDescription[pin].ulPWMChannel;
  PWMC_ConfigureChannel(PWM_INTERFACE,channel,PWM_CMR_CPRE_CLKA,0,0);
  PWMC_SetPeriod(PWM_INTERFACE,channel,2);
  PWMC_SetDutyCycle(PWM_INTERFACE,channel,1);
  PWMC_EnableChannel(PWM_INTERFACE,channel);
  //pmc_mck_set_prescaler(2);
 
  Serial.begin(115200);
  i2cScanner();
  Wire.begin();
  Serial.print("wrReg: "); Serial.println((wrReg(0x12, 0x80)));
  delay(1000);
  readRegisterBank();
  Serial.print("here!");
}

void loop()

}


here is the output
Code: [Select]

Scanning...
No I2C devices found

wrReg: 0
0

Register num: 12 val: 0
Register num: 12 val: 00
here!


I read about i2c/twi bugs on the DUE wire lib implementation... I'm using ide 1.6.0 beta. Might this be the case? thank you!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy