Back to Weekly Assignments

week 4. Embedded programming



Group assignment:


Group assignment


1.Demonstrate and compare the toolchains and development workflows for available embedded architectures 2.Document your work to the group work page and reflect on your individual page what you learned

Individual assignment:

"HERO SHOT"

Photo of Your name

1.Browse through the datasheet for your microcontroller.
2. Write a program for a microcontroller, and simulate its operation, to interact (with local input &/or output devices) and communicate (with remote wired or wireless connection) 3.Learning outcomes

4.Implement programming protocols.

To make things quick and easy for you, we have split all the boards into three main categories, Entry Level Arduino boards, Enhanced Arduino boards, and IoT Arduino boards. Further, we have also provided a table under each section for quick skimming, so let’s get started.

Entry-Level Arduino Boards


These types of Arduino boards are the best choice to start with. In this category, most boards have either slow clock speed or a limited number of I/O ports. All these boards are powered by 8-bit microcontrollers. Most of them are easy to learn and make projects with. Not only that, there are a variety of modules and shield boards available on the market, especially targeting these base-level boards. Here is the table showing all the features of these boards.

Photo of Your name

Arduino Uno is the most popular and widely used development board. It is powered by an ATMega328P microcontroller. It is the most popular choice among the community because it’s, cheap, easy to learn and use, and also a variety of premade modules are available for this which makes it easier for developing new projects or prototypes. It consists of 14 Digital I/O out of which 6 pins are 8bit PWM pins, 6 pins are 10-bit Analog inputs, and basic communication ports like SPI, I2C, and UART.

Now, there are many different types of Arduino UNO boards available across the global market, but most of these boards are the clone or copy versions of the original UNO board that you see above. Hence the color or the appearance of the board might be different than what is shown above.

Photo of Your name
Schematic Diagram



Arduino Uno Overview


Microcontroller: ATmega328P
Operating Voltage: 5V
Input Voltage (recommended): 7–12V
Input Voltage (limits): 6–20V
Digital I/O Pins: 14 (of which 6 provide PWM output)
Analog Input Pins: 6
DC Current per I/O Pin: 20 mA
Flash Memory: 32 KB (ATmega328P) – 0.5 KB used by bootloader
SRAM: 2 KB
EEPROM: 1 KB
Clock Speed: 16 MHz
USB Connection: Type-B
Power Jack: Barrel jack
ICSP Header: Yes
Reset Button: Yes

Arduino Uno Pinout

Digital Pins (0–13)

Pin Function
0 RX (Serial Receive)
1 TX (Serial Transmit)
2–13 General I/O
3, 5, 6, 9, 10, 11 PWM Output (AnalogWrite)

Analog Pins (A0–A5)

Pin Function
A0–A5 Analog Inputs (0–1023)
Also usable as digital pins



Arduino Uno Power Pins:

Pin Function
VIN Input voltage to Arduino
5V Regulated 5V output
3.3V 3.3V output (50 mA max)
GND Ground (multiple pins)
RESET Reset the board

Other Arduino Uno Pins:

Pin Function
AREF Reference voltage for analog inputs (optional)
IOREF Reference for I/O voltage (usually 5V)
ICSP SPI programming header (MISO, MOSI, SCK, RESET)

Communication Interfaces

UART: Yes (Digital Pins 0 and 1)
I2C: A4 (SDA), A5 (SCL)
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK)


ESP32 Memory Architecture Overview

Photo of Your name

ESP32 memory types and descriptions:
Memory Type Description
ROM ~448 KB (contains bootloader, core libraries)
SRAM ~520 KB (Internal)
RTC SRAM 8 KB (for deep sleep state retention)
Flash External (usually 4MB or more via SPI)
PSRAM (opt) Up to 8 MB (optional external via SPI/QSPI)



ESP32 Internal Memory Breakdown:

Photo of Your name

Region Size Function
IRAM (Instruction RAM) 128 KB Stores executable code
DRAM (Data RAM) 328 KB Heap, global/static variables
RTC Fast/Slow RAM 8 KB Low-power memory for deep sleep


ESP32 SPI Flash Default Pin Mapping:

Signal GPIO
CS (Chip Select) GPIO15
CLK GPIO6
MISO (Q) GPIO7
MOSI (D) GPIO8
WP (Write Protect) GPIO10
HOLD (HD) GPIO9

ESP32 PSRAM Default Pin Mapping:

Signal GPIO
CS GPIO17
CLK GPIO16
D/Q0 GPIO8
D/Q1 GPIO9
D/Q2 GPIO10
D/Q3 GPIO11

Note: PSRAM and Flash can share the SPI bus in QSPI mode.

Photo of Your name

>you can use the Servo library that comes with the Arduino IDE. Here are the basic steps:

Connect the servo motor to the Arduino: Connect the signal wire of the servo to a digital pin on the Arduino (e.g., pin 9), and connect the power and ground wires of the servo to a power supply (e.g., the 5V and GND pins on the Arduino).

Include the Servo library: At the beginning of your Arduino sketch, include the Servo library by adding the following line of code:
#include

Create a Servo object: In the setup() function of your sketch, create a Servo object by declaring a variable of type Servo. For example:

Servo myServo;

Attach the servo: In the setup() function, use the attach() method of the Servo object to attach the servo to the digital pin you connected it to. For example: myServo.attach(9);


Set the servo position: In the loop() function, use the write() method of the Servo object to set the position of the servo. The write() method takes a valuebetween 0 and 180, where 0 is the minimum position and 180 is the maximum position. For example:


myServo.write(90); // sets the servo to the middle position
Delay and repeat: After setting the servo position, use the delay() function to wait for a short period of time before setting the position again. This will cause the servo to move to the new position gradually. Repeat this process in a loop to continuously control the servo position. Here's an example code snippet that sets the servo to the middle position, waits for 2 seconds, then sets the servo to the maximum position and waits for another 2 seconds before repeating the cycle:



#include
Servo myServo;
void setup() {
myServo.attach(9);
}
void loop() {
myServo.write(90); // sets the servo to the middle position
delay(2000);
myServo.write(180); // sets the servo to the maximum position
delay(2000);
}

Note that you may need to adjust the delay time and servo position values to suit your specific requirements.



Goal: Control a servo motor with ESP32 in Wokwi



Step 1:Open Wokwi



Go to https://wokwi.com

What is wokvi3

Wokwi - World's most advanced ESP32 Simulator

Wokwi is an online simulator for electronics and embedded systems. It lets you simulate circuits, boards, sensors, and other components.

You can use Wokwi to prototype IoT projects.

Features Simulate popular boards: Simulate Arduino, ESP32, STM32, and Raspberry Pi Pico Use a large library of components: Includes sensors, LEDs, LCDs, motors, and relays Integrate with development environments: Integrates with VS Code, PlatformIO, and Arduino Debug code: Use the VS Code debugger to debug your code

Capture digital signals: Use the Virtual Logic Analyzer to capture digital signals in your simulation

Connect to the internet: Use the built-in WiFi Gateway to connect to the internet and use cloud services

  • Use cases
    Blink an LED on ESP32 Monitor the weather on ATtiny85 Control 32 servos with Arduino Mega Animate an LED Matrix with FastLED Connect to MQTT servers to send sensor data Query web services over HTTP, HTTPS, and web sockets Pricing Wokwi offers different plans for open source, personal, advanced, and commercial projects.









  • Photo of Your name

    Click "New Project"

    Choose "ESP32 Project"

    Photo of Your name



    Step 2:Add ESP32

    Click the "+" button or press I to open the Parts Library and:
    Add ESP32 Dev Module

    Photo of Your name



    Step 3:Add Servo Motor

    Click the "+" button or press I to open the Parts Library and Add Servo Motor

    Photo of Your name



    Step 4:Servo Motor to ESP32 Wiring in Wokwi



    Servo Pin Connect To (ESP32)
    VCC 5V
    GND GND
    Signal GPIO 18



    Photo of Your name





    Photo of Your name


    Step 5:Simulate


    Click the green “Play” button (▶️).
    Watch the servo motor sweep back and forth in simulation.