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?
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
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
#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);
}
}
#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.
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 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.
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.