ESP32-CAM Trash Picker — Esp32 Cam simulation

An ESP32-CAM car that detects trash, drives to it and scoops it up with a servo arm.

An interactive Esp32 Cam circuit simulation you can run free in your browser on Velxio, by eraniajoycatubig.

Components

Sketch code

/*
 * ESP32-CAM Trash Picker
 * 1. Looks for trash (Edge Impulse FOMO model, or typed input for simulation)
 * 2. When trash is seen, the motors turn ON automatically and the car steers to it
 * 3. When the trash is close, it stops, the servo arm scoops it up, then it carries on
 *
 * Wiring (see velxio_dc_motor_wiring.svg):
 *   GPIO 13 -> 1k resistor -> NPN transistor base -> LEFT  DC motor
 *   GPIO 15 -> 1k resistor -> NPN transistor base -> RIGHT DC motor
 *   GPIO 14 -> servo signal (scoop / arm)   servo V+ -> 5V, GND -> GND
 *
 * USE_CAMERA 0 : simulation. Type "x y" in Serial Monitor, e.g. "30 40"
 *                x = 0..100 from left edge, y = 0..100 from top edge
 *                (y near 100 = trash is close). "n" or anything else = no trash.
 * USE_CAMERA 1 : real camera + your Edge Impulse library (change the include).
 */

#define USE_CAMERA 0

#include <Arduino.h>

#if USE_CAMERA
#include <trash_detection_inferencing.h>   // <-- CHANGE to your library name
#include "esp_camera.h"

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

static uint8_t *snapshot_buf = nullptr;

static camera_config_t camera_config;

static void initCameraConfig() {
  memset(&camera_config, 0, sizeof(camera_config));
  camera_config.pin_pwdn = PWDN_GPIO_NUM;
  camera_config.pin_reset = RESET_GPIO_NUM;
  camera_config.pin_xclk = XCLK_GPIO_NUM;
#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
  camera_config.pin_sccb_sda = SIOD_GPIO_NUM;
  camera_config.pin_sccb_scl = SIOC_GPIO_NUM;
  camera_config.sccb_i2c_port = -1;
#else
  camera_config.pin_sscb_sda = SIOD_GPIO_NUM;   // if this errors, rename to pin_sccb_sda
  camera_config.pin_sscb_scl = SIOC_GPIO_NUM;   // and pin_sccb_scl
#endif
  camera_config.pin_d7 = Y9_GPIO_NUM;
  camera_config.pin_d6 = Y8_GPIO_NUM;
  camera_config.pin_d5 = Y7_GPIO_NUM;
  camera_config.pin_d4 = Y6_GPIO_NUM;
  camera_config.pin_d3 = Y5_GPIO_NUM;
  camera_config.pin_d2 = Y4_GPIO_NUM;
  camera_config.pin_d1 = Y3_GPIO_NUM;
  camera_config.pin_d0 = Y2_GPIO_NUM;
  camera_config.pin_vsync = VSYNC_GPIO_NUM;
  camera_config.pin_href = HREF_GPIO_NUM;
  camera_config.pin_pclk = PCLK_GPIO_NUM;
  camera_config.xclk_freq_hz = 20000000;
  camera_config.ledc_timer = LEDC_TIMER_0;
  camera_config.ledc_channel = LEDC_CHANNEL_0;
  camera_config.pixel_format = PIXFORMAT_JPEG;
  camera_config.frame_size = FRAMESIZE_QVGA;
  camera_config.jpeg_quality = 12;
  camera_config.fb_count = 1;
  camera_config.fb_location = CAMERA_FB_IN_PSRAM;
  camera_config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
}

static int ei_camera_get_data

More projects by eraniajoycatubig