Carte de caméra TTGO T-Journal ESP32 : pour commencer

Carte de caméra TTGO T-Journal ESP32 : pour commencer

Ceci est un guide de démarrage pour la carte de développement de caméra TTGO T-Journal ESP32. Le TTGO T-Journal comprend une caméra OV2640, un écran OLED, plusieurs GPIO pour connecter des périphériques et un programmeur intégré, ce qui facilite le téléchargement de code. Nous allons jeter un coup d’œil à la carte de développement de la caméra et apprendre à la programmer à l’aide de l’IDE Arduino.

Caméra TTGO T-Journal ESP32 : programmeur intégré, OLED, antenne et exemples de projets

Où acheter?

Vous pouvez aller au Page TTGO T-Journal sur Maker Advisor pour comparer la planche sur différents magasins.

Caméra TTGO T-Journal ESP32 + OLED + Antenne + Programmeur intégré

Présentation de la caméra TTGO T-Journal ESP32

le TTGO T-Journal est une carte de développement de caméra ESP32 de 12 $ à 15 $ avec une caméra OV2640, une antenne, un écran OLED I2C SSD1306 de 0,91 pouce, quelques GPIO exposés et une interface micro-USB qui facilite et accélère le téléchargement de code sur la carte.

Pour un aperçu complet de cette carte, vous pouvez regarder la vidéo suivante ou lire cet article : Examen de la carte de développement de la caméra TTGO T-Journal ESP32.

Caractéristiques du TTGO T-Journal ESP32

Voici un résumé des fonctionnalités du TTGO T-Journal :

  • Chipset ESPRESSIF-ESP32-PCIO-D4 240MHz Xtensa® microprocesseur LX6 32 bits simple/double cœur
  • FLASH QSPI flash/SRAM, jusqu’à 4 x 16 MBSRAM 520 ko SRAM
  • Bouton de réinitialisation et bouton sur GPIO 32
  • Écran OLED SSD1306 de 0,91 pouce
  • Indicateur d’alimentation LED rouge
  • USB vers TTL CP2104 (vous pouvez télécharger le code via un câble USB);
  • Appareil photo OV2640 2 mégapixels
  • Servo analogique du moteur de direction (livré avec deux jeux de broches idéales pour connecter les servos)
  • Tension de fonctionnement : 2,3 V-3,6 V
  • Courant de travail: environ 160mA
  • Taille : 64,57 mm x 23,98 mm

Spécifications de l’alimentation :

  • Alimentation USB 5V/1A
  • Courant de charge 1A
  • Batterie au lithium 3.7V

Lisez notre revue approfondie : Carte de développement de caméra TTGO T-Journal ESP32

Brochage de la carte TTGO T-Journal ESP32

Il est très important d’avoir le bon brochage pour votre carte de caméra. Si vous n’attribuez pas les bonnes broches de caméra dans votre code, la caméra ne fonctionnera pas. L’image suivante montre le brochage de la carte TTGO T-Journal ESP32.

Connexions de la caméra TTGO T-Journal ESP32

Caméra TTGO T-Journal ESP32 OV2640

Voici un tableau avec les connexions entre l’ESP32 et la caméra :

Caméra OV2640 ESP32
D2 GPIO 17
D3 GPIO 35
D4 GPIO 34
D5 GPIO 5
D6 GPIO 39
D7 GPIO 18
D8 GPIO 36
D9 GPIO 19
SIOC GPIO 23
SIOD GPIO 25
XCLK GPIO 27
VSYNC GPIO 22
HREF GPIO 26
PCLK GPIO 21
TVD GPIO 15
PWDN GPIO 0

Ainsi, l’affectation des broches dans votre croquis Arduino doit être la suivante :

#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM     27
#define SIOD_GPIO_NUM     25
#define SIOC_GPIO_NUM     23
#define Y9_GPIO_NUM       19
#define Y8_GPIO_NUM       36
#define Y7_GPIO_NUM       18
#define Y6_GPIO_NUM       39
#define Y5_GPIO_NUM       5
#define Y4_GPIO_NUM       34
#define Y3_GPIO_NUM       35
#define Y2_GPIO_NUM       17
#define VSYNC_GPIO_NUM    22
#define HREF_GPIO_NUM     26
#define PCLK_GPIO_NUM     21

Étant donné que cette carte utilise la même caméra que celle utilisée dans la carte ESP32-CAM, les exemples pour l’ESP32-CAM (qui n’utilisent pas de carte microSD) devraient également fonctionner avec le TTGO T-Journal en modifiant la définition des broches. Nous allons vous montrer quelques exemples dans un instant.

Connexions OLED de la carte TTGO T-Journal ESP32

TTGO T-Journal Carte ESP32 Connexions OLED Broches SCL SDA I2C

Cette carte est livrée avec un écran OLED I2C SSD1306 de 0,91 pouce. Pour interagir avec l’écran, vous pouvez utiliser le Adafruit SSD1306, la oled-ssd1306 ou d’autres bibliothèques compatibles. Nous utilisons généralement l’Adafruit SSD1306 avec le Adafruit_GFX pour interagir avec les écrans OLED.

L’OLED communique avec l’ESP32 à l’aide des broches suivantes :

OLED ESP32
SDA GPIO 14
SCL GPIO 13

Affichage OLED de contrôle de carte TTGO T-Journal ESP32

Dans cette section, bien vous montrer des conseils rapides sur la façon de contrôler l’affichage OLED de la carte TTGO T-Journal ESP32.

Installation des bibliothèques

Pour contrôler l’écran OLED, nous utiliserons le Adafruit SSD1306 et Adafruit GFX bibliothèques. Ces bibliothèques peuvent être installées via Arduino IDE Library Manager.

Dans votre IDE Arduino, accédez à Esquisser > Inclure la bibliothèque > Gérer les bibliothèques. Ensuite, recherchez le nom de la bibliothèque et installez-la.

Broches OLED I2C et taille d’affichage

Le contrôle de cet écran OLED est similaire au contrôle d’un écran OLED 0.96 standard connecté à un ESP32. La seule différence est la façon dont vous initialisez l’affichage.

Vous devez prendre en compte les broches I2C utilisées par cet écran (car il n’utilise pas les broches I2C par défaut) et la taille de l’écran.

  • Broches I2C :
    • SDA (GPIO 14)
    • SCL (GPIO 13)
  • Taille d’affichage :
    • Largeur : 128 pixels
    • Hauteur : 32 pixels

Esquisse Arduino

Pour contrôler l’écran OLED, vous devez d’abord importer les bibliothèques requises :

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Définissez la taille de l’OLED :

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

Définissez les broches I2C :

#define I2C_SDA 14
#define I2C_SCL 13

Créez ensuite un Adafruit_SSD1306 objet appelé affichage comme suit:

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

Dans le mettre en place(), vous devez initialiser une communication I2C sur les broches I2C que vous avez définies précédemment comme suit :

Wire.begin(I2C_SDA, I2C_SCL);

Ensuite, initialisez l’écran OLED comme suit :

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
  Serial.println(F("SSD1306 allocation failed"));
  for(;;);
}

Après avoir correctement initialisé l’affichage, vous pouvez utiliser les fonctions habituelles pour écrire du texte et afficher des formes sur l’OLED. Lisez notre didacticiel OLED avec l’ESP32 pour en savoir plus sur la façon d’interagir avec l’écran OLED.

À des fins de test, vous pouvez télécharger le code suivant sur votre tableau. Il affiche simplement « Hello World ».

/*
  Rui Santos
  Complete project details at https://Raspberryme.com/ttgo-t-journal-esp32-camera-getting-started/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define I2C_SDA 14
#define I2C_SCL 13

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  
  Wire.begin(I2C_SDA, I2C_SCL);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.print("Hello World!");;
  display.display();
}

void loop() {
  // put your main code here, to run repeatedly:
}

Afficher le code brut

TTGO T-Journal ESP32 Board Control OLED Display Exemple de message Hello World

Projets de caméra TTGO T-Journal ESP32

Nous avons modifié certains de nos projets ESP32-CAM existants pour qu’ils soient compatibles avec le TTGO T-Journal.

Serveur Web de streaming vidéo

Le code suivant crée un serveur Web de streaming vidéo sur l’adresse IP de la caméra. Ainsi, vous pouvez créer une IP CAM qui peut être intégrée dans des plateformes domotiques comme Home Assistant ou Node-RED.

/*
  Rui Santos
  Complete project details at https://Raspberryme.com/ttgo-t-journal-esp32-camera-getting-started/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include "esp_camera.h"
#include <WiFi.h>
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "fb_gfx.h"
#include "soc/soc.h" //disable brownout problems
#include "soc/rtc_cntl_reg.h"  //disable brownout problems
#include "esp_http_server.h"

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define I2C_SDA 14
#define I2C_SCL 13

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

//Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

#define PART_BOUNDARY "123456789000000000000987654321"

// OV2640 camera module pins (CAMERA_MODEL_TTGO-T-Journal)
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM     27
#define SIOD_GPIO_NUM     25
#define SIOC_GPIO_NUM     23
#define Y9_GPIO_NUM       19
#define Y8_GPIO_NUM       36
#define Y7_GPIO_NUM       18
#define Y6_GPIO_NUM       39
#define Y5_GPIO_NUM       5
#define Y4_GPIO_NUM       34
#define Y3_GPIO_NUM       35
#define Y2_GPIO_NUM       17
#define VSYNC_GPIO_NUM    22
#define HREF_GPIO_NUM     26
#define PCLK_GPIO_NUM     21

static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
static const char* _STREAM_BOUNDARY = "rn--" PART_BOUNDARY "rn";
static const char* _STREAM_PART = "Content-Type: image/jpegrnContent-Length: %urnrn";

httpd_handle_t stream_httpd = NULL;

static esp_err_t stream_handler(httpd_req_t *req){
  camera_fb_t * fb = NULL;
  esp_err_t res = ESP_OK;
  size_t _jpg_buf_len = 0;
  uint8_t * _jpg_buf = NULL;
  char * part_buf[64];

  res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
  if(res != ESP_OK){
    return res;
  }

  while(true){
    fb = esp_camera_fb_get();
    if (!fb) {
      Serial.println("Camera capture failed");
      res = ESP_FAIL;
    } else {
      if(fb->width > 400){
        if(fb->format != PIXFORMAT_JPEG){
          bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len);
          esp_camera_fb_return(fb);
          fb = NULL;
          if(!jpeg_converted){
            Serial.println("JPEG compression failed");
            res = ESP_FAIL;
          }
        } else {
          _jpg_buf_len = fb->len;
          _jpg_buf = fb->buf;
        }
      }
    }
    if(res == ESP_OK){
      size_t hlen = snprintf((char *)part_buf, 64, _STREAM_PART, _jpg_buf_len);
      res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);
    }
    if(res == ESP_OK){
      res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
    }
    if(res == ESP_OK){
      res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
    }
    if(fb){
      esp_camera_fb_return(fb);
      fb = NULL;
      _jpg_buf = NULL;
    } else if(_jpg_buf){
      free(_jpg_buf);
      _jpg_buf = NULL;
    }
    if(res != ESP_OK){
      break;
    }
    //Serial.printf("MJPG: %uBn",(uint32_t)(_jpg_buf_len));
  }
  return res;
}

void startCameraServer(){
  httpd_config_t config = HTTPD_DEFAULT_CONFIG();
  config.server_port = 80;

  httpd_uri_t index_uri = {
    .uri       = "/",
    .method    = HTTP_GET,
    .handler   = stream_handler,
    .user_ctx  = NULL
  };
  
  //Serial.printf("Starting web server on port: '%d'n", config.server_port);
  if (httpd_start(&stream_httpd, &config) == ESP_OK) {
    httpd_register_uri_handler(stream_httpd, &index_uri);
  }
}

void setup() {
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
 
  Serial.begin(115200);
  Serial.setDebugOutput(false);
  
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG; 
  
  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }
  
  // Camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }
  // Wi-Fi connection
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  Serial.print("Camera Stream Ready! Go to: http://");
  Serial.print(WiFi.localIP());

  // Init OLED
  Wire.begin(I2C_SDA, I2C_SCL);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(5, 5);
  display.print(WiFi.localIP());;
  display.display();
  
  // Start streaming web server
  startCameraServer();
}

void loop() {
  delay(1);
}

Afficher le code brut

Exemple de serveur Web de streaming vidéo ESP32-CAM

En savoir plus sur ce projet : ESP32-CAM Video Streaming Web Server

Prendre une photo et l’afficher sur le serveur Web

Le code suivant crée un serveur Web auquel vous pouvez accéder pour prendre et afficher des photos. L’adresse IP du serveur Web est affichée sur l’OLED.

/*
  Rui Santos
  Complete project details at https://Raspberryme.com/ttgo-t-journal-esp32-camera-getting-started/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include "WiFi.h"
#include "esp_camera.h"
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "soc/soc.h"           // Disable brownour problems
#include "soc/rtc_cntl_reg.h"  // Disable brownour problems
#include "driver/rtc_io.h"
#include <ESPAsyncWebServer.h>
#include <StringArray.h>
#include <SPIFFS.h>
#include <FS.h>

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define I2C_SDA 14
#define I2C_SCL 13

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

boolean takeNewPhoto = false;

// Photo File Name to save in SPIFFS
#define FILE_PHOTO "/photo.jpg"

// OV2640 camera module pins (CAMERA_MODEL_TTGO-T-Journal)
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM     27
#define SIOD_GPIO_NUM     25
#define SIOC_GPIO_NUM     23
#define Y9_GPIO_NUM       19
#define Y8_GPIO_NUM       36
#define Y7_GPIO_NUM       18
#define Y6_GPIO_NUM       39
#define Y5_GPIO_NUM       5
#define Y4_GPIO_NUM       34
#define Y3_GPIO_NUM       35
#define Y2_GPIO_NUM       17
#define VSYNC_GPIO_NUM    22
#define HREF_GPIO_NUM     26
#define PCLK_GPIO_NUM     21

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    body { text-align:center; }
    .vert { margin-bottom: 10%; }
    .hori{ margin-bottom: 0%; }
  </style>
</head>
<body>
  <div id="container">
    <h2>ESP32-CAM Last Photo</h2>
    <p>It might take more than 5 seconds to capture a photo.</p>
    <p>
      <button onclick="rotatePhoto();">ROTATE</button>
      <button onclick="capturePhoto()">CAPTURE PHOTO</button>
      <button onclick="location.reload();">REFRESH PAGE</button>
    </p>
  </div>
  <div><img src="https://www.raspberryme.com/ttgo-t-journal-esp32-camera-getting-started/saved-photo" id="photo" width="70%"></div>
</body>
<script>
  var deg = 0;
  function capturePhoto() {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', "/capture", true);
    xhr.send();
  }
  function rotatePhoto() {
    var img = document.getElementById("photo");
    deg += 90;
    if(isOdd(deg/90)){ document.getElementById("container").className = "vert"; }
    else{ document.getElementById("container").className = "hori"; }
    img.style.transform = "rotate(" + deg + "deg)";
  }
  function isOdd(n) { return Math.abs(n % 2) == 1; }
</script>
</html>)rawliteral";

void setup() {
  // Serial port for debugging purposes
  Serial.begin(115200);

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  if (!SPIFFS.begin(true)) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    ESP.restart();
  }
  else {
    delay(500);
    Serial.println("SPIFFS mounted successfully");
  }

  // Print ESP32 Local IP Address
  Serial.print("IP Address: http://");
  Serial.println(WiFi.localIP());

  // Init OLED
  Wire.begin(I2C_SDA, I2C_SCL);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(5, 5);
  display.print(WiFi.localIP());;
  display.display();


  // Turn-off the 'brownout detector'
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);

  // OV2640 camera module
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;

  if (psramFound()) {
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }
  // Camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    ESP.restart();
  }

  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/html", index_html);
  });

  server.on("/capture", HTTP_GET, [](AsyncWebServerRequest * request) {
    takeNewPhoto = true;
    request->send_P(200, "text/plain", "Taking Photo");
  });

  server.on("/saved-photo", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, FILE_PHOTO, "image/jpg", false);
  });

  // Start server
  server.begin();

}

void loop() {
  if (takeNewPhoto) {
    capturePhotoSaveSpiffs();
    takeNewPhoto = false;
  }
  delay(1);
}

// Check if photo capture was successful
bool checkPhoto( fs::FS &fs ) {
  File f_pic = fs.open( FILE_PHOTO );
  unsigned int pic_sz = f_pic.size();
  return ( pic_sz > 100 );
}

// Capture Photo and Save it to SPIFFS
void capturePhotoSaveSpiffs( void ) {
  camera_fb_t * fb = NULL; // pointer
  bool ok = 0; // Boolean indicating if the picture has been taken correctly

  do {
    // Take a photo with the camera
    Serial.println("Taking a photo...");

    fb = esp_camera_fb_get();
    if (!fb) {
      Serial.println("Camera capture failed");
      return;
    }

    // Photo file name
    Serial.printf("Picture file name: %sn", FILE_PHOTO);
    File file = SPIFFS.open(FILE_PHOTO, FILE_WRITE);

    // Insert the data in the photo file
    if (!file) {
      Serial.println("Failed to open file in writing mode");
    }
    else {
      file.write(fb->buf, fb->len); // payload (image), payload length
      Serial.print("The picture has been saved in ");
      Serial.print(FILE_PHOTO);
      Serial.print(" - Size: ");
      Serial.print(file.size());
      Serial.println(" bytes");
    }
    // Close the file
    file.close();
    esp_camera_fb_return(fb);

    // check if file has been correctly saved in SPIFFS
    ok = checkPhoto(SPIFFS);
  } while ( !ok );
}

Afficher le code brut

ESP32-CAM Prendre une photo et l'afficher sur le serveur Web

En savoir plus sur ce projet : ESP32-CAM Prendre une photo et l’afficher sur un serveur Web

Exemple de CameraWebServer

Vous pouvez également exécuter l’exemple CameraWebServer par défaut fourni avec l’IDE Arduino. Dans votre IDE Arduino, accédez à Déposer > Exemples > ESP32 > Caméra et ouvrez le CaméraWebServer Exemple.

Vous pouvez cliquer sur le lien suivant pour télécharger le .zip avec le code final :

Sinon, vous devez ajouter le brochage TTGO T-Journal au camera_pins.h languette.

Exemple de CameraWebServer ESP32-CAM pour Arduino IDE

Copiez ce qui suit dans le fichier camera_pins.h.

#if defined(CAMERA_MODEL_T_JOURNAL)
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM     27
#define SIOD_GPIO_NUM     25
#define SIOC_GPIO_NUM     23

#define Y9_GPIO_NUM       19
#define Y8_GPIO_NUM       36
#define Y7_GPIO_NUM       18
#define Y6_GPIO_NUM       39
#define Y5_GPIO_NUM       5
#define Y4_GPIO_NUM       34
#define Y3_GPIO_NUM       35
#define Y2_GPIO_NUM       17
#define VSYNC_GPIO_NUM    22
#define HREF_GPIO_NUM     26
#define PCLK_GPIO_NUM     21

Ensuite, dans l’onglet CameraWebServer, commentez tous les modèles de caméras existants et ajoutez votre caméra, comme suit :

// Select camera model
#define CAMERA_MODEL_T_JOURNAL
//#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE
//#define CAMERA_MODEL_AI_THINKER

Étant donné que cet appareil photo n’a pas de PSRAM, les fonctions de reconnaissance et de détection des visages de ce projet ne fonctionnent pas avec cet appareil photo. Toutes les autres fonctionnalités fonctionnent bien.

Exemple de CameraWebServer ESP32-CAM pour Arduino IDE Web Server

Télécharger le code sur la caméra TTGO T-Journal ESP32

Pour télécharger le code, il vous suffit de connecter la carte à votre ordinateur, puis dans l’IDE Arduino, allez sur Outils > Port et sélectionnez le port COM auquel il est connecté.

Ensuite, vous devez également sélectionner un modèle de carte. Le TTGO T-Journal n’est pas disponible sur les modèles ESP32. Alors, sélectionnez les paramètres suivants :

  • Conseil: « Module Wrover ESP32 »
  • Schéma de partition : « Énorme application (3 Mo sans OTA) »
Carte ESP32 Wrover Module et partition Scheme Énorme APP (3 Mo sans OTA)

Ensuite, cliquez simplement sur le bouton de téléchargement Arduino IDE et le tour est joué !

Arduino IDE Compiler et télécharger le bouton d'esquisse

Emballer

Ce tutoriel était un guide de démarrage rapide pour la carte de développement de caméra TTGO T-Journal ESP32. Vous avez appris à contrôler l’écran OLED et à adapter les projets de caméra ESP32 existants à votre carte.

Nous espérons que vous avez trouvé ce tutoriel utile. Pour en savoir plus sur cette carte, vous pouvez lire notre aperçu complet sur Maker Advisor ainsi que notre article de comparaison des cartes de développement ESP32-CAM :

Vous pouvez également être intéressé par d’autres cartes de développement ESP32 :

Merci d’avoir lu.