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

ESP32-Controlled OLED Display and Servo with DotStar LED Strip and Audio Output

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled OLED Display and Servo with DotStar LED Strip and Audio Output

Circuit Documentation

Summary of the Circuit

This circuit is designed to incorporate a variety of components including microcontrollers, power management modules, audio output devices, a display, and LED lighting. The primary controller is an ESP32 DEVKIT V1 microcontroller, which interfaces with an OLED display, a DotStar LED strip, a servo motor via a PCA9685 PWM Servo Breakout, and audio output through a PAM8403 amplifier module. The circuit is powered by a pair of 18650 Li-ion batteries, managed by a TP4056 charging module, and controlled by a rocker switch. The ESP32 also drives a piezo speaker directly for additional audio signaling.

Component List

Microcontrollers

Power Management

Display

LED Lighting

Motor Control

Audio Output

Servo Motor

Wiring Details

ESP 32 DEVKIT V1 (30 pins)

Adafruit PCA9685 PWM Servo Breakout

Servo

0.96" OLED

Adafruit DotStar Strip 60M_B

18650 Li-ion Battery x 2

TP4056

PAM8403

Speaker

Piezo Speaker

Rocker Switch (SPST)

Documented Code

ESP 32 DEVKIT V1 (30 pins) - sketch.ino

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

// Define screen dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// Define I2C pins for OLED display (adjust as needed)
#define OLED_SDA 19
#define OLED_SCL 18

// Create an instance of the display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Ball properties
int ball_x = SCREEN_WIDTH / 2;
int ball_y = SCREEN_HEIGHT / 2;
int ball_radius = 5;
int ball_x_speed = 2;
int ball_y_speed = 2;

void setup() {
  // Start serial communication for debugging
  Serial.begin(115200);

  // Initialize I2C for the OLED display with custom SDA and SCL pins
  Wire.begin(OLED_SDA, OLED_SCL);

  // Initialize the display
  if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) { // 0x3C is the common I2C address
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

  display.clearDisplay();
  display.display();
}

void loop() {
  // Clear the display
  display.clearDisplay();

  // Draw the ball
  display.fillCircle(ball_x, ball_y, ball_radius, SSD1306_WHITE);

  // Update the ball's position
  ball_x += ball_x_speed;
  ball_y += ball_y_speed;

  // Check for collision with the screen edges (bounce effect)
  if (ball_x - ball_radius <= 0 || ball_x + ball_radius >= SCREEN_WIDTH) {
    ball_x_speed = -ball_x_speed; // Reverse direction on X axis
  }
  if (ball_y - ball_radius <= 0 || ball_y + ball_radius >= SCREEN_HEIGHT) {
    ball_y_speed = -ball_y_speed; // Reverse direction on Y axis
  }

  // Update the display with the new frame
  display.display();

  // Delay to control the speed of animation
  delay(30);
}

This code is designed to run on the ESP32 microcontroller and controls an OLED display to animate a bouncing ball. It initializes the display, sets up the ball's properties, and contains a loop that updates the ball's position, checks for collisions, and redraws the ball on the display. The I2C communication with the display is set up with custom SDA and SCL pins defined in the code.