mopane — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by seabecyber.

Components

Sketch code

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <DHT.h>
#include <TinyGPS++.h>
#include <WiFi.h>

// Wi-Fi Credentials
const char* ssid = "YourSSID";
const char* password = "YourPassword";

// TFT Display Pin Definitions (using hardware SPI)
#define TFT_CS    5
#define TFT_DC    21
#define TFT_RST   22

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

// DHT22 Sensor setup
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

// Analog Microphone Pins (using ADC1 pins so they work alongside WiFi)
#define MIC_SIG1_PIN 34
#define MIC_SIG2_PIN 35

// GPS setup (Hardware Serial 2) - Fixed to 9600 baud to match simulator module
const int GPS_RXPin = 16;
const int GPS_TXPin = 17;
const uint32_t GPSBaud = 9600;

TinyGPSPlus gps;
HardwareSerial gpsSerial(2);

// ESP32-CAM Serial 1 setup (Hardware Serial 1)
const int CAM_RXPin = 26;
const int CAM_TXPin = 25;
HardwareSerial camSerial(1);

// System State Variables
bool systemTriggeredByFace = false;
int detectedWormCount = 0;
String camStatusStr = "Waiting for Face...";

void setup() {
  Serial.begin(115200);
  
  // Initialize Display
  tft.begin();
  tft.setRotation(1); // Landscape mode
  tft.fillScreen(ILI9341_BLACK);
  
  // Draw static UI layout
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.setCursor(10, 10);
  tft.print("Mopane Monitor Hub");
  
  tft.drawFastHLine(0, 35, 320, ILI9341_BLUE);

  // Connect to Wi-Fi
  tft.setCursor(10, 210);
  tft.setTextSize(1);
  tft.print("Connecting to WiFi...");
  
  WiFi.begin(ssid, password);
  unsigned long startAttemptTime = millis();
  
  while (WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < 10000) {
    delay(500);
    Serial.print(".");
  }

  tft.fillRect(10, 205, 300, 30, ILI9341_BLACK);
  tft.setCursor(10, 210);
  if (WiFi.status() == WL_CONNECTED) {
    tft.setTextColor(ILI9341_GREEN);
    tft.print("WiFi Connected!");
  } else {
    tft.setTextColor(ILI9341_RED);
    tft.print("WiFi Failed");
  }

  // Initialize Sensors and Communication Ports
  dht.begin();
  gpsSerial.begin(GPSBaud, SERIAL_8N1, GPS_RXPin, GPS_TXPin);
  camSerial.begin(115200, SERIAL_8N1, CAM_RXPin, CAM_TXPin);
}

void loop() {
  // 1. Read incoming data stream from ESP32-CAM via Serial1
  while (camSerial.available() > 0) {
    String incomingMessage = camSerial.readStringUntil('\n');
    incomingMessage.trim();
    
    // Check if camera detected a face to start monitoring
    if (incomingMessage.equals("TRIGGER:START_MONITORING")) {
      systemTriggeredByFace = true;
      updateSystemStateDisplay("Face Detected - Active!");
    }
    
    // Parse normal count packets: "COUNT:24,STATUS:..."
    if (incomingMessage.startsWith("COUNT:")) {
      int commaIndex = incomingMessage.indexOf(',');
      if (commaIndex != -1) {
        detectedWormCount = incomingMessage.substring(6, commaIndex).toInt();
        camStatusStr = incomingMessage.substring(commaIndex + 8);
        updateCameraD

More projects by seabecyber