AI chatbot — Xiao Esp32S3 Sense simulation

An interactive Xiao Esp32S3 Sense circuit simulation you can run free in your browser on Velxio, by soniyashvi966.

Components

Sketch code

#include "esp_camera.h"
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

// TFT pins (XIAO GPIO numbers)
#define TFT_CS   4
#define TFT_DC   2
#define TFT_RST  3

// Buttons and LED
#define BTN_CAPTURE 1
#define BTN_ASK     5
#define STATUS_LED  6

// SPI pins: D8, D9, D10
#define SPI_SCK   7
#define SPI_MISO  8
#define SPI_MOSI  9

Adafruit_ILI9341 tft(TFT_CS, TFT_DC, TFT_RST);

bool cameraReady = false;
bool lastCapture = HIGH;
bool lastAsk = HIGH;

// XIAO ESP32-S3 Sense camera
void startCamera() {

  camera_config_t config = {};

  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;

  config.pin_d0 = 15;
  config.pin_d1 = 17;
  config.pin_d2 = 18;
  config.pin_d3 = 16;
  config.pin_d4 = 14;
  config.pin_d5 = 12;
  config.pin_d6 = 11;
  config.pin_d7 = 48;

  config.pin_xclk = 10;
  config.pin_pclk = 13;
  config.pin_vsync = 38;
  config.pin_href = 47;

  config.pin_sccb_sda = 40;
  config.pin_sccb_scl = 39;

  config.pin_pwdn = -1;
  config.pin_reset = -1;

  config.xclk_freq_hz = 20000000;

  // RGB565 allows direct TFT drawing
  config.pixel_format = PIXFORMAT_RGB565;
  config.frame_size = FRAMESIZE_QVGA;
  config.fb_count = 1;
  config.fb_location = CAMERA_FB_IN_PSRAM;

  esp_err_t result = esp_camera_init(&config);

  if (result == ESP_OK) {
    cameraReady = true;
    Serial.println("Camera READY");
  } else {
    Serial.printf("Camera ERROR: 0x%x\n", result);
  }
}

// Home screen
void showHome() {

  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);

  tft.setCursor(30, 25);
  tft.println("AI VISION");

  tft.setCursor(30, 55);
  tft.println("ASSISTANT");

  tft.drawFastHLine(10, 90, 300, ILI9341_BLUE);

  tft.setCursor(20, 115);
  tft.println("Camera Ready");

  tft.setCursor(20, 155);
  tft.println("Press CAPTURE");

  tft.setCursor(20, 190);
  tft.println("to take photo");
}

// Capture and display image
void capturePhoto() {

  if (!cameraReady) {
    Serial.println("Camera unavailable");
    return;
  }

  digitalWrite(STATUS_LED, HIGH);

  Serial.println("Capturing image...");

  camera_fb_t *frame = esp_camera_fb_get();

  if (!frame) {
    Serial.println("Capture failed");
    digitalWrite(STATUS_LED, LOW);
    return;
  }

  Serial.printf("Image captured: %u bytes\n", frame->len);

  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.setCursor(20, 10);
  tft.println("Captured Image");

  // Display camera image
  tft.drawRGBBitmap(
    0,
    40,
    (uint16_t *)frame->buf,
    frame->width,
    frame->height
  );

  Serial.println("Image displayed on TFT");

  esp_camera_fb_return(frame);

  digitalWrite(STATUS_LED, LOW);
}

// Ask AI screen
void askAI() {

  tft.fillScreen(ILI9341_BLACK);

  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);

  tft.setCursor(20, 40);
  tft.println("AI ASSISTANT");

  tft.setCursor(20, 100);
  tft.println("AI request");

  tft.setCursor(20, 135);
  tft.println("

More projects by soniyashvi966