I'm trying to use the GC2145 camera with the GIGA R1 following the tutorial here: https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-camera/, and I keep receiving errors associated with the gc2145.h file. I've manually found it within the arducam_dvp library, but for some reason I keep getting the "Compilation error: gc2145.h: no such file or directory" error. Any ideas on why this is happening, or how to fix it?
I have no idea, since that #include directive is only enabled when you are compiling for a Nicla Vision board:
#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 "ov7670.h"
OV7670 ov7670;
Camera cam(ov7670);
#define IMAGE_MODE CAMERA_RGB565
#else
#error "This board is unsupported."
#endif
However, the code in the tutorial is indeed broken (but in a way that will produce an error about ov7670.h when compiling for the GIGA R1 WiFi board, not about gc2145.h).
Use the more well maintained example sketch that is available from Arduino IDE instead of the outdated version of the sketch from the tutorial.
Select File > Examples > Camera > CameraCaptureRawBytes from the Arduino IDE menus. The "CameraCaptureRawBytes" sketch will open in a new Arduino IDE window. Now try compiling or uploading that sketch. Hopefully this time everything will work as expected.
Even though the code was bad, you can probably still use the informational content in the tutorial, and hopefully the Processing sketch as well.
Thanks for the response! I've modified the code from the tutorial with the example built into Arduino IDE, but I still receive the same error when I try to compile. This is the code I'm working with:
#include "camera.h"
#include "gc2145.h"
GC2145 galaxyCore;
Camera cam(galaxyCore);
#define IMAGE_MODE CAMERA_RGB565
FrameBuffer fb;
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
if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) {
blinkLED();
}
blinkLED(5);
}
void loop() {
if(!Serial) {
Serial.begin(115200);
while(!Serial);
}
// Time out after 2 seconds, which sets the (constant) frame rate
bool timeoutDetected = millis() - lastUpdate > 2000;
// Wait for sync byte and timeout
// Notice that this order must be kept, or the sync bytes will be
// consumed prematurely
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);
}
}
It just seems peculiar that the only issue is with the one gc2145.h file!
I'm having this issue as well. I tried resolving it with the following code changes but still received "No such file or directory" Errors. I also tried using each of the commented libraries.
#include "camera.h"
#include "gc2145.h"
//#include "GC2145.h"
//#include "arducam_dvp.h"
GC2145 galaxyCore;
Camera cam(galaxyCore);
#define IMAGE_MODE CAMERA_RGB565
FrameBuffer fb;
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
if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) {
blinkLED();
}
blinkLED(5);
}
void loop() {
if(!Serial) {
Serial.begin(115200);
while(!Serial);
}
// Time out after 2 seconds, which sets the (constant) frame rate
bool timeoutDetected = millis() - lastUpdate > 2000;
// Wait for sync byte and timeout
// Notice that this order must be kept, or the sync bytes will be
// consumed prematurely
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);
}
}
The "GC2145" library installation is only accessible when you are using a Nicla Vision board. It is not accessible when you are using a GIGA R1 WiFi board. So this result is expected.
There is some information here from a community member about using the GC2145 module with the GIGA R1 WiFi board:
They are using the 3rd party "arducam_dvp" library, which you can install via the Arduino IDE Library Manager
When I include the arducam_dvp library, I get another error message that says "GC2145 does not name a type"
#include "camera.h"
#include "arducam_dvp.h"
GC2145 galaxyCore;
Camera cam(galaxyCore);
#define IMAGE_MODE CAMERA_RGB565
FrameBuffer fb;
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
}
}
Now add this line after the line with the #include directive for arducam_dvp.h:
#include <GC2145/gc2145.h>
The "arducam_dvp" library comes with an example sketch that demonstrates the usage of the library. You can open it by selecting File > Examples > arducam_dvp > CameraCaptureRawBytes from the Arduino IDE menus.
Thank you. This is great! I have now uploaded the code to my Arduino; however, when I upload the next bit of code provided by Arduino to Processing, I am seeing a blank grey screen and a connection timed out error.
/*
Use with the Examples -> CameraCaptureRawBytes Arduino sketch.
This example code is in the public domain.
*/
import processing.serial.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Serial myPort;
// must match resolution used in the Arduino sketch
final int cameraWidth = 320;
final int cameraHeight = 240;
// Must match the image mode in the Arduino sketch
final boolean useGrayScale = false;
// Must match the baud rate in the Arduino sketch
final int baudRate = 115200;
final int cameraBytesPerPixel = useGrayScale ? 1 : 2;
final int cameraPixelCount = cameraWidth * cameraHeight;
final int bytesPerFrame = cameraPixelCount * cameraBytesPerPixel;
final int timeout = int((bytesPerFrame / float(baudRate / 10)) * 1000 * 2); // Twice the transfer rate
PImage myImage;
byte[] frameBuffer = new byte[bytesPerFrame];
int lastUpdate = 0;
boolean shouldRedraw = false;
void setup() {
size(640, 480);
myPort = new Serial(this, "COM5", baudRate); // Windows
// wait for a full frame of bytes
myPort.buffer(bytesPerFrame);
myImage = createImage(cameraWidth, cameraHeight, ALPHA);
// Let the Arduino sketch know we're ready to receive data
myPort.write(1);
}
void draw() {
// Time out after a few seconds and ask for new data
if(millis() - lastUpdate > timeout) {
println("Connection timed out.");
myPort.clear();
myPort.write(1);
}
if(shouldRedraw){
PImage img = myImage.copy();
img.resize(640, 480);
image(img, 0, 0);
shouldRedraw = false;
}
}
int[] convertRGB565ToRGB888(short pixelValue){
//RGB565
int r = (pixelValue >> (6+5)) & 0x01F;
int g = (pixelValue >> 5) & 0x03F;
int b = (pixelValue) & 0x01F;
//RGB888 - amplify
r <<= 3;
g <<= 2;
b <<= 3;
return new int[]{r,g,b};
}
void serialEvent(Serial myPort) {
lastUpdate = millis();
// read the received bytes
myPort.readBytes(frameBuffer);
// Access raw bytes via byte buffer
ByteBuffer bb = ByteBuffer.wrap(frameBuffer);
// Ensure proper endianness of the data for > 8 bit values.
// The 1 byte bb.get() function will always return the bytes in the correct order.
bb.order(ByteOrder.BIG_ENDIAN);
int i = 0;
while (bb.hasRemaining()) {
if(useGrayScale){
// read 8-bit pixel data
byte pixelValue = bb.get();
// set pixel color
myImage.pixels[i++] = color(Byte.toUnsignedInt(pixelValue));
} else {
// read 16-bit pixel data
int[] rgbValues = convertRGB565ToRGB888(bb.getShort());
// set pixel RGB color
myImage.pixels[i++] = color(rgbValues[0], rgbValues[1], rgbValues[2]);
}
}
myImage.updatePixels();
// Ensures that the new image data is drawn in the next draw loop
shouldRedraw = true;
// Let the Arduino sketch know we received all pixels
// and are ready for the next frame
myPort.write(1);
}
I checked that the baud rate matches the baud rate in my Arduino sketch. I also set greyscale to false and made sure that my port matches the port that I am using.
Hi all. The official "GC2145" library has now been added as a component of the "Arduino Mbed OS Giga Boards" platform:
This was released today in version 4.1.5 of the platform. So you only need to use the Arduino IDE Boards Manager to update the platform and you'll have the library all ready to use.