🛠 Capturer une image avec la caméra GC2145 (DCMI)
Objectives
Initialize the embedded 2 Mpx GalaxyCore GC2145 color camera, capture QVGA 320×240 images in RGB565 format via the STM32H747 parallel DCMI bus, and stream them over USB.
Hardware
- Arduino Nicla Vision (integrated GC2145 sensor — not the Himax HM01B0, which is reserved for other boards)
- "Arduino Mbed OS Nicla Boards" core (the Camera library is provided with the core, not as a separate repository)
- PC with a raw RGB565 image viewer (e.g., the official Processing sketch CameraRawBytesVisualizer)
- Key constraint: resolutions above 320×240 require external RAM (SDRAM), which the Nicla Vision does NOT have — stay at QVGA
Complete code
// Adapte de l'exemple officiel CameraCaptureRawBytes (ArduinoCore-mbed)
#include "camera.h"
#include "gc2145.h"
GC2145 galaxyCore; // capteur couleur 2MP embarque
Camera cam(galaxyCore); // API Camera commune
#define IMAGE_MODE CAMERA_RGB565
FrameBuffer fb; // tampon par defaut 320x240x2
void blinkLED(uint32_t count) {
pinMode(LED_BUILTIN, OUTPUT);
while (count--) { digitalWrite(LED_BUILTIN, LOW); delay(50);
digitalWrite(LED_BUILTIN, HIGH); delay(50); }
}
void setup {
// QVGA 30 FPS ; clignotement infini si le capteur ne repond pas
if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) blinkLED(0xFFFFFFFF);
blinkLED(5); // 5 clignotements = camera OK
}
void loop {
if (!Serial) { Serial.begin(115200); while (!Serial); }
if (cam.grabFrame(fb, 3000) == 0) // timeout 3 s
Serial.write(fb.getBuffer, cam.frameSize); // frame RGB565 brute
else
blinkLED(20); // erreur de capture
}
Expected verification
Upon upload, 5 flashes of the green LED confirm the GC2145 initialization. The viewer (Processing, RGB565 320×240 mode) displays a smooth stream. Infinite blinking from setup = the sensor is not responding on the bus (check that the core is up to date).
Common errors
- Aiming for higher than QVGA: Resolutions above 320×240 require SDRAM.h and the external RAM of a Portenta; on the Nicla Vision, the buffer fits exactly in internal RAM — otherwise, you will get allocation errors or corrupted frames.
- Corrupted frames in the viewer: Known bug (arduino/ArduinoCore-mbed#559, series/endianess); check for a high baudrate (921600 or higher) and the byte ordering mode of the viewer.
- Looking for a HM01B0 global shutter: The HM01B0/HM0360 driver in the Camera library does NOT apply to this board; here it is indeed
GC2145 galaxyCore. - Forgetting the timeout:
grabFrame(fb)without a delay can block; pass 3000 ms as shown above. - USB Baudrate: On Mbed, the CDC often ignores the value; keep 115200 on the viewer side and limit the upstream data rate.
Other tutorials for this board
Code examples for this board
led_rgb.inoArduinoimu_lsm6dsox.inoArduinotof_distance.inoArduinomicro_pdm.inoArduinocamera_capture.inoArduinowifi_scan.inoArduino