Skip to content

5. Week5

Microcontroller

A microcontroller is a compact integrated circuit that controls specific functions in embedded systems. It includes a CPU, memory (RAM and Flash), I/O ports, and often timers and ADCs. Microcontrollers are used in devices like appliances, IoT gadgets, and robotics for automation and control.

XIAO ESP32-S3 Pinout for Digital I/O, Analog Input, and PWM

The XIAO ESP32-S3 is a versatile microcontroller board with a variety of pins for different functionalities. Here’s a breakdown of the pins you’re interested in:

Digital I/O Pins:

D0-D10: These 11 pins can be used for both digital input and output purposes. They are highly flexible and can be configured for various functions.

Analog Input Pins:

A0-A5, A8-A10: These 9 pins are designed for analog input, allowing you to read analog signals from sensors or other devices.

PWM Pins:

D0-D10: All 11 digital I/O pins can be used for Pulse-Width Modulation (PWM), enabling control over the duty cycle of a signal. This is useful for controlling the brightness of LEDs, motor speeds, and other applications.

Example

Search for the name of the Arduino used and choose a location

Then a suppository

To choose Getting started with seeed studio XIAO ESP32S3

Then search for esp32 and download it

With these steps, we search for the name of the Arduino written on it

To make sure the connection

Code Example C++

Use the three backticks to separate code.

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(5000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
} 

Confirm the code is active and running. (verify)>(upload)

Result

The second experiment using the microcontroller (Arduino) and LED

Search for Thonny website and download the first link

Steps to connect the Arduino and search for its name

Fill in the blanks

We searched for a code with the required name, which is the name of the piece we are working on esp32 blink python

Another code Python

import machine
import time

print("Hello, ESP32!")
led = machine.Pin(18, machine.Pin.OUT)

# Define a simple melody with durations (in seconds)
melody = [
    (0.2, 1),  # Note on for 0.2 seconds
    (0.1, 0),  # Note off for 0.1 seconds
    (0.3, 1),  # Note on for 0.3 seconds
    (0.1, 0),  # Note off for 0.1 seconds
    (0.4, 1),  # Note on for 0.4 seconds
    (0.1, 0),  # Note off for 0.1 seconds
]

while True:
    for duration, state in melody:
        led.value(state)
        time.sleep(duration)

Resulte


Last update: December 19, 2024