camera_capture.ino

Arduino Nicla Vision · File : camera_capture.ino · Language : Arduino · Use case : Capturer une image avec la caméra GC2145

The Nicla Vision GC2145 2 MP camera captures QVGA greyscale through the core Camera library: this sketch computes each image mean brightness — a digital eye to track room light or seed embedded vision (Edge Impulse).

Hardware

An Arduino Nicla Vision (STM32H7 M7+M4, 23×23 mm) with GC2145 camera, LSM6DSOX IMU, PDM mic, ToF (VL53Lx), ESP32 Wi-Fi/BLE module and RGB LED (LEDR/G/B). The board alone; the GC2145 sits on the front with its FPC connector. 8 MB on-board PSRAM holds the frames.

Wiring

No wiring: the camera hangs off the internal parallel DCMI bus. Docs-db confirms GC2145 (not HM01B0, which belongs to other boards).

How it works

cam.begin(CAMERA_R320x240, GREYSCALE, 20) sets the sensor to 320×240 grey at ~20 fps; grabFrame fills the PSRAM buffer; averaging the grey bytes yields luminance, enough for a day/night threshold.

Running it

Programmed from the Arduino IDE (ArduinoCore-mbed, NICLA_VISION target) over USB-C; Camera, PDM, Arduino_LSM6DSOX, WiFiNINA and ArduinoBLE libraries provided.

Variants

Switch to RGB565 for color, JPEG the frame over the NINA Wi-Fi, or attach a TinyML model (Edge Impulse) for object recognition.

camera_capture.ino

// Caméra GC2145 2 MP embarquée : capture QVGA noir & blanc,
// puis luminosité moyenne de l'image (détection jour/nuit).
// Bibliothèque Camera du core ArduinoCore-mbed (Nicla Vision).

#include "Camera.h"

#define LARGEUR 320
#define HAUTEUR 240

Camera cam;
uint8_t *image;

void setup() {
  Serial.begin(115200);
  if (!cam.begin(CAMERA_R320x240, GREYSCALE, 20)) {
    Serial.println("Caméra GC2145 absente");
    while (1) { ; }
  }
  image = (uint8_t *)psram::malloc(cam.frameSize());
}

void loop() {
  if (cam.grabFrame(image) == 0) {
    // Luminosité moyenne = moyenne des pixels gris 0-255
    uint32_t somme = 0;
    for (uint32_t i = 0; i < cam.frameSize(); i++) {
      somme += image[i];
    }
    uint8_t moyenne = somme / cam.frameSize();
    Serial.print("luminosite moyenne = ");
    Serial.println(moyenne);
    // image[] contient la trame brute : la traiter ou la transmettre
  } else {
    Serial.println("Capture échouée");
  }
  delay(1000);
}

← Back to the board