OSCGB — ESP32 simulation

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

Components

Sketch code

/*
  ESP32 DIY oscilloscope + Wi-Fi phone display

  Wiring (per schematic): probe -> R1 -> node -> D34, OLED SDA=D21 SCL=D22,
  buttons OK=D25 BACK=D26 PLUS=D27 MINUS=D14 (other leg to GND), CAL OUT = D13.
  The ESP32 joins YOUR home Wi-Fi (set STA_SSID / STA_PASS below).
    1. Put your phone on the same Wi-Fi
    2. Open the address shown on the OLED / Serial Monitor (e.g. http://192.168.1.37)
    (If joining fails it falls back to its own network ESP32-Scope, http://192.168.4.1)
    3. You get the live waveform, Vpp, frequency, and on-screen buttons.

  Libraries: Adafruit SSD1306, Adafruit GFX Library (WiFi and WebServer are built in)
*/

#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define PIN_ADC 34
#define PIN_CAL 13   // D25 is now a button; CAL OUT moved to D13 (not wired in the sim)
#define PIN_SDA 21
#define PIN_SCL 22

// ================= SETTINGS (the only lines you normally change) =================
#define START_IN_DEMO true    // true = built-in test wave (use this in Velxio)
                              // false = read the real probe on D34 (real hardware)
                              // (hold OK for 1 s at any time to switch)
#define USE_HOME_WIFI false   // false = ESP32 makes its own Wi-Fi "ESP32-Scope"
                              // true  = join your home Wi-Fi (fill in the two lines below)
// ===================================================================================
// ---- Home Wi-Fi (only used when USE_HOME_WIFI is true) ----
const char *STA_SSID = "YOUR_WIFI_NAME";
const char *STA_PASS = "YOUR_WIFI_PASSWORD";
// If the home Wi-Fi cannot be joined in 15 s, the ESP32 makes its own network instead.
const char *AP_SSID = "ESP32-Scope";
const char *AP_PASS = "scope1234";  // at least 8 characters

// Buttons as wired in the Velxio schematic (left to right): D25, D26, D27, D14
// Other leg of every button goes to GND (internal pull-ups are used).
const uint8_t BTN_PIN[4] = {25, 26, 27, 14};  // OK, BACK, PLUS, MINUS
enum { B_OK, B_BACK, B_PLUS, B_MINUS };

const float VREF = 3.3f;
const float DIVIDER = 2.0f;

const int W = 128;
const int H = 64;
const int WAVE_TOP = 18;
const int WAVE_BOT = 63;
const int PX_PER_DIV = 16;

const uint32_t TB_US[] = {500, 1000, 2000, 5000, 10000, 20000, 50000};
const char *TB_NAME[] = {"500us", "1ms", "2ms", "5ms", "10ms", "20ms", "50ms"};
const uint8_t TB_COUNT = 7;
uint8_t tb = 1;

Adafruit_SSD1306 display(W, H, &Wire, -1);
WebServer server(80);

uint16_t buf[W];
uint16_t trigLevel = 2048;
float vpp = 0;
float freqHz = 0;
uint16_t rawMin = 0, rawMax = 0;
bool running = true;
bool calOn = false;

bool demo = START_IN_DEMO;
uint8_t demoShape = 0;
float demoPhase = 0;
uint32_t okDownAt = 0;
bool webDemoToggle = false;

volatile bool btnFlag[4] = {false, false, false, false};
volatile uint32_t btnLastUs[4] = {0, 0, 0, 0};

void IRAM_ATTR btnIsr(uint8_t i) {
  uint32_t now = micros();
  if (now 

More projects by bharatgonapa06