🛠 Diffuser des images JPEG depuis le Nicla Vision

Arduino Nicla Vision · intermediaire · Schéma : IMG-nicla-vision-intermediaire-2-niclavision-streaming-jpeg.svg — chaîne de diffusion : caméra GC2145, conversion RGB565 vers JPEG sur le PC hôte, navigateur affichant une image JPEG

Objectives

Transform QVGA captures from the Nicla Vision into usable JPEG images: either via embedded software encoding, or (recommended) by streaming raw RGB565 and encoding the JPEG on the host PC.

Hardware

Complete code

// Trame RGB565 + en-tete binaire pour que l'hote encode le JPEG
// Hote Python : numpy + Pillow -> Image.frombytes("RGB", (320,240), data)
#include "camera.h"
#include "gc2145.h"

GC2145 galaxyCore;
Camera cam(galaxyCore);
FrameBuffer fb;
const uint8_t MAGIC[4] = {0xAA, 0x55, 0x01, 0x01}; // magic+version

void setup {
  Serial.begin(2000000);
  if (!cam.begin(CAMERA_R320x240, CAMERA_RGB565, 15)) { // 15 FPS = marge USB
    pinMode(LED_BUILTIN, OUTPUT);
    while (true) { digitalWrite(LED_BUILTIN, LOW); delay(100);
                   digitalWrite(LED_BUILTIN, HIGH); delay(100); }
  }
}

void loop {
  if (cam.grabFrame(fb, 3000) != 0) return;
  Serial.write(MAGIC, 4);                        // synchronisation trame
  Serial.write(fb.getBuffer, cam.frameSize); // 320*240*2 = 153600 o
}

On the host side, read 4 bytes of magic, then 153600 bytes, convert RGB565 → RGB888, and use img.save("frame.jpg", quality=85) to obtain a JPEG.

Expected verification

The host script writes ~15 JPEG/s to a folder or serves them on an HTTP port; images are sharp in QVGA. If frames are missing, lower the camera FPS before touching the serial throughput.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials