Week10

Assignment: Output Devices

Software used: KiCAD

***In this assignment, I have used Gemini as an experiment to see how to use ChatGPT for documentation. Major content is curated using Gemini, and it's for learning purposes.

Individual Assignment:

Creating a PCB with Seeed Studio XIAO ESP32-C3 and output devices. For this assignment, 4 stepper motors are connected and simulated using a program.

What are Output Devices?

Output devices receive electrical signals from a microcontroller (like the XIAO we often use in Fab Academy) and convert these signals into a different form of energy or information that humans can perceive or that can act upon the environment. Think of it as the reverse of an input device, which senses the physical world and converts it into electrical signals.

Why are Output Devices Important?

Output devices are crucial because they:

Types of Output Devices:

The world of output devices is vast and varied! Here are some common types you'll likely encounter in Fab Academy and beyond:

1. Visual Displays:

2. Motors and Actuators:

3. Audio Output:

4. Thermal Output:

5. Other Output Devices:

Connecting Output Devices to Microcontrollers

Interfacing output devices with microcontrollers typically involves:

What is SG90 ?

The SG90 is a very popular and inexpensive micro servo motor widely used in hobby robotics, radio-controlled models, and DIY electronics projects. Its small size, light weight, and ease of control make it a go-to actuator for many applications where precise angular movement is required.

Here's a detailed explanation of the SG90:

Key Features and Characteristics:

How it Works (PWM Control):

Video:

The SG90's position is controlled by the width of a pulse sent to its signal wire. Here's the general principle:

Microcontrollers like the Arduino have built-in libraries (like the Servo library) that simplify the generation of these precise PWM signals, allowing you to easily command the SG90 to move to specific angles.

Video Link Programing

What is an OLED Display?

OLED stands for Organic Light-Emitting Diode. Unlike traditional LCDs (Liquid Crystal Displays) that require a separate backlight to illuminate their pixels, each pixel in an OLED display is an individual light-emitting diode. This self-emissive property gives OLEDs several key advantages:

What is I2C Communication?

I2C (Inter-Integrated Circuit), also known as TWI (Two-Wire Interface), is a synchronous, multi-master/multi-slave serial communication protocol. It's widely used for short-distance, intra-board communication between integrated circuits.

Key features of I2C:

I2C OLED Display Modules (e.g., SSD1306)

The most common I2C OLED displays for hobbyists are based on the SSD1306 driver IC. These modules come in various sizes and resolutions, with 0.96-inch 128x64 pixel and 0.91-inch 128x32 pixel monochrome (usually white or blue) displays being the most popular.

How it Works (Simplified):

  1. Module Components: An I2C OLED display module consists of:
  1. Connection: You connect the module to your microcontroller using just four pins:
  1. Microcontroller Interaction:

Advantages of I2C OLED Displays:

Assignment Output Devices

Objective: To connect four SG90 micro servo motors to a Seeed Studio XIAO ESP32C3 microcontroller and control their movements using a programmed sequence or user input.

1. Components Required:

2. Understanding the Seeed Studio XIAO ESP32C3:

The XIAO ESP32C3 has several GPIO pins, many of which can generate PWM signals. This is perfect for controlling multiple servos. Look at the pinout diagram for your specific XIAO ESP32C3 board. You'll primarily be using the digital pins capable of PWM.

3. Wiring Diagram and Connections:

Safety First: Disconnect all power before making or changing connections.

  1. Prepare the Power Rail on Breadboard:
  1. Connect Each SG90 Servo (x4):

Visual Aid (Conceptual):

EXTERNAL 5V POWER SUPPLY

     (+) ----- [RED Breadboard Rail] --- RED WIRE (Servo 1, 2, 3, 4)

     (-) ----- [BLUE Breadboard Rail] --- BROWN/BLACK WIRE (Servo 1, 2, 3, 4)

                                    |

                                    +--- GND PIN (XIAO ESP32C3)

XIAO ESP32C3

  D0 (GPIO0) ----- YELLOW/ORANGE WIRE (Servo 1 Signal)

  D1 (GPIO1) ----- YELLOW/ORANGE WIRE (Servo 2 Signal)

  D2 (GPIO2) ----- YELLOW/ORANGE WIRE (Servo 3 Signal)

  D3 (GPIO3) ----- YELLOW/ORANGE WIRE (Servo 4 Signal)

4. Software Setup (Arduino IDE):

  1. Install Arduino IDE: If you haven't already, download and install the Arduino IDE.
  2. Add ESP32 Boards Manager:
  1. Select XIAO ESP32C3 Board:
  1. Install Servo Library:

5. Programming the XIAO ESP32C3:

Here's a sample Arduino sketch that demonstrates controlling four servos. You can adapt the angles and delays to create your desired movements.

Arduino

#include <ESP32Servo.h> // Include the ESP32 Servo library

// Define the pins connected to each servo's signal wire

#define SERVO1_PIN GPIO0 // Corresponds to XIAO D0

#define SERVO2_PIN GPIO1 // Corresponds to XIAO D1

#define SERVO3_PIN GPIO2 // Corresponds to XIAO D2

#define SERVO4_PIN GPIO3 // Corresponds to XIAO D3

// Create Servo objects for each motor

Servo servo1;

Servo servo2;

Servo servo3;

Servo servo4;

void setup() {

  Serial.begin(115200); // Initialize serial communication for debugging

  // Allow allocation of all timers for `micros()` and `delay()` functions

  // This is specific to ESP32Servo library if not using default timer

  ESP32PWM::allowAllPins();

  // Attach each servo object to its respective pin

  // (Optional: Set min and max pulse width if your servos behave oddly,

  //          default values are usually fine for SG90)

  // servo1.attach(SERVO1_PIN, 500, 2400); // Example custom pulse widths

  servo1.attach(SERVO1_PIN);

  servo2.attach(SERVO2_PIN);

  servo3.attach(SERVO3_PIN);

  servo4.attach(SERVO4_PIN);

  Serial.println("Servos initialized.");

}

void loop() {

  // === Sequence 1: Move all servos to 0 degrees ===

  Serial.println("Moving all servos to 0 degrees...");

  servo1.write(0);

  servo2.write(0);

  servo3.write(0);

  servo4.write(0);

  delay(1500); // Wait for 1.5 seconds for servos to reach position

  // === Sequence 2: Move all servos to 90 degrees (center) ===

  Serial.println("Moving all servos to 90 degrees...");

  servo1.write(90);

  servo2.write(90);

  servo3.write(90);

  servo4.write(90);

  delay(1500);

  // === Sequence 3: Move all servos to 180 degrees ===

  Serial.println("Moving all servos to 180 degrees...");

  servo1.write(180);

  servo2.write(180);

  servo3.write(180);

  servo4.write(180);

  delay(1500);

  // === Sequence 4: Individual Servo Control (Example) ===

  Serial.println("Individual servo movements...");

  servo1.write(45);  delay(500);

  servo2.write(135); delay(500);

  servo3.write(20);  delay(500);

  servo4.write(160); delay(500);

  delay(1000); // Pause before next sequence

  // === Sequence 5: Sweep all servos back and forth ===

  Serial.println("Sweeping servos...");

  for (int angle = 0; angle <= 180; angle += 5) {

    servo1.write(angle);

    servo2.write(180 - angle); // Move in opposite direction

    servo3.write(angle);

    servo4.write(180 - angle);

    delay(30); // Small delay for smooth sweep

  }

  delay(500);

  for (int angle = 180; angle >= 0; angle -= 5) {

    servo1.write(angle);

    servo2.write(180 - angle);

    servo3.write(angle);

    servo4.write(180 - angle);

    delay(30);

  }

  delay(1000); // Pause before repeating loop

}

***Code generated using Gemini  but going to use my program to demonstrate.

Video Link

Woking File Link : LINK

<<Back to Home