GIGA R1 Camera example problem

Hi everyone,
I was trying to get the OV7670 module working with the GIGA.

I have followed the instructions in the tutorial, but when i launch the code on Processing the log shows: "Connection timed out" and an empty window shows up.

Running the serial monitor on the IDE shows that there is data being sent from the GIGA every 2 seconds, as per sketch.
If it has any sense, I still have to find out.

Has anyone had this problem before and know how to solve it?

Thanks in advance :slight_smile:

1 Like

Hi, make sure to select correct port, and correct baud rate. And also if you are sending RGB data, you have to set usegrayscale to false, if not to true

Thanks for the prompt reply, the problem was indeed "usegrayscale".

Now Processing and the board can talk, but I have found another problem.....
The camera seems to have issues with the syncs.

The module that I am using has a resolution of 640x480, so I had to change some things in both Arduino and Processing, but still the image is all over the place.

For reference, you can find the code attached, I might have missed somethin important since I am not very familiar with the library :sweat_smile:

#include "camera.h"
#include "SDRAM.h"

#ifdef ARDUINO_NICLA_VISION
  #include "gc2145.h"
  GC2145 galaxyCore;
  Camera cam(galaxyCore);
  #define IMAGE_MODE CAMERA_RGB565

#elif defined(ARDUINO_PORTENTA_H7_M7)
  #include "hm0360.h"
  HM0360 himax;
  Camera cam(himax);
  #define IMAGE_MODE CAMERA_GRAYSCALE

#elif defined(ARDUINO_GIGA)
  #include "ov767x.h"
  // uncomment the correct camera in use
  OV7670 ov767x;
  // OV7675 ov767x;
  Camera cam(ov767x);
  #define IMAGE_MODE CAMERA_RGB565
#else

#error "This board is unsupported."
#endif

FrameBuffer fb(SDRAM_START_ADDRESS);
//FrameBuffer fb;

unsigned long lastUpdate = 0;

void blinkLED(uint32_t count)
{
  pinMode(86, OUTPUT);
  while (count--) {
    digitalWrite(86, LOW);  // turn the LED on (HIGH is the voltage level)
    delay(50);                       // wait for a second
    digitalWrite(86, HIGH); // turn the LED off by making the voltage LOW
    delay(50);                       // wait for a second
  }
}

void blinkLED2(uint32_t count){
  pinMode(88, OUTPUT);
  while (count--) {
    digitalWrite(88, LOW);  // turn the LED on (HIGH is the voltage level)
    delay(50);                       // wait for a second
    digitalWrite(88, HIGH); // turn the LED off by making the voltage LOW
    delay(50);                       // wait for a second
  }
}

void blinkLED3(uint32_t count){
    pinMode(87, OUTPUT);
    while (count--) {
      digitalWrite(87, LOW);  // turn the LED on (HIGH is the voltage level)
      delay(50);                       // wait for a second
      digitalWrite(87, HIGH); // turn the LED off by making the voltage LOW
      delay(50);                       // wait for a second
    }
}

void setup() {
  SDRAM.begin();
  // Init the cam QVGA, 30FPS
  if (!cam.begin(CAMERA_R640x480, IMAGE_MODE, 30)) {
    blinkLED2(1);
  }
  blinkLED2(5);
}

void loop() {
  if(!Serial) {    
    Serial.begin(921600);
    while(!Serial);
  }

  if(Serial.available()){
    blinkLED3(2)    
;  }
  // Time out after 2 seconds and send new data
  bool timeoutDetected = millis() - lastUpdate > 2000;
  
  // Wait for sync byte.
  if(!timeoutDetected && Serial.read() != 1) return;  

  lastUpdate = millis();
  
  // Grab frame and write to serial
  if (cam.grabFrame(fb, 3000) == 0) {
    Serial.write(fb.getBuffer(), cam.frameSize());
    blinkLED2(2);    
  } 
  
  else {
    blinkLED(20);
  }
}

In some cases using high resolutions you may have to increase delay
Especially with rgb565 at full resolution

Are you talking about the timeout in the sketch?

I tried to follow your advise and increased it up to 10000, still the problem appears.

It seems like Vsync and Hsync are not functioning like they should, or the data is not sent correctly out if the board.....

Do you have the resolutions set to the same in both arduino sketch and the app for viewing?

Yes, both in Arduino:
!cam.begin(CAMERA_R640x480, IMAGE_MODE, 30)

and Processing:

final int cameraWidth = 640;
final int cameraHeight = 480;

I've also enabled Sdram on the Giga as per the Sketch suggestion when using resolution above 320x240.

That is weird. Can you send a photo of your camera module? Mine works.

Sorry for the delay.
My module is the one from AZDelivery, this is the Amazon page of the product: https://www.amazon.it/dp/B0797QDDPJ?ref=ppx_yo2ov_dt_b_product_details&th=1

Oh, hmm, I have the exact same looking one.
Try lower resolution with grayscale mode if it works

I tried what you suggested, but the problem still persists....

I will try to run the module on another board, just to see if its working or not.

Thanks again for your help.

1 Like

In case itโ€™s still broken, I can send you my exact code today so you can try it, just not with my computer right now, so will take a second

Might as well try it
Send it over when you have time, I am not in a hurry.

1 Like

This is my code:

#include "camera.h"
#include "SDRAM.h"

//#define Resolution OV5640



#ifdef ARDUINO_NICLA_VISION
  #include "gc2145.h"
  GC2145 galaxyCore;
  Camera cam(galaxyCore);
  #define IMAGE_MODE CAMERA_RGB565
#elif defined(ARDUINO_PORTENTA_H7_M7)
  #include "hm0360.h"
  HM0360 himax;
  Camera cam(himax);
  #define IMAGE_MODE CAMERA_GRAYSCALE
#elif defined(ARDUINO_GIGA)
  #include "ov767x.h"
  // uncomment the correct camera in use
  OV7670 ov767x;
  // OV7675 ov767x;
  Camera cam(ov767x);
  #define IMAGE_MODE CAMERA_RGB565
#else
#error "This board is unsupported."
#endif

/*
Other buffer instantiation options:
  FrameBuffer fb(0x30000000);
  FrameBuffer fb(320,240,2);

If resolution higher than 320x240 is required, please use external RAM via
  #include "SDRAM.h"
  FrameBuffer fb(SDRAM_START_ADDRESS);
  ...
  // and adding in setup()
  SDRAM.begin();
*/
FrameBuffer fb(SDRAM_START_ADDRESS);

unsigned long lastUpdate = 0;


void blinkLED(uint32_t count = 0xFFFFFFFF)
{
  pinMode(LED_BUILTIN, OUTPUT);
  while (count--) {
    digitalWrite(LED_BUILTIN, LOW);  // turn the LED on (HIGH is the voltage level)
    delay(50);                       // wait for a second
    digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW
    delay(50);                       // wait for a second
  }
}

void setup() {
  // Init the cam QVGA, 30FPS

    SDRAM.begin();

  if (!cam.begin(CAMERA_R640x480, CAMERA_RGB565, 15)) {
    blinkLED();
  }

  blinkLED(5);
}

void loop() {
  if(!Serial) {    
    Serial.begin(2000000);
    while(!Serial);
  }

  // Time out after 2 seconds and send new data
  bool timeoutDetected = millis() - lastUpdate > 10000;
  
  // Wait for sync byte.
  if(!timeoutDetected && Serial.read() != 1) return;  

  lastUpdate = millis();
  
  // Grab frame and write to serial
  if (cam.grabFrame(fb, 3000) == 0) {
    Serial.write(fb.getBuffer(), cam.frameSize());
  } else {
    blinkLED(20);
  }
}

@ludo_viero I have a camera module similar to yours, and I am also having trouble with it on the Giga. My images have similar artifacts. I have two modules and they both do the same. So between my two and yours, I think the chance of defective hardware seems low.

I tried the code from @bexin, but it has no change on the image.

Currently, I am digging through the libraries because I'm starting to suspect Vsync and Hsync are on the wrong pins.

Hey! the issue with many hardware things like this is the Arduino team as of now has the wrong clock speed values for the chip, this is having a lot of issues with IO for many users. If using the M4 core create your own timers and use them in your own IO code to read/write :slight_smile: I had the same issue when using the M4 core for a camera for my drone, its working fine now.

PS take bexins code and modify it so that you use SDRAM4 space and things will run much smoother. Refer to STM32 documentation for more of an explanation.

Also you can write your own library to run the camera in less than 200 lines of code, its mostly memory related code. The module does most of the heavy lifting for you already.

If using the M4 core

Unless the Arduino example is using the M4 core, I am not.

PS take bexins code and modify it so that you use SDRAM4 space and things will run much smoother.

I did, there is no change in behavior. This does not appear to be an RAM issue.

I imagined it was a timing problem, since the artefacts appeared similar to the ones I saw on old computers when the video syncs weren't correct and the image kept shifting.

Now, is it possible to add code to the sketch / editing the library to fix the issue?

I'm talking not just for myself, but for people who are experiencing the problem now and a possible person who down the road will experience the same problem as us.

The weird thing would be, if itโ€™s a timing problem why does it work for some of me. Iโ€™ll send the code I have for the app, maybe itโ€™s something different there.

That would be great, but I doubt you modified something important from the template used in the tutorial.

Don't even think it would be a problem with Processing's version or drives for the board, although I can test the former by downloading an older version of the program and see if it works.