Skip to content

Embedded Programming

This week was all about exploring embedded programming—basically, how we write code that runs directly on microcontrollers to control hardware like sensors, LEDs, motors, etc. Unlike regular programming where your code runs on a computer, embedded programming deals with small, dedicated devices where the code needs to interact closely with the physical world.

What is Embedded Programming?

Embedded programming is basically writing code for small computers that are built into devices—like microcontrollers. These devices don’t have screens or keyboards like our laptops; instead, they interact with the physical world through sensors, LEDs, motors, and other hardware.

The main goal is to make these tiny computers perform specific tasks—like blinking an LED, reading a button press, or controlling a motor—by uploading code directly onto them. Unlike general-purpose programming, embedded programming is very closely tied to hardware. You're not just coding logic, you're also dealing with timing, power, and physical inputs and outputs.

Image

It’s used in everything from home appliances and smart wearables to industrial machines and robotics.

A. Understanding Toolchains

When we first started working with microcontrollers, we thought it would be as simple as writing code, pressing upload, and watching it work. Turns out, there’s a whole process happening behind the scenes—that’s what a toolchain is!

A toolchain is a set of tools that helps us write, compile, debug, and upload code to a microcontroller. Without it, our code is just text on a screen. Since each board has its own workflow, we had to figure out what worked best for each one.

The key components of a toolchain:

  1. Compiler: Converts code into something the microcontroller understands.
  2. Linker: Organizes the code and makes it executable.
  3. Debugger: Helps find and fix issues.
  4. Flashing tool: Uploads the program to the board.
  5. IDE (Integrated Development Environment): Where we write and test the code (e.g., Arduino IDE, VS Code, Thonny).

Group Assignment

B. Working with Microcontrollers

For this week’s group activity, our Fab Academy colleagues Samruddhi and Sharvari took the lead and carried it out. The documentation for this is linked.

What I Learned Throughout in Journey:

Ease of Use & Development

Feature ATmega328P (Arduino Uno) ESP32 RP2040 (Raspberry Pi Pico)
Ease of Setup Very easy – works out of the box with Arduino IDE Requires installing ESP-IDF or Arduino-ESP32 Simple but needs Pico SDK or MicroPython
Programming Language C/C++ (Arduino) C/C++, MicroPython C/C++, MicroPython
Library Support Extensive – many built-in libraries Large – supports Wi-Fi, Bluetooth, and IoT libraries Moderate – supports robotics and real-time applications
Development Tools Arduino IDE ESP-IDF, Arduino-ESP32, VS Code Pico SDK, Thonny, VS Code
Debugging Basic – print statements in serial monitor Advanced – supports logging and remote debugging Moderate – debug via SWD, print statements in serial monitor
Community Support Very large – many tutorials and examples Large – growing fast due to IoT demand Moderate – strong for robotics and real-time applications
Reliability Very stable, minimal crashes Can be unstable due to Wi-Fi tasks Stable, but some quirks in multi-core processing
Best Use Cases LED blinking, motor control, sensors IoT devices, smart home automation, web-based projects Robotics, real-time motor control, audio processing

Image

Technical Features

Feature ATmega328P (Arduino Uno) ESP32 RP2040 (Raspberry Pi Pico)
Clock Speed (Processing speed, MHz) 16 MHz 160–240 MHz (Dual Core) 133 MHz (Dual Core)
Cores (Number of CPU units) 1 (Single Core) 2 (Dual Core) 2 (Dual Core)
Flash Memory (Storage for program code) 32 KB 4 MB (External) 2 MB (External)
RAM (Temporary memory for running programs) 2 KB 520 KB 264 KB
GPIO Pins (General-purpose input/output for peripherals) 14 digital, 6 analog 34 GPIO 26 GPIO
ADC (Analog to Digital Converter for reading sensors) 10-bit ADC (6 channels) 12-bit ADC (18 channels) 12-bit ADC (3 channels)
PWM (Pulse Width Modulation for motors, LEDs, etc.) 6 PWM channels 16 PWM channels 26 PWM channels
Communication (Interfaces to connect with devices) I2C, SPI, UART I2C, SPI, UART, CAN, Ethernet I2C, SPI, UART
Power Consumption (Energy efficiency of the chip) Low High Moderate
Built-in Wireless (Wi-Fi & Bluetooth availability) No Yes (Wi-Fi + Bluetooth) No
Best for (Ideal applications) Beginners, basic electronics IoT, wireless communication, advanced applications Robotics, real-time applications, sensor-heavy projects

At first, toolchains felt overwhelming, but once we saw them in action, they made sense. Each board has a different workflow, but all follow the same basic steps:

writing code → compiling → debugging → flashing.

The right toolchain makes this process smoother, and choosing the right board depends on what we want to build!

Individual Assignment

A. My First Time with Wokwi – Debugging, Trial, and Success

Getting Started with Wokwi Image

Wokwi is an online microcontroller simulator—no downloads needed. You can access it directly from your browser.
I was excited to try it out. The interface was clean, and a default program was already running. It seemed easy—until I made changes.

Image

What I expected:
"I’ll tweak some values, and everything will work."

What actually happened:
"Why is nothing working?! What did I break?"

My Experiments

1.Running the Default Program – Success

I hit the play button on the default sketch. It worked smoothly!

Image

But I wasn’t here just to watch—I wanted to experiment.

2.Changing Color Names to 'Blood,' 'Muscle,' and 'Vein' – Instant Failure

Instead of "red, green, and blue," I tried naming colors after human anatomy.

Result: It didn’t work at all.

Lesson: Computers need predefined names or numeric values—they’re not poetic!

3.Printing Text – Displaying 'I am Devanshi'

Image

I changed the code to print my name on the serial monitor.

Result: It worked!

Lesson: When debugging, text output is often easier to troubleshoot than visuals.

4.Trying Neil Gershenfeld’s Fab Academy Code – Server Issues

Found a code from the Fab Academy website and pasted it into Wokwi.

Image

Issue: The website wouldn’t load due to high traffic.

Lesson: Online tools have limitations—sometimes, issues aren’t in our code but in the tool itself.

Debugging Code – Removing Unnecessary Elements

I simplified a complex program to make it run.

Image

New Problem: Unexpected errors appeared!

Lesson: Modifying someone else’s code is tricky—randomly deleting parts can break dependencies.

5.Final Attempt – Building My Own Circuit

I built a new project from scratch using an XIAO ESP32-C3, a servo motor, an LED, and two push buttons.

Image

Thought Process While Designing:

What should it do? I wanted a simple interaction where pressing buttons moved a servo and controlled an LED.

Images

Pin selection: The ESP32 has multiple GPIO pins, but I had to choose ones that supported my components.

Pull-up resistors: I used the INPUT_PULLUP setting to avoid floating inputs.

Servo power needs: Servos can be power-hungry, so I checked that my board could supply enough current.

Image

Code structure: I wrote a simple setup() to initialize components and a loop() to handle button presses.

Functionality:

Button 1 → Moves the servo left (0°) and turns the LED ON.

Button 2 → Moves the servo right (90°) and turns the LED OFF.

Steps to make it work:

Wiring the Components: Connected the buttons, servo, and LED to the ESP32.

Setting Up the Code: Defined pins, initialized components in setup(), and wrote logic in loop().

Testing & Debugging: Pressed buttons, checked responses, and fixed minor logic errors.

Final Run: Verified that the servo moved and the LED toggled as expected. Image

Result: It finally worked!

Lesson: Starting fresh is sometimes easier than fixing broken code.

Key Takeaways from My Wokwi Experience

  1. Not all changes are valid – Just because something makes sense to me (like "blood" as a color) doesn’t mean the computer understands it.

  2. Errors aren’t always obvious – Some problems took a long time to figure out, and others had no clear reason. Debugging is an art as much as a skill.

  3. Tool limitations exist – Online platforms depend on factors like server traffic. Sometimes, an issue isn’t in our code but in the tool itself.

  4. Writing my own code was easier – Instead of modifying a complex program, starting from scratch gave me more control.

  5. Persistence pays off – After multiple failures, getting a working circuit felt like a real achievement. This was my first embedded simulation, and it was totally worth it.

Since, WOKWI was not functioning conviniently due to heavy website traffic, using varied development programming software.

B. Beat Sync Lights – Let Your LEDs Dance! Working with Tinker Cad

Ever wanted your lights to dance with your music? That’s exactly what I built using an Arduino Uno and a sound sensor! Basically, the sensor listens for beats, and the Arduino makes the LEDs blink accordingly. It’s like a mini disco in your room!

How It Works?

  1. Sound sensor picks up music beats – It detects sound intensity (how loud it is).
  2. Arduino reads the sensor values – If the sound crosses a certain level, it knows a beat has hit.
  3. LED reacts to the beat – If the music is loud enough, the LED flashes. If it's quiet, the LED stays off.
  4. Adjust the sensitivity – You can tweak the threshold to make it more responsive to beats!

Things Needed to Build

  1. Arduino Uno
  2. Sound sensor (KY-038 or similar)
  3. LED(s)
  4. 220Ω resistors
  5. Jumper wires & breadboard
  6. Music! (The more bass, the better!)

Why I Picked Arduino Uno (and How I Hooked Everything Up)
I chose the Arduino Uno for this project because… well, it’s kind of the classic board everyone starts with. It’s simple to use, has enough pins, and works well with most basic components. Plus, I already had one lying around! Image

Also, since both the sound sensor and the LED work on 5V, the Uno made it really easy—no need to worry about extra power regulation or anything fancy.

This is how connection was made

Component Arduino Pin Reason / My Thought Process
Sound Sensor - VCC 5V To power the sound sensor. Arduino's 5V pin provides stable power for components.
Sound Sensor - GND GND Ground connection to complete the circuit—essential for everything to work.
Sound Sensor - OUT A0 (or D2) A0 for analog values (more control), or D2 for simple on/off behavior (digital read).
LED Anode (+) D9 Chose a digital pin to control LED blinking. D9 is just what I picked—it could be any.
LED Cathode (–) GND via 220Ω resistor To limit current to the LED and prevent burning it out. Resistor goes between LED and GND.

Putting It Together- Circuit Diagram

Image

Image

Circuit On Breadboard

Image

Hero Shots

Image Image

Original Design Files

Beat Sync Light

Wokwi Files

Light Name Appears RGB

Name of Person

Led with Motor