Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-C3 Mini and OLED Display Analog Signal Visualizer

View and Edit Project In Cirkit DesignerImage of ESP32-C3 Mini and OLED Display Analog Signal Visualizer

Circuit Documentation

Summary

This circuit consists of an ESP32-C3 Mini microcontroller connected to a 0.96" OLED display. The ESP32-C3 Mini reads an analog signal and displays a waveform representation of this signal on the OLED display.

Component List

ESP32-C3 Mini

0.96" OLED

Wiring Details

ESP32-C3 Mini

0.96" OLED

Code

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define ANALOG_PIN 0 // Analog input pin (use correct GPIO number)

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize the I2C bus
  Wire.begin();

  // Initialize the OLED display
  if(!display.begin(0x3C, OLED_RESET)) { // Use correct I2C address
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.display();
  delay(2000); // Pause for 2 seconds
  display.clearDisplay();
}

void loop() {
  // Read the analog signal from the defined analog pin
  int analogValue = analogRead(ANALOG_PIN);

  // Map the analog value to the display height
  int displayValue = map(analogValue, 0, 1023, 0, SCREEN_HEIGHT);

  // Clear the display
  display.clearDisplay();

  // Draw the waveform
  for (int x = 0; x < SCREEN_WIDTH; x++) {
    int y = map(analogRead(ANALOG_PIN), 0, 1023, 0, SCREEN_HEIGHT);
    display.drawPixel(x, SCREEN_HEIGHT - y, SSD1306_WHITE);
    delay(10); // Small delay to simulate waveform
  }

  // Display the waveform
  display.display();
}

This code initializes the ESP32-C3 Mini and the OLED display, reads an analog signal, and displays a waveform representation of the signal on the OLED display.