Week 4 : Embedded Programming
Overview
This week I programmed a microcontroller to both interact with a physical output device and communicate data over a wired connection. In my final project I hope to be able to communicate wirelessly. For my individual assignment I will use a Seeed Studio XIAO RP2040 running MicroPython to drive a vibrating motor while simultaneously transmitting live telemetry back to my computer over USB serial.
I chose a vibrating motor as my output device because it is a core component of my final project. This week gave me the opportunity to understand how to control it programmatically before integrating it into a larger system.
Notes on Interaction vs Communication:The vibrating motor is my local output device because it physically responds to the board's GPIO pins. The USB serial stream (visible in Thonny's shell) is my communication. My RP2040 board transmits structured text data to my computer over a wired connection in real time. I'm hoping by doing it this why this week's requirements are satisfied in a single program.
Assignment Requirements
Group Assignment
- Demonstrate and compare the toolchains and development workflows for available embedded architectures.
- Document your work to the group work page and reflect on your individual page what you learned.
Individual Assignment
- Browse through the datasheet for a microcontroller.
- Write and test a program for an embedded system using a microcontroller to interact with local input and/or output devices and communicate using remote wired or wireless connections.
Note: I am a remote student so I worked on this portion alone.
Notes on comparing toolchains
Comparing the RP2040 and the ATmega328 side by side made the differences between interpreted and compiled workflows very concrete. With the RP2040 and MicroPython, I can run a line of code instantly in the REPL and see the motor respond in real time. With the ATmega328 and Arduino IDE, the C++ code must be compiled into a binary on my computer first, then flashed to the board. That extra step is a meaningful difference in how quickly I can iterate and debug. The voltage difference (3.3V vs 5V logic) also matters practically. There are components that work safely with one board that may not be safe with the others.
Learning Outcomes
The official learning outcome for this week is to implement programming protocols. Through the completion of my group and individual assignments, I also worked toward developing the following technical competencies.
| Technical Competency | Application During This Assignment |
|---|---|
| Embedded Architectures | Exploring and comparing ARM and AVR microcontroller architectures. |
| Technical Documentation | Interpreting microcontroller datasheets and development board specifications. |
| Development Toolchains | Exploring Arduino IDE, Arduino C++, MicroPython, and Thonny. |
| Input and Output Configuration | Configuring analog sensor inputs and digital control outputs. |
| Embedded Programming | Developing, uploading, and testing programs on a microcontroller development board. |
| Communication Protocols | Implementing bidirectional USB serial communication between a microcontroller and a computer. |
| Testing and Calibration | Evaluating sensor readings and establishing appropriate activation thresholds. |
| Hardware and Software Integration | Troubleshooting PCB fabrication, electrical connections, and programming challenges. |
| Interdisciplinary Application | Integrating textile electronics techniques learned through Fabricademy into an embedded system. |
These competencies contribute to the development of the embedded programming, electronics design, and troubleshooting skills necessary for the completion of my Fab Academy final project.
Understanding Microcontroller Architecture
In the context of embedded electronics, microcontroller architecture can be understood as the internal blueprint of a microcontroller. It defines how the processor executes instructions, accesses memory, communicates with peripherals, and processes information.
For this assignment, I explored two different microcontroller architectures: AVR and ARM. Although both are based on Reduced Instruction Set Computer (RISC) principles, their internal organization and instruction sets differ.
Key Characteristics of Microcontroller Architecture
| Architectural Feature | Technical Description | My Interpretation |
|---|---|---|
| Bit Width | The width of the processor's native data registers and associated operations. | The width of the internal data highway. |
| Instruction Set | The machine-level instructions that a processor can execute. | The language understood by the processor. |
| Memory Organization | The arrangement and accessibility of program instructions and data. | How the processor organizes its instructions and workspace. |
| Registers | Small, fast storage locations used during processor operations. | The processor's immediate working memory. |
| Peripherals | Integrated hardware modules such as timers, ADCs, GPIO controllers, and communication interfaces. | The tools that allow the processor to interact with external devices. |
Understanding these characteristics helped me recognize that selecting a microcontroller involves more than comparing physical size or clock speed. The architecture, available memory, peripheral capabilities, and development environment must also support the intended application.
AVR Architecture — ATmega328P
The Adafruit Metro 328 is based on the ATmega328P, an 8-bit AVR microcontroller. AVR microcontrollers are widely used in introductory embedded electronics, Arduino-compatible development boards, and applications that require relatively simple sensing and control operations.
| Architectural Feature | ATmega328P Characteristics |
|---|---|
| Bit Width | 8-bit processor architecture. Larger numerical operations may require multiple processor instructions. |
| Instruction Set | AVR RISC instruction set. Many instructions execute in a single clock cycle, although some require multiple cycles. |
| Memory Organization | Harvard architecture, with separate program and data memory spaces. |
| Register Set | 32 general-purpose, 8-bit working registers. |
| Processing Configuration | Single-core microcontroller. |
Practical Implications
The ATmega328P is well suited to applications such as reading switches, collecting sensor data, controlling LEDs, operating actuators through appropriate driver circuits, and performing basic communication tasks.
Its relatively limited SRAM and processing resources also require greater consideration of memory usage when developing more complex embedded applications.
ARM Architecture — Raspberry Pi RP2040
The Seeed Studio XIAO RP2040 incorporates the Raspberry Pi RP2040 microcontroller, which contains two 32-bit ARM Cortex-M0+ processor cores.
In comparison with the ATmega328P, the RP2040 provides greater memory capacity, wider processor registers, additional hardware capabilities, and support for development environments such as MicroPython, CircuitPython, and compiled C/C++.
| Architectural Feature | RP2040 Characteristics |
|---|---|
| Bit Width | 32-bit processor architecture, allowing native operations on 32-bit data values. |
| Instruction Set | ARMv6-M architecture using the Thumb instruction set. |
| Memory Organization | Unified address space with memory-mapped peripherals, internal SRAM, and access to external flash memory. |
| Register Set | 16 architecturally visible core registers, including general-purpose registers, the stack pointer, link register, and program counter. |
| Processing Configuration | Two ARM Cortex-M0+ processor cores. |
| Programmable I/O | Dedicated Programmable Input/Output (PIO) hardware for implementing custom and timing-sensitive interfaces. |
Practical Implications
The RP2040 provides additional resources for applications requiring more complex programming, multiple peripherals, larger memory allocations, and flexible communication interfaces.
Its available memory also makes it possible to run an embedded Python interpreter, providing an alternative to a traditional compiled C/C++ development workflow.
Although the RP2040 contains two processor cores, taking advantage of both cores depends on how the application and development environment are configured.
Comparing toolchains and Development Workflows
I am a remote student and will have to complete the group assignment on my own. I currently have an Adafruit Metro and FabriXiao (from the Czech Republic and my Fabricademy course) available on hand for comparisons. I am concerned about the use of my FabriXiao as I used it heavily in the workshop I attended at FAB 25 in the Czech Republic and also used it extensively during my time as a student in the 2025/2026 Fabricademy course. I hope that I will be able to program and utilize it for this project as well, otherwise, I will need to source another chip. The FabriXiao utilizes the Seeed Studio XIAO-RP2040 board.
I decided to source another chip, I purchased a Xiao RP2040 and will us it below in my comparissons.
I analyzed and compared the toolchains, development workflows, and electrical differences between my available embedded architectures. Specifically, I contrasted the Seeed Studio XIAO RP2040 (running MicroPython via Thonny IDE) with the Adafruit Metro 328 (running C++ via Arduino IDE).
Microcontroller Specs Comparison
After examining the architectural differences between ARM and AVR microcontrollers, I compared the hardware specifications of the two development boards to better understand their capabilities and limitations.
| Hardware Feature | Seeed Studio XIAO RP2040 | Adafruit Metro 328 |
|---|---|---|
| Microcontroller | Raspberry Pi RP2040 | Microchip ATmega328P |
| Processor Architecture | 32-bit ARM Cortex-M0+ | 8-bit AVR RISC |
| Processor Cores | 2 | 1 |
| Clock Speed | Up to 133 MHz | 16 MHz board clock |
| On-Chip SRAM | 264 KB | 2 KB |
| Program Flash Memory | 2 MB external flash on the development board | 32 KB internal flash |
| Logic Voltage | 3.3 V | 5 V by default |
| ADC Hardware Resolution | 12-bit | 10-bit |
| Digital Communication Interfaces | UART, SPI, I2C, native USB | UART, SPI, I2C |
| Specialized Hardware | Programmable Input/Output (PIO) | Hardware timers and counters |
| Form Factor | Compact castellated development board | Arduino UNO-compatible footprint |
| Embedded Python Support | MicroPython and CircuitPython | Not supported by standard MicroPython distributions |
| Compiled Programming Support | C/C++ | C/C++ |
| Selected Development Environment | Thonny IDE | Arduino IDE |
Hardware Documentation
- Seeed Studio XIAO RP2040 — Official Documentation
- Adafruit Metro 328 — Hardware Specifications
- Microchip ATmega328P — Technical Documentation
Electrical Compatibility Considerations
One of the most important practical differences between these development boards is their logic voltage. The XIAO RP2040 uses 3.3 V logic, while the Metro 328 operates with 5 V logic in its default configuration.
Connecting incompatible voltage levels directly can damage a microcontroller. When integrating devices with different operating voltages, it is necessary to verify electrical compatibility and use appropriate level-shifting circuitry when required.
GPIO current ratings must also be considered. The ATmega328P's 40 mA per-pin absolute maximum rating is a damage-prevention limit rather than a recommended operating current. Higher-current devices, including vibration motors, should be controlled through appropriate external driver circuitry rather than powered directly from a GPIO pin.
Toolchain and Dev Workflow Comparison
In embedded programming, a development toolchain is the collection of software tools used to write, process, transfer, execute, and debug programs intended for a microcontroller.
For this comparison, I explored two different programming approaches: an embedded Python interpreter using MicroPython and Thonny, and a compiled C/C++ workflow using Arduino IDE.
| Workflow Component | XIAO RP2040 — MicroPython | Metro 328 — Arduino C++ |
|---|---|---|
| Programming Language | Python | C/C++ |
| Development Environment | Thonny IDE | Arduino IDE |
| Source File Format | .py | .ino, .cpp, .h |
| Program Processing | Python source is processed and executed by the MicroPython runtime. | Source code is compiled and linked into executable machine code on the computer. |
| Initial Board Preparation | Install MicroPython firmware. | Install the appropriate Arduino board package and select the board. |
| Program Transfer | Transfer or execute Python scripts through the USB serial connection. | Upload compiled firmware through the board's serial bootloader. |
| Interactive Execution | Read-Evaluate-Print Loop (REPL) allows individual commands to be executed interactively. | Program changes generally require recompilation and another upload. |
| Debugging | Interactive shell, error messages, and printed output. | Compiler messages, serial monitoring, and printed diagnostic output. |
| Memory Considerations | Additional memory is required to support the Python runtime. | Compiled programs avoid the need for a resident Python interpreter. |
| Development Advantages | Rapid experimentation and interactive testing. | Efficient execution and access to the Arduino library ecosystem. |
This comparison illustrates that the development workflow is influenced by both the microcontroller hardware and the selected programming environment. An ARM-based microcontroller is not limited to Python, and the RP2040 can also be programmed using compiled C/C++.
Understanding Firmware Installation and Program Upload
While comparing these development workflows, I identified an important distinction between installing firmware on a microcontroller and transferring an individual program to the device.
Remote Student Assignment Approach
As a remote Fab Academy student affiliated with the UNC Charlotte node, I completed my weekly embedded programming activities independently.
To explore the architectural differences and development workflows addressed in the group assignment, I selected the Seeed Studio XIAO RP2040 and the Adafruit Metro 328 as the subjects of my technical comparison.
My comparison focused on processor architecture, memory organization, electrical characteristics, programming languages, development environments, firmware installation, program execution, and debugging workflows.
My practical embedded programming work is documented in the individual assignment section below, where I designed, fabricated, assembled, programmed, and tested a functional embedded system using the XIAO RP2040.
Development Workflow Comparison Findings
Through my investigation of the RP2040 and ATmega328P, I identified several important differences between the selected embedded architectures and development environments.
| Comparison Area | Key Finding |
|---|---|
| Architecture | The RP2040 provides a dual-core 32-bit ARM architecture, while the ATmega328P uses a single-core 8-bit AVR architecture. |
| Memory Resources | The RP2040 provides greater SRAM capacity, supporting more complex applications and embedded Python environments. |
| Electrical Compatibility | Differences in GPIO logic voltage must be considered when selecting and connecting external components. |
| Programming Workflow | MicroPython supports interactive execution through a resident interpreter, while Arduino C++ uses a compiled programming workflow. |
| Debugging | MicroPython provides interactive debugging through the REPL, while Arduino IDE provides compiler feedback and serial monitoring. |
| Application Suitability | Microcontroller selection depends on the processing, memory, electrical, and peripheral requirements of the intended application. |
| Individual Assignment Selection | I selected the XIAO RP2040 and Arduino IDE for the practical development of my embedded system. |
This comparison informed my selection of hardware and software tools for the individual assignment. Rather than selecting a development environment solely based on ease of use, I considered the requirements of my intended embedded system and the programming skills that would support my final project.
Workflow Resources
Microcontroller Implementation
Microcontroller Exploration and Datasheet Review
Before developing my embedded system, I reviewed the official Raspberry Pi RP2040 datasheet and the Seeed Studio XIAO RP2040 development board documentation.
My objective was to understand the internal architecture of the RP2040, its available memory, GPIO functionality, analog input capabilities, electrical limitations, and communication interfaces. This information informed the hardware configuration and programming decisions for my individual assignment.
Technical Documentation Reviewed
| Resource | Information Provided | Application to My Assignment |
|---|---|---|
| Raspberry Pi RP2040 Datasheet | Processor architecture, memory, registers, electrical characteristics, and internal peripherals. | Understanding the capabilities and limitations of the microcontroller. |
| Seeed Studio XIAO RP2040 Documentation | Development board specifications, physical pin assignments, power connections, and programming resources. | Identifying appropriate pins for my input device, output device, and power connections. |
| Raspberry Pi Microcontroller Documentation | Overview of RP-series microcontroller features and available hardware resources. | Understanding the broader capabilities of the RP2040 architecture. |
The RP2040 datasheet describes the microcontroller at the chip level, while the Seeed Studio documentation explains how those capabilities are made accessible through the XIAO development board.
Core Architectural Features
The RP2040 contains several architectural features that make it suitable for embedded applications involving physical interaction, sensor monitoring, and communication.
| Feature | Datasheet Finding | Relevance to My Assignment |
|---|---|---|
| Processor Architecture | Two 32-bit ARM Cortex-M0+ processor cores. | Provides processing resources for embedded control and communication. |
| Clock Speed | Rated for operation up to 133 MHz under specified conditions. | Supports responsive sensor monitoring and output control. |
| SRAM | 264 KB of internal SRAM organized into six banks. | Provides working memory for variables, program execution, and communication buffers. |
| Flash Memory | The RP2040 supports external flash through a QSPI interface. The XIAO RP2040 includes 2 MB of external flash. | Provides storage for the uploaded embedded program. |
| Analog-to-Digital Converter | 12-bit ADC hardware with multiple analog input channels. | Allows changes in sensor voltage to be converted into numerical readings. |
| Digital GPIO | Configurable general-purpose input and output pins. | Allows the program to control the MOSFET connected to the vibration motor. |
| USB Controller | Integrated USB hardware. | Supports the USB serial communication used between my board and computer. |
Hardware Registers and GPIO Control
During my datasheet exploration, I investigated how software instructions are translated into physical changes at the microcontroller's pins. The RP2040 uses memory-mapped registers to configure and control its hardware peripherals.
| Register or Hardware Block | Function | Practical Application |
|---|---|---|
| SIO | Single-cycle input/output hardware supporting rapid GPIO access. | Provides hardware-level access to digital pin states. |
GPIO_OUT |
Stores the output logic state associated with GPIO pins. | Supports digital output control, such as switching a motor driver. |
GPIO_IN |
Provides access to digital input states. | Allows the processor to monitor digital input signals. |
GPIO_OE |
Controls whether the SIO output driver is enabled. | Supports configuration of GPIO direction. |
| Pad Control Registers | Configure electrical properties including pull-up and pull-down resistors. | Support appropriate electrical configuration of input and output pins. |
| ADC Peripheral | Converts analog voltage into a digital numerical representation. | Allows the program to monitor changes in the Velostat pressure sensor circuit. |
Datasheet Sections Relevant to My Assignment
| Datasheet Section | Subject |
|---|---|
| 1.4 | Pinout and pin functions. |
| 2.3 | Processor subsystem and single-cycle I/O. |
| 2.19 | GPIO configuration and control. |
| 4.9 | Analog-to-digital conversion. |
| Electrical Characteristics | Voltage limitations and electrical operating conditions. |
Connecting Datasheet Research to Programming
Although my individual assignment uses the higher-level functions available through Arduino C++, these functions ultimately interact with the microcontroller's underlying hardware.
For example, pinMode() configures pin behavior, digitalWrite() controls a digital output, and analogRead() obtains a numerical representation of an analog input voltage.
Understanding the underlying hardware helped me distinguish between the instructions written in my program and the physical operations performed by the microcontroller.
A note and update on the table above learned during the System Integraton weekly review: I chose to change my board for my final project from a RP2040 to a RP2350 because of voltage and electrical safety concersn related to the RP2040. The RP2040 can be completely destroyed by electrical faults. To understand these more fully please visit this link: Xiao Charging Situation
Electrical Characteristics and Safety Considerations
The Seeed Studio XIAO RP2040 operates using 3.3 V GPIO logic. Understanding the distinction between board supply voltage, GPIO voltage, and allowable output current is important when connecting external components.
The GPIO pins are intended primarily for transmitting and receiving electrical signals. Components with higher current requirements, such as motors, should be controlled using appropriate external driver circuitry.
| Electrical Consideration | Design Implication |
|---|---|
| 3.3 V GPIO Logic | External signals must remain within the permitted voltage range. |
| GPIO Current Limitations | Higher-current loads require suitable driver circuitry. |
| Inductive Loads | Motors require protection against voltage transients produced during switching. |
| Power Supply Configuration | The power source must be appropriate for both the development board and connected components. |
| Electrical Isolation Between Traces | PCB fabrication and assembly must prevent unintended connections and short circuits. |
Retrospective Update from System Integration Week
During subsequent final project development and system integration, I encountered additional electrical considerations related to power management and the integration of XIAO development boards.
These experiences led me to reconsider my microcontroller selection and investigate the XIAO RP2350 as an alternative to the XIAO RP2040 for portions of my final project.
This change was informed by the evolving electrical and functional requirements of my project. Both microcontroller families require careful attention to supply voltage, GPIO limitations, power management, and circuit protection.
This experience reinforced the importance of reviewing electrical characteristics in addition to processor architecture and programming capabilities when selecting a microcontroller.
Development Board Pin Selection
After reviewing the RP2040 datasheet, I used the Seeed Studio XIAO RP2040 pinout documentation to identify the physical board connections required for my individual assignment.
My completed embedded system required an analog input for the textile pressure sensor, a digital output for the motor driver, appropriate power and ground connections, and a communication interface between the development board and my computer.
| XIAO Board Connection | RP2040 Connection | Configuration | Function in My System |
|---|---|---|---|
| A0 / D0 | GPIO26 / ADC0 | Analog input | Reads the voltage associated with the textile pressure sensor. |
| D2 / A2 | GPIO28 / ADC2 | Digital output | Controls the gate of the AO3400 MOSFET through a resistor. |
| 3V3 | Board power supply | 3.3 V supply | Provides the documented positive supply connection for the motor circuit. |
| GND | Common ground | Electrical reference | Provides a common reference for the microcontroller and connected circuitry. |
| USB-C | Native USB interface | Wired communication | Supports programming, sensor telemetry, incoming commands, and outgoing event messages. |
Although GPIO26 and GPIO28 both support analog input functionality, their roles in my embedded system are different. GPIO26 is used to obtain analog sensor readings, while GPIO28 is configured as a digital output to control the motor driver.
Within my Arduino program, these pins are referenced using the development board aliases A0 and D2.
Analog-to-Digital Conversion
The RP2040 contains a 12-bit ADC peripheral. However, the resolution of the numerical readings returned by Arduino's analogRead() function depends on the configuration of the programming environment.
Rather than assuming that the ADC readings represented resistance or force directly, I used the numerical values observed during testing to establish a practical activation threshold for my textile pressure sensor.
Group Assignment Reflection
Comparing ARM and AVR architectures helped me better understand the relationship between microcontroller hardware, available processing resources, programming languages, and development toolchains.
One of the most significant differences I identified was the development workflow associated with interpreted and compiled programming environments. MicroPython provides an interactive approach to experimentation through its REPL, while Arduino IDE requires compilation and uploading of the program before executing revised instructions on the microcontroller.
I also developed a greater appreciation for the importance of electrical compatibility. Differences in GPIO voltage, memory capacity, available peripherals, and current limitations influence both the selection of a microcontroller and the design of the circuitry connected to it.
Through my previous Fabricademy experience with the FabriXiao, I had already been introduced to compact embedded development boards and their applications within textile electronics. This assignment allowed me to further explore the underlying architecture and programming environments associated with those devices.
Toolchain Selection for My Individual Assignment
Although MicroPython provides advantages for interactive experimentation, I selected Arduino IDE and Arduino C++ for my individual assignment.
My final project involves integrating physical input devices, haptic feedback, display functionality, storage, and communication between embedded devices. The Arduino ecosystem provides access to libraries and development resources that are relevant to these intended applications.
By selecting Arduino IDE for this week's individual assignment, I was able to begin developing familiarity with the programming environment and embedded development practices that I intended to apply throughout subsequent assignments and final project development.
What I took away from learning about toolchains and develpment workflows
The RP2040's mass storage upload mechanism (drag-and-drop UF2) is convenient for CircuitPython but Arduino IDE's direct COM port upload is faster for iterative testing. For my final project on the nRF52840 which requires BLE, SD card, and display libraries, Arduino IDE will be what I work with to complete the program. I made the decision to use Arduino for this week's individual work to build that muscle memory now.
Individual Assignment — Embedded System Development
Project Objective
For my individual assignment, I developed a prototype embedded system that integrates physical user interaction, haptic feedback, and bidirectional wired communication.
This project serves as an early functional prototype for the wearable component of my Fab Academy final project. My objective was to investigate how a microcontroller could detect a physical interaction, provide haptic confirmation, and communicate information to another device.
System Architecture
| System Component | Hardware or Software | Function |
|---|---|---|
| Processing | Seeed Studio XIAO RP2040 | Executes the embedded program and coordinates system behavior. |
| Local Input | Velostat textile pressure sensor | Detects physical interaction through changes in electrical resistance. |
| Local Output | DC vibration motor | Provides physical haptic feedback to the user. |
| Output Driver | AO3400 N-channel MOSFET | Switches the motor circuit in response to the microcontroller's digital output. |
| Communication | USB serial connection | Transfers sensor readings, event messages, and commands between the board and computer. |
| Programming Environment | Arduino IDE / Arduino C++ | Supports program development, uploading, monitoring, and testing. |
| Hardware Integration | Custom milled PCB | Provides electrical connections between the microcontroller and supporting components. |
Intended System Behavior
- The microcontroller monitors the textile pressure sensor.
- The embedded program compares the sensor reading with a calibrated activation threshold.
- When a qualifying press is detected, the program transmits an event message to the computer.
- The vibration motor activates to provide haptic confirmation.
- The microcontroller also monitors the USB serial connection for incoming commands.
- A valid incoming motor command activates the motor independently of the physical pressure sensor.
- The microcontroller transmits a confirmation message after completing the commanded motor activation.
This configuration demonstrates both local physical interaction and bidirectional communication within a single embedded system.
Electronic Components and Materials
The following components and materials were used during the design, fabrication, assembly, and development of my embedded system.
| Component or Material | Specification | Quantity | Function |
|---|---|---|---|
| Microcontroller Development Board | Seeed Studio XIAO RP2040 | 1 | Embedded processing and communication. |
| N-channel MOSFET | AO3400 | 1 | Controls the motor circuit. |
| Diode | 1N4148W | 1 | Provides a path for inductive current when the motor is switched off. |
| Gate Resistor | 100 ohms | 1 | Limits transient current during MOSFET gate switching. |
| Vibration Motor | DC coreless vibration motor | 1 | Provides haptic feedback. |
| Motor Connector | 2-pin header | 1 | Connects the vibration motor to the PCB. |
| Tactile Switch | 6 mm mechanical push button | Initial design only | Originally intended as the physical input device. |
| Pressure-Sensitive Material | Velostat | As required | Provides pressure-dependent electrical resistance. |
| Conductive Fabric | Textile electrode material | As required | Forms the conductive surfaces of the textile sensor. |
| Conductive Thread | Conductive textile connection material | As required | Provides electrical connections within the textile sensor assembly. |
| Copper-Clad Board | PCB milling stock | 1 | Substrate for the custom fabricated circuit board. |
| USB-C Data Cable | Power and data capable | 1 | Supports programming and serial communication. |
Equipment and Software
| Equipment or Software | Application |
|---|---|
| KiCad | Schematic development, PCB layout, ERC, and DRC. |
| Inkscape | Preparation and modification of PCB fabrication files. |
| Mods CE | Generation of PCB milling toolpaths. |
| Roland SRM-20 | PCB trace milling and exterior cutting. |
| Roland VPanel | Machine control and origin configuration. |
| Soldering Station | Electronic component assembly. |
| Digital Multimeter | Continuity testing and electrical troubleshooting. |
| Arduino IDE | Embedded programming, uploading, and serial monitoring. |
To integrate the electronic components of my embedded system, I designed and fabricated a custom printed circuit board. My workflow combined electronic design, vector file preparation, subtractive manufacturing, and electrical verification.
| Development Stage | Software or Equipment | Output |
|---|---|---|
| Schematic Design | KiCad | Electrical circuit and component connections. |
| Schematic Verification | KiCad ERC | Electrical rule verification. |
| PCB Layout and Routing | KiCad PCB Editor | Physical component placement and copper trace routing. |
| PCB Design Verification | KiCad DRC | Design rule verification. |
| Fabrication File Preparation | Inkscape | Separate copper trace and exterior cutting files. |
| Toolpath Generation | Mods CE | Machine-readable PCB milling files. |
| PCB Fabrication | Roland SRM-20 | Physically milled printed circuit board. |
| Assembly and Verification | Soldering station and multimeter | Assembled circuit and electrical testing results. |
Drawing The Schematic in KiCAD
KiCad
After creating a new project in KiCad, I placed symbols for the XIAO RP2040. Since KiCad does not natively store this symbol I did have to download the Seeed Studio XIAO Series library and the associated footprint libraries etc in order to complete this PCB. After loading the library I:
- Added the symbol for a AO3400 MOSFET
- Added the symbol for a 1N4148W diode
- Added the symbol for a 100 ohm resistor
- Added the symbol for a tactile button
- Added a 2pin motor header for connecting my haptic motor later
Understanding the Motor Driver Circuit
The vibration motor is controlled through an external MOSFET circuit rather than being powered directly from the microcontroller's GPIO pin.
This configuration allows the microcontroller to provide a digital control signal while the motor receives current through a separate switching path.
| Component | Function in the Motor Circuit |
|---|---|
| AO3400 MOSFET | Functions as a low-side electronic switch controlling the motor's connection to ground. |
| 100 Ohm Resistor | Connects the microcontroller's output to the MOSFET gate and limits transient gate charging current. |
| 1N4148W Diode | Provides a flyback current path intended to reduce voltage transients when the inductive motor is switched off. |
| Vibration Motor | Converts electrical energy into physical vibration for haptic feedback. |
Motor Switching Operation
- The microcontroller configures D2 as a digital output.
- When D2 is set HIGH, the MOSFET gate receives a control signal.
- The MOSFET conducts, completing the motor's current path to ground.
- The motor activates and produces vibration.
- When D2 is set LOW, the MOSFET stops conducting and the motor is switched off.
- The flyback diode provides a path for the motor's remaining inductive current during switching.
This hardware configuration allows the embedded program to control the timing of the vibration motor using digital output instructions.
Future Circuit Improvements
For future iterations of the wearable system, I would evaluate the motor's operating and startup current, the current capacity of the power supply, the MOSFET's switching characteristics at 3.3 V gate drive, and the suitability of the selected flyback diode.
I would also consider adding a gate pull-down resistor to establish a defined OFF state while the microcontroller is starting or its GPIO pin is not actively configured.
Electrical Rules Check (ERC) | Working towards getting 0 errors in the ERC
This was an extremely tedious step.
Running the Electrical Rules Checker revealed two issues I had to work through. First, the diode wasn't annotated yet. This was a pretty easy fix. I ran the annotate schematic function under the tools in KiCad to auto-number everything
Next I was getting errors because I forgot to show that the pins I was not connecting to were not supposed to have any connections. I went back and added no-connect flags on all of the unused GPIO pins
The part that took me a bit of work was linking the actual XIAO RP2040 to the schematic as a symbol and as a footprint. The library that I download wasnt loading initially. I kept getting a foorprint library warning for U1 no matter how many times I reinstalled and closed the program and restarted it. Eventually I was able to instal the library through KiCad's plugin content manager after realizing that I was downloading the file to a folder that was not routing to the actual KiCad program file in my file explorer. After installation the ERC passed with 0 errors and 0 warnings.
Completing the Electrical Rules Check with zero errors and zero warnings confirmed that the schematic satisfied the electrical rules configured within KiCad.
However, passing ERC does not independently guarantee that every component selection or electrical connection is appropriate for the intended physical application. Additional review and physical testing will still be performed.
PCB Layout, Component Placement, and Routing
I used the "PCB from Schematic" funcction to open the PCB editor and start moving things around in a way that I thought would most resemble placement for my eventual final project board
All of the footprints came in nowhere near where I wanted them so I took a few minutes to move them to spaces that I hoped would make sense when I run the DRC and actually start soldering later.
The ratsnest is extremely annoying, honestly, and really takes some patience to ensure that none of the wires are crossing and that components that have shared functionality (like the mosfe and resistor) are close to avoid making my board too chunky. Keeping in mind that this is eventually going to translate into a wearable, I'm really trying to keep space tight on the board.
Once I had the components placed I drew the board outline on the Edge Cuts layer with plans to round the corners out in Inkscape later. Personally, I love using inkscape to make corrections to trace width, pad width, and any other changes that will make the board function better. I was trained using inkscape years ago so I just prefer incorporating it for these steps.
Design Rules Check (DRC)
Finally, I was ready to run the DRC (though I was EXTREMELY nervous), thankfully I had 0 errors.
The Design Rules Check returned zero errors for the PCB layout. This indicated that the routed board satisfied the design rules configured within KiCad at that stage of development.
Because the PCB would be manufactured using a desktop milling process, I also needed to consider tool diameter, trace width, copper clearance, and the limitations of the selected fabrication method.
Preparing Fabrication Files in Inkscape
I exported two separate SVG files and also a PDF (just because, I technically only needed the SVGs for Inkscape)
- F.CU only
- Edge.Cuts only
I opened both files simultaneously in Inkscape and renamed pieces accordingly in the layers panel.
I like to go stroke by stroke between pads and combine them to make sure my traces are fully connecting. There are faster ways to do this but I feel like this helps me to ensure that I know for sure everything is connecting in the way I intended in KiCad.
Next I went in and changed the stroke widths from .200 to .300 (Previously I'd noticed that 200 is too thin for traces, in my opinion)
Then, I saved the whole thing as my trace layer to be routed on the SRM-20 through Mods CE. I like to keep the exterior cut in during the trace routing just in case I've made any spacing issues or If I can actually make the edge cut closer to the boarders of the pads and traces.
Finally, I hide everything except the edge cuts and save just the edge cut to be routed alone in the SRM-20
Keep in mind, I save these as plain SVGs NOT Inkscape SVGs for use in Mods CE
Generating PCB Milling Toolpaths in Mods CE
PCB Milling Tool Selection
| Milling Operation | Tool | Purpose |
|---|---|---|
| Copper Trace Milling | 1/64 inch flat end mill | Removes copper between electrical traces and pads. |
| Exterior Cutting | 1/32 inch flat end mill | Cuts the fabricated PCB from the surrounding substrate. |
I verified the selected tool within Mods CE before generating each toolpath. I also maintained the same X and Y origins between milling operations and established an appropriate Z origin after changing tools.
I use Chrome to open and operate Mods CE. I do this because Neil mentioned it in a class once and I noticed it "behaves" better than using microsoft Edge. I'm not sure of the reasons why it moves more quickly and seemlessly but it does.
Using the Navigation Menu on the top left side, I go down to the SRM-20 and choose PCB milling
I cut my traces using a 1/64 flat endmill and I like to choose this before I even inport my file. I just would HATE to have the wrong tool chosen and break a bit because this setting was off.
Next, I go ahead and bring in my trace file. I double check that I have the correct bit chosen before moving to the next step (yes I double check this because I really don't want to waste any bits).
I make sure to set my machine X, Y, and Z to zero because I choose my XYZ height and location based on the spoilboard I am currently using. I use different spoil boards based on other projects that are simultaneously milling. I use the VPanel to make all of these adjustments live.
Finally I create the file and use the Mods' preview to make sure it's looking how I expect before exporting the file
PCB Milling Using the Roland SRM-20
I already had a wax sacrificial board taped down to the work plane on the SRM-20 from a previous project. It's on there with a LOT of scotch double sided (permenant) tape. The top of the wax has already been surface planed to make sure it's flat. I double check using a small level that I keep handy thats usually used for woodworking
Once I have the file ready, I move back into Vpanel, load the output and start the cut.
The mills take a few minutes depending on the project. Once it's done I grab the vaccuum and remove all particles before starting the edge cut. I do this so I can examine the board and make any corrections before doing the edge cuts. I feel like this is important because I'd rather remill while it's still physically connected to the rest of the copper board than when it is shifting a little here and there because it's no longer connected to the rest of the well adheared copper board.
Next, I moved on to the edge cut following the same procedure as abov; however, this time I double check that my 1/32 flat endmill is the bit that is chosen.
Keep in mind, before starting the milling process I had to change the bits out and rezero the Z axis ONLY to ensure I actually am in the exact same place as my original cut. I make sure to jog to the previous X/Y zero and then zero my Z because I've already removed the copper since my trace cut INCLUDES my edges. I only rezero from the very top of the copper if i've adjust the edge cut at all.
I actually use a sewing Pin to remove the board. I find a sewing pin is small enough to get inbetween the sides and also doest scratch the surface of the PCB as much as the flat head screwdriver I used to use.
PCB Soldering and Assembly
Component Assembly Sequence
Before soldering the electronic components, I cleaned the milled PCB with isopropyl alcohol to remove surface residue that could interfere with solder adhesion.
I assembled the components in the following sequence, beginning with the smaller surface-mounted components before moving to the larger connectors and development board.
| Assembly Order | Component | Assembly Consideration |
|---|---|---|
| 1 | 1N4148W Diode | Verify correct polarity and avoid excessive heating. |
| 2 | AO3400 MOSFET | Verify component orientation and pin alignment. |
| 3 | 100 Ohm Resistor | Establish reliable solder connections between pads. |
| 4 | 2-Pin Motor Header | Maintain mechanical alignment and electrical continuity. |
| 5 | Seeed Studio XIAO RP2040 | Align the development board with the fabricated footprint. |
I set my soldering iron to 350 degrees Celsius during assembly. The small surface-mounted components required careful placement and controlled heating to avoid damaging the copper pads.
Although some of my solder joints were not visually ideal, I evaluated the electrical connections using a multimeter before applying power to the board.
Continuity Checks
Before plugging in anything I made sure to check all traces and pads for continuity. I use a multimeter for this step and mine produces a beep when there is continuity
| Connection Tested | Expected Result | Observed Result | Interpretation |
|---|---|---|---|
| 3V3 to Motor Pin 1 | Continuity | Audible beep | Positive motor supply connection established. |
| GND to MOSFET Source | Continuity | Audible beep | Ground connection established. |
| D2 to Gate Resistor | Continuity | Audible beep | Microcontroller control signal trace connected to the resistor. |
| Motor Ground Connection to MOSFET Drain | Continuity | Audible beep | Motor switching path established. |
| 3V3 to GND | No direct continuity | No audible beep | No low-resistance short detected by the continuity test. |
These checks provided an initial verification of the assembled circuit. However, continuity testing alone does not guarantee that the board is free from every possible electrical fault.
During additional inspection and troubleshooting, I identified manufacturing and assembly issues that required correction before completing the embedded programming portion of the assignment.
Horrific Problems after Soldering (lol)
Issue 01 — Unintended Copper Bridge
After milling, a continuity check revealed a beep between a signal trace and an adjacent XIAO pad. I pulled out a magnifing glass and noticed that a copper bridge from a trace routed too close to the pad.
I was extremely annoyed because i'd already removed the board and also connected pieces so I was immediately worried that I might accidently mess up a joint or component when trying to fix this. initially I considered using the dremel to clear it but decided that was probably too extreme. I grabbed an Xacto knife that has lost it's point (its square at the tip now) and slowly lightly scored it until I isolated the channel.
Lesson Learned
Increase clearances in KiCad before exporting.
Issue 02 — Lifted Copper Pad
While soldering the 1N4148W diode I held the iron on the cathode pad too long and lifted the copper. The pad came up with the diode leg and i lost continuity completely in this area.
I grabbed some wire from what I'd clipped from the diode earlier to make it shorter and made a bridge. Thankfully this restored continuity; however, the beauty of my board was decreasing lol.
Lesson Learned
Keep the iron off of the board and move quickly when soldering.
Issue 03 - Tactile Switch Failure | TWO defetive tactile buttons
I wont name the brand but I tried two different 6mm tactile buttons as my loacal input devices. Both failed continuity testing. On both buttons all four legs beeped to eachother without pressing the button meaning the button was somehow permanently closed. Those were the only buttons I had that would fit the board
I had to take a break for lunch at this point because I was extremely annoyed at the thought of possibly having to stop for days to find a new button or create a completely new PCB. I was not trying to do either.
While eating it occured to me that this would be a great opportunity to go back to something I learned in Fabricademy a few weeks ago. A fabric based button.
I ended up making a velostat fabric pressure sensor as a buttton. This also works a lot better towards my final project concept as well. A win is a win. (I added the steps to this below)
Issue 04 - Ghost PCB | USB Communication Failure
Eventually I was ready to plug in the board to see if I could get something going through the IDE. Unfortunatley nothing appeard in my Device Manager.
After some trial and error I realized that I'd grabbed a USB c cable that goes to my portable charger and was not data capable.
i went and grabbed my iphone USBc charger and it immediately showed up as COM7 in the IDE
Hardware Troubleshooting Summary
| Issue | Diagnostic Method | Identified Cause or Finding | Corrective Action | Lesson Learned |
|---|---|---|---|---|
| Unintended electrical connection between adjacent traces and pads. | Continuity testing and magnified visual inspection. | Unremoved copper created an unintended conductive bridge. | Carefully isolated the copper connection and retested continuity. | Increase appropriate PCB clearances before fabrication. |
| Loss of electrical continuity at the diode connection. | Visual inspection and multimeter testing. | A copper pad lifted during soldering. | Installed a conductive wire bridge to restore the connection. | Reduce soldering dwell time and avoid excessive heating of copper pads. |
| Tactile switches did not exhibit the expected switching behavior. | Continuity testing across the switch terminals. | Both switches appeared to remain electrically connected during testing. | Replaced the intended mechanical input with a Velostat textile pressure sensor. | Verify component pinouts and functionality before circuit design and assembly. |
| Microcontroller was not recognized by the computer. | Device Manager inspection and USB cable substitution. | The original USB-C cable did not provide the required data connection. | Replaced the cable with a data-capable USB-C cable. The board appeared as COM7. | Verify cable functionality before assuming that a PCB or microcontroller has failed. |
Reflection on Hardware Troubleshooting
The difficulties encountered during PCB fabrication and assembly reinforced the importance of evaluating an embedded system systematically.
Rather than immediately assuming that the microcontroller or program was responsible for an unexpected result, I investigated the individual components, electrical connections, fabrication quality, and communication hardware.
The most significant design improvement resulting from this troubleshooting process was the transition from a mechanical tactile switch to a textile-based pressure sensor. This adaptation allowed me to continue developing the embedded system while incorporating techniques from Fabricademy and moving closer to the intended wearable functionality of my final project.
Input Device - Textile Pressure Button
Integrating Fabricademy Techniques into Fab Academy
My original embedded system incorporated a mechanical tactile push button as the local input device. However, after encountering unexpected continuity testing results with the tactile switches available to me, I began exploring alternative methods of detecting physical user interaction.
During my participation in the 2025–2026 Fabricademy program, I learned how conductive textiles and pressure-sensitive materials could be combined to create flexible electronic components. I realized that these techniques could provide an alternative input device without requiring me to completely redesign and fabricate another PCB.
I decided to develop a textile-based pressure sensor using Velostat, conductive fabric, and conductive thread. This approach also aligned more closely with the wearable wristband component of my Fab Academy final project.
| Design Consideration | Mechanical Tactile Switch | Textile Pressure Sensor |
|---|---|---|
| Physical Structure | Rigid electronic component | Flexible layered material |
| Electrical Response | Open or closed electrical connection | Pressure-dependent electrical resistance |
| Input Interpretation | Digital HIGH or LOW state | Analog reading evaluated against a threshold |
| Wearable Integration | Requires accommodation of a rigid component | Can potentially be integrated into flexible textile structures |
| Programming Considerations | Switch state detection and debouncing | Sensor calibration, threshold detection, and filtering |
Although this design iteration originated from a hardware troubleshooting challenge, it provided an opportunity to combine digital fabrication, embedded programming, and textile electronics within a single functional prototype.
Understanding Velostat
Velostat is an electrically conductive, pressure-sensitive material that can be used to construct flexible resistive sensors. Its effective electrical resistance generally decreases as pressure is applied.
By placing Velostat between two conductive textile electrodes, I was able to create a flexible sensing structure that responds to physical compression.
Textile Sensor Materials
| Material | Electrical or Mechanical Function |
|---|---|
| Conductive Fabric | Provides conductive electrode surfaces on either side of the pressure-sensitive material. |
| Velostat | Provides a pressure-dependent resistive layer between the electrodes. |
| Conductive Thread | Provides electrical connections within the textile sensor assembly. |
Sensor Construction and Operating Principle
The sensor uses a layered structure in which Velostat is positioned between conductive fabric surfaces. When pressure is applied, the electrical resistance between the conductive surfaces changes.
Conductive textile connections allow the sensor to be incorporated into the embedded system. The resulting electrical signal is monitored using the analog input functionality of the XIAO RP2040.
Unlike a conventional mechanical switch, this structure does not simply alternate between two defined electrical states. Its response varies with applied pressure, making calibration an important part of the embedded programming process.
Electrical Integration of the Textile Pressure Sensor
The textile pressure sensor was connected to the analog input functionality of the Seeed Studio XIAO RP2040 using the A0 development board pin.
Velostat changes electrical resistance in response to applied pressure. However, the microcontroller's analog-to-digital converter measures voltage rather than resistance directly. The numerical values obtained from the sensor therefore depend on its electrical configuration and the voltage presented to the analog input.
During testing, I observed that the numerical readings returned by the analog input decreased when pressure was applied to my textile sensor.
| Sensor Condition | Material Response | Observed Program Response |
|---|---|---|
| No applied pressure | Relatively higher electrical resistance | Higher numerical analog readings |
| Applied pressure | Reduced effective electrical resistance | Lower numerical analog readings |
| Pressure released | Resistance moves toward the uncompressed condition | Analog readings are expected to move toward the resting range |
Interpreting the Sensor Signal
My objective was not to measure an absolute physical force or calculate an exact resistance value. Instead, I used the analog readings to distinguish between intentional user interaction and the resting condition of the sensor.
This approach allowed the textile pressure sensor to function as a programmable input device. The activation threshold could be adjusted within the embedded program based on observed sensor behavior.
Embedded Programming Workflow
Selecting the Programming Environment
For the practical implementation of my embedded system, I selected Arduino IDE and Arduino C++ as my development environment and programming language.
Although I explored MicroPython and other embedded Python development workflows during the group assignment portion of this week, I decided to use Arduino IDE because it aligned with the development tools I intended to use for my final project.
My final project involves a handheld journaling console and a wearable device that provides haptic feedback. At this stage of development, I was investigating the Seeed Studio XIAO nRF52840 for wireless communication between the devices.
The Arduino ecosystem provides libraries and development resources for Bluetooth Low Energy (BLE), display interfaces, SD card communication, and physical input and output devices. Developing familiarity with this environment during Week 04 would support my work in subsequent assignments.
| Selection Criteria | Relevance to My Project |
|---|---|
| Microcontroller Support | Development support for the XIAO RP2040 and other microcontrollers considered for my final project. |
| Library Availability | Access to libraries for communication, displays, storage, and peripheral integration. |
| Serial Monitor | Provides a convenient interface for observing sensor readings and transmitting commands. |
| Programming Consistency | Allows me to develop familiarity with a common programming environment across multiple assignments. |
| Iterative Development | Supports repeated compilation, uploading, testing, and modification of embedded programs. |
Arduino IDE Configuration and Board Preparation
Before developing and uploading my embedded program, I configured Arduino IDE to support the Raspberry Pi RP2040 microcontroller used on my Seeed Studio XIAO development board.
| Configuration Parameter | Selected Configuration |
|---|---|
| Development Environment | Arduino IDE |
| Programming Language | Arduino C++ |
| Board Package | Raspberry Pi Pico/RP2040 by Earle F. Philhower, III |
| Selected Development Board | Seeed Studio XIAO RP2040 |
| Communication Port | COM7 during my testing session |
| Serial Monitor Setting | 115200 baud |
| Physical Connection | USB-C data cable |
Programming and Upload Procedure
- Install the Raspberry Pi Pico/RP2040 board package through the Arduino IDE Boards Manager.
- Connect the XIAO RP2040 to the computer using a USB-C cable capable of transmitting data.
- Select the Seeed Studio XIAO RP2040 from the available board configurations.
- Select the communication port associated with the connected development board.
- Develop the embedded program using Arduino C++.
- Compile the program and upload it to the microcontroller.
- Open the Arduino Serial Monitor to observe program output and transmit test commands.
- Evaluate the physical behavior of the connected input and output devices.
Upload Results
After resolving the USB cable issue described in my hardware troubleshooting section, the XIAO RP2040 appeared as COM7 within Arduino IDE.
During the upload process, the development board entered its bootloader mode. The board initially blinked before completing the firmware upload. Once the upload was complete, I was able to proceed with testing the embedded system.
Development Environment Resources
Original Embedded Program
I developed an Arduino C++ program that combines analog sensor monitoring, digital output control, conditional decision-making, and bidirectional serial communication.
The program was designed to detect physical interaction with the textile pressure sensor, activate a vibration motor for haptic confirmation, transmit event messages to a connected computer, and respond to incoming serial commands.
Program Functional Requirements
| Program Requirement | Implementation |
|---|---|
| Monitor physical user interaction. | Read the textile pressure sensor using analogRead(). |
| Identify intentional pressure. | Compare the analog reading with a calibrated threshold. |
| Provide haptic feedback. | Activate the motor using a digital output and MOSFET driver circuit. |
| Transmit sensor information. | Print numerical analog readings through USB serial communication. |
| Transmit interaction events. | Send the NEXT message when the activation condition is satisfied. |
| Receive external instructions. | Monitor incoming serial data for the MOTOR_ON command. |
| Confirm command completion. | Transmit the MOTOR_DONE message after the commanded motor pulse. |
Arduino C++ Source Code
The following source code represents the embedded program used to operate and test my physical prototype.
// ─────────────────────────────────────────────────────────────
// Fab Academy Week 4 — Embedded Programming
// Board: Seeed Studio XIAO RP2040
// Toolchain: Arduino IDE + Raspberry Pi Pico/RP2040 board package
// Input: Velostat fabric pressure sensor on A0
// Output: DC coreless vibration motor via AO3400 MOSFET on D2
// Communication: Bidirectional USB serial at 115200 baud
// ─────────────────────────────────────────────────────────────
const int buttonPin = A0; // velostat pressure sensor — analog input
const int motorPin = D2; // MOSFET gate — digital output
// Threshold calibrated from live Serial Monitor testing:
// At rest: sensor reads 100–200 (high resistance, no pressure)
// Pressed: sensor reads as low as 5 (low resistance, pressure applied)
// Threshold set to 20 — only genuine press triggers
int threshold = 20;
void setup() {
Serial.begin(115200);
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, LOW);
Serial.println("Week 4 ready");
}
void loop() {
// Read analog pressure value from velostat sensor
int pressure = analogRead(buttonPin);
Serial.println(pressure); // live telemetry for monitoring and calibration
// Pressure DECREASES under compression (velostat behavior)
// Trigger when value drops below threshold
if (pressure < threshold) {
Serial.println("NEXT"); // signal to computer application
pulseMotor(); // haptic confirmation
delay(1000); // prevent repeat triggers while held
}
// Listen for incoming serial command from computer
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
if (cmd == "MOTOR_ON") {
pulseMotor();
Serial.println("MOTOR_DONE"); // confirm completion to computer
}
}
delay(50); // 50ms loop tick
}
// Motor pulse function — fires motor for 500ms
void pulseMotor() {
digitalWrite(motorPin, HIGH);
delay(500);
digitalWrite(motorPin, LOW);
}
Understanding My Embedded Program
To understand how my embedded system operates, I divided the program into its main functional elements: variable declarations, initialization, continuous monitoring, conditional decision-making, serial communication, and motor control.
Variable Declarations and Pin Assignments
| Program Element | Assigned Value | Purpose |
|---|---|---|
const int buttonPin |
A0 | Identifies the analog input used to monitor the textile pressure sensor. |
const int motorPin |
D2 | Identifies the digital output connected to the MOSFET motor driver. |
int threshold |
20 | Defines the numerical activation condition established during sensor calibration. |
int pressure |
Updated during each loop | Stores the most recent analog sensor reading. |
String cmd |
Received serial text | Stores an incoming command from the connected computer. |
The pin assignments are declared as constant integer values because the physical connections do not change during program execution. The pressure reading and received command are updated as the system operates.
Program Initialization — setup()
The setup() function executes when the embedded program starts. It establishes the initial configuration required before the continuous monitoring portion of the program begins.
| Instruction | Function |
|---|---|
Serial.begin(115200); |
Initializes the serial communication interface with the selected baud-rate setting. |
pinMode(motorPin, OUTPUT); |
Configures the motor control pin as a digital output. |
digitalWrite(motorPin, LOW); |
Establishes the motor's OFF state after program initialization. |
Serial.println("Week 4 ready"); |
Transmits a startup message indicating that the program has initialized. |
Continuous Monitoring — loop()
After initialization, the loop() function continuously repeats the instructions responsible for monitoring the sensor, controlling the motor, and processing incoming communication.
- Obtain the current analog sensor reading using analogRead().
- Transmit the reading through the serial interface.
- Compare the reading with the calibrated activation threshold.
- Execute the pressure-triggered response if the activation condition is satisfied.
- Check whether incoming serial data is available.
- Process a recognized motor activation command when received.
- Wait for the programmed loop delay before repeating the sequence.
This structure allows the microcontroller to monitor its physical input and respond to external commands within the same embedded program.
Analog Input Monitoring and Threshold Detection
The textile pressure sensor produces a variable electrical response rather than the binary state associated with a conventional mechanical switch.
To interpret this response, my program obtains an analog reading from the sensor and stores the resulting numerical value in the pressure variable.
int pressure = analogRead(buttonPin);
Serial.println(pressure);
Printing each reading to the Serial Monitor allowed me to observe the sensor's behavior under different physical conditions and identify a suitable activation threshold.
Threshold-Based Decision Making
int threshold = 20;
I selected a threshold of 20 based on the observed difference between the resting sensor readings and the readings obtained when pressure was applied.
| Sensor Condition | Observed Analog Reading | Program Interpretation |
|---|---|---|
| Sensor at rest | Approximately 100 to 200 | No activation required. |
| Firm pressure applied | Approximately 5 to 15 | Activation condition satisfied. |
| Activation threshold | 20 | Separates the observed pressed and resting conditions. |
The conditional statement below evaluates whether the current sensor reading is less than the selected threshold.
if (pressure < threshold) {
Serial.println("NEXT");
pulseMotor();
delay(1000);
}
When the condition evaluates as true, the program transmits the NEXT event message and calls the motor-control function to provide haptic confirmation. A one-second cooldown delay is then applied before the program continues.
The threshold was selected specifically for this prototype and its observed electrical response. Changes to the sensor materials, construction, electrical connections, or environmental conditions may require additional calibration.
Programming the Local Output Device
The vibration motor functions as the local output device within my embedded system. Its purpose is to provide physical haptic feedback in response to either a detected pressure event or a received serial command.
Rather than repeating the same motor-control instructions in multiple sections of the program, I created a separate function called pulseMotor().
void pulseMotor() {
digitalWrite(motorPin, HIGH);
delay(500);
digitalWrite(motorPin, LOW);
}
| Instruction | Electrical Response | Physical Response |
|---|---|---|
digitalWrite(motorPin, HIGH); |
The digital output activates the MOSFET driver. | The vibration motor begins operating. |
delay(500); |
The output remains in its active state for the programmed interval. | The motor provides approximately half a second of vibration. |
digitalWrite(motorPin, LOW); |
The MOSFET driver is switched off. | The motor stops producing sustained vibration. |
Creating a dedicated function allows the motor-control sequence to be reused in different parts of the embedded program. Both the pressure-triggered event and the incoming serial command call the same function.
This approach also simplifies future modification. For example, changing the delay value within pulseMotor() would change the programmed motor activation duration for both types of interaction.
Implementing Bidirectional Wired Communication
In addition to controlling physical input and output devices, my embedded system communicates with an external computer through a wired USB serial connection.
Communication occurs in two directions. The microcontroller transmits sensor readings and event messages to the computer, while the computer can transmit instructions back to the microcontroller.
Outgoing Communication
| Transmitted Information | Purpose |
|---|---|
Week 4 ready |
Indicates that the embedded program has initialized. |
| Numerical analog readings | Provides sensor telemetry for monitoring and calibration. |
NEXT |
Indicates that the pressure activation condition has been satisfied. |
MOTOR_DONE |
Confirms completion of a motor activation requested through serial communication. |
Incoming Communication
The program also monitors the serial interface for incoming data from the connected computer.
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
if (cmd == "MOTOR_ON") {
pulseMotor();
Serial.println("MOTOR_DONE");
}
}
| Program Instruction | Function |
|---|---|
Serial.available() |
Checks whether incoming serial data is available for processing. |
Serial.readStringUntil('\n') |
Reads incoming text until a newline character is received or the configured timeout is reached. |
cmd.trim() |
Removes leading and trailing whitespace from the received command. |
cmd == "MOTOR_ON" |
Checks whether the received text matches the recognized motor activation command. |
pulseMotor() |
Executes the programmed vibration motor activation sequence. |
Serial.println("MOTOR_DONE") |
Transmits a completion message after the motor-control function finishes. |
Command and Response Protocol
I established a simple text-based command and response convention for communication between the microcontroller and computer.
When the computer sends the MOTOR_ON command, the embedded program identifies the instruction, activates the motor, and returns the MOTOR_DONE message after completing the programmed pulse.
This communication convention provides an early example of how an external device could request a physical action from the wearable system and receive confirmation that the corresponding program operation has completed.
For this assignment, the communication interface is USB serial rather than the wireless Bluetooth Low Energy connection intended for future development.
Program Limitations and Future Improvements
The embedded program developed during this assignment successfully demonstrates the fundamental interaction and communication functions required for my prototype. However, evaluating its current behavior also revealed several opportunities for improvement.
| Current Implementation | Limitation | Potential Improvement |
|---|---|---|
| Motor timing controlled using delay(500). | Normal program execution pauses during the programmed motor activation interval. | Implement non-blocking timing using millis() and a motor state variable. |
| Pressure activation followed by delay(1000). | The delay limits the frequency of activation but does not prevent repeated events when pressure remains applied. | Implement press and release detection so that each intentional press generates a single event. |
| Single activation threshold. | Readings fluctuating around the threshold may cause inconsistent activation behavior. | Use separate activation and release thresholds to introduce hysteresis. |
| Individual analog sensor readings. | Electrical noise and variations in the textile sensor may influence individual readings. | Implement averaging or another suitable digital filtering method. |
| Fixed numerical threshold of 20. | The selected threshold may not remain suitable when the physical sensor construction or electrical configuration changes. | Develop a repeatable sensor calibration procedure. |
| Serial command processing using readStringUntil(). | Program execution can wait for a complete command or serial timeout. | Implement non-blocking serial input processing. |
| One recognized incoming command. | The available command set is limited, and unrecognized instructions do not produce a dedicated error response. | Expand the command protocol to support additional operations and error messages. |
| Numerical telemetry transmitted during each normal loop iteration. | Telemetry temporarily pauses during blocking delays and command processing. | Use independent, non-blocking timing for sensor monitoring, communication, and motor control. |
| USB serial communication. | The current prototype requires a wired connection to the external computer. | Investigate Bluetooth Low Energy communication for the wearable application. |
Understanding Blocking and Non-Blocking Programming
One of the most significant limitations of my current program is its use of blocking delays. When a delay instruction executes, subsequent instructions within the same program flow must wait until that interval has elapsed.
During a pressure-triggered event, the motor-control function introduces a 500-millisecond delay, followed by a 1000-millisecond cooldown delay. Normal sensor monitoring and incoming command processing are temporarily interrupted during this sequence.
In a future iteration, I would investigate the use of millis() to monitor elapsed time without stopping the continuous execution of the main program loop.
This approach would be particularly valuable for my final project, where the embedded system may need to monitor physical input, maintain communication, and control output devices with minimal interruption.
These proposed improvements represent opportunities for future development. The original program documented above remains the version used for the physical testing conducted during this assignment.
Testing and Calibration
After successfully uploading my embedded program to the XIAO RP2040, I began testing the integrated system to evaluate the behavior of the textile pressure sensor, vibration motor, and serial communication interface.
Testing Objectives
- Verify that the microcontroller receives analog readings from the textile pressure sensor.
- Identify the numerical difference between the resting and pressed sensor conditions.
- Establish an appropriate activation threshold.
- Verify that physical interaction generates an outgoing serial message.
- Verify that the vibration motor responds to a detected pressure event.
Sensor Calibration Procedure
- Connect the embedded system to the computer using a USB-C data cable.
- Open the Arduino Serial Monitor at 115200 baud.
- Observe the analog sensor readings without applying pressure.
- Apply firm pressure to the textile sensor and observe the change in readings.
- Compare the numerical ranges associated with the resting and pressed conditions.
- Establish an activation threshold of 20 within the embedded program.
- Evaluate the physical and serial responses when the sensor reading falls below the threshold.
Observed Testing Results
| Test Condition | Observed ADC Reading | Serial Monitor Response | Physical Response | Result |
|---|---|---|---|---|
| Sensor at rest | 100–200 | Numerical sensor readings | Motor remains inactive | Successful |
| Firm pressure applied | 5–15 | Numerical reading followed by NEXT | Vibration motor activates | Successful |
Calibration Results and Interpretation
The resting sensor readings fluctuated between approximately 100 and 200. When firm pressure was applied to the Velostat sensor, the readings decreased to approximately 5 to 15.
Based on these observations, I selected a numerical threshold of 20. This value was above the observed readings associated with firm pressure and below the observed resting range.
When the sensor reading fell below the threshold, the program transmitted the NEXT message through the serial interface and activated the vibration motor using the programmed motor-control function.
These results demonstrated that the microcontroller could interpret a physical input and produce both a physical output and a digital communication response.
The recorded values represent raw analog-to-digital converter readings rather than calibrated measurements of force, pressure, or electrical resistance.
Bidirectional Communication Verification
After verifying the response of the textile pressure sensor and vibration motor, I tested the ability of the embedded system to receive instructions from an external device and respond through both physical output and digital communication.
For this test, I maintained the USB serial connection between the XIAO RP2040 and my computer and continued using the Arduino Serial Monitor at 115200 baud.
Incoming Command Testing Procedure
- Allow the embedded system to remain at rest without applying pressure to the textile sensor.
- Observe the numerical sensor readings in the Serial Monitor.
- Enter the MOTOR_ON command into the Serial Monitor.
- Transmit the command to the XIAO RP2040.
- Observe the physical response of the vibration motor.
- Verify that the MOTOR_DONE confirmation message appears after the programmed motor activation.
Communication Testing Results
| Test Condition | Communication Direction | Observed Serial Response | Observed Physical Response | Result |
|---|---|---|---|---|
| Sensor at rest | Microcontroller to computer | Numerical readings between 100 and 200 | Motor remains inactive | Successful |
| Firm pressure applied to sensor | Microcontroller to computer | NEXT event message | Motor activates | Successful |
| MOTOR_ON command transmitted | Computer to microcontroller | Incoming command processed | Motor activates without physical pressure being applied | Successful |
| Programmed motor pulse completed | Microcontroller to computer | MOTOR_DONE confirmation message | Motor activation ends | Successful |
Observed Communication Behavior
During command testing, the vibration motor activated after I transmitted the MOTOR_ON instruction. Once the programmed motor pulse was complete, the MOTOR_DONE message appeared in the Serial Monitor.
I also observed that the numerical sensor readings temporarily stopped appearing during the motor activation sequence. This behavior is consistent with the blocking delay used within the original motor-control function.
The successful execution of an incoming command and the transmission of a corresponding completion message demonstrated bidirectional wired communication between the embedded system and my computer.
Although this prototype uses USB serial communication, the command and response convention establishes a foundation for the wireless communication functionality intended for my final project.
Final Results and System Demonstration
Completed Embedded System — Hero Shot
The completed prototype integrates a custom-fabricated PCB, a Seeed Studio XIAO RP2040 microcontroller, a textile-based Velostat pressure sensor, a MOSFET-controlled vibration motor, and a USB serial communication interface.
The resulting embedded system demonstrates the integration of digital fabrication, electronic design, textile electronics, embedded programming, and physical computing.
Final System Functionality
| System Function | Demonstrated Capability |
|---|---|
| Local Input | Detection of physical pressure using a textile sensor. |
| Local Output | Activation of a vibration motor through a MOSFET driver. |
| Embedded Processing | Interpretation of analog readings using conditional programming logic. |
| Outgoing Communication | Transmission of sensor readings and interaction events. |
| Incoming Communication | Reception and execution of external motor activation commands. |
| Command Confirmation | Transmission of a completion message following the programmed motor pulse. |
Embedded Programming Video Demonstration
To demonstrate the execution of my embedded program, I recorded my testing process within Arduino IDE. I used the Serial Monitor to observe the data transmitted from the microcontroller and evaluate the behavior of my program during execution.
This testing process allowed me to monitor the system in real time, troubleshoot my code, and evaluate communication between the microcontroller and my computer through USB serial communication.
I also used this recording during Week 2 - Computer-Aided Design to demonstrate video compression using HandBrake. Referencing the same video across both assignments allows me to document my work without duplicating files within my repository.
Connection to My Final Project
At the time of this assignment, my Fab Academy final project concept consisted of a two-part journaling system incorporating a handheld electronic console and a textile-based wearable device.
The handheld console was intended to provide an interactive journaling experience, while the wearable wristband would provide haptic feedback and communicate with the console through a wireless connection.
Week 04 provided an opportunity to prototype several fundamental functions required for the wearable portion of this system before attempting to integrate the complete final project.
Transfer of Weekly Assignment Skills
| Week 04 Implementation | Intended Final Project Application |
|---|---|
| Textile pressure sensor | Flexible user interaction integrated into a wearable textile structure. |
| Vibration motor | Haptic notifications and physical feedback for the user. |
| MOSFET motor driver | Controlled activation of the wearable's vibration motor. |
| NEXT event message | Transmission of user interaction events to another device. |
| MOTOR_ON command | Remote activation of wearable haptic feedback. |
| MOTOR_DONE response | Confirmation that a requested software operation has completed. |
| USB serial communication | Initial development of a command and response convention before wireless implementation. |
| Custom PCB fabrication | Development of compact electronic assemblies appropriate for wearable integration. |
| Arduino C++ programming | Development of programming skills applicable to future embedded system integration. |
Transition from Wired to Wireless Communication
Although the Week 04 prototype communicates through USB serial, the fundamental interaction model can be adapted to other communication interfaces.
My intended next step was to investigate Bluetooth Low Energy communication between the journaling console and the wearable device.
This would require additional development involving wireless communication, device power management, communication protocols, and physical system integration.
Interdisciplinary Development
An important outcome of this assignment was the integration of techniques learned through Fabricademy into my Fab Academy final project development process.
The replacement of a mechanical tactile switch with a flexible textile pressure sensor demonstrated how materials exploration could directly influence electronic design and embedded programming decisions.
This assignment therefore served as both an embedded programming exercise and an early functional development stage for my intended wearable journaling system.
Assignment Reflection
What I Learned About Embedded Programming
Before completing this assignment, I had not considered interaction and communication as distinct functions within an embedded system.
Developing a program that monitored physical input, controlled a vibration motor, and transmitted information through a serial connection helped me understand the relationship between these functions.
I learned that an embedded system can receive information from its physical environment, interpret that information using programmed logic, produce a physical response, and communicate information to another device.
Understanding the Relationship Between Hardware and Software
This assignment also reinforced that successful embedded programming depends on more than writing functional source code.
The program must operate within the electrical and physical limitations of the hardware connected to the microcontroller. Issues involving PCB fabrication, component functionality, electrical continuity, and USB connectivity can prevent an otherwise functional program from operating as intended.
The troubleshooting process helped me develop a more systematic approach to identifying whether an unexpected result originated from the hardware, the software, or the communication interface.
Applying Knowledge Across Disciplines
One of the most rewarding outcomes of this assignment was the opportunity to integrate techniques learned through Fabricademy.
Although the transition from a tactile switch to a textile pressure sensor originated from a hardware challenge, the resulting design was more closely aligned with my intended wearable application.
This experience demonstrated the value of remaining flexible during the development process and considering alternative materials and methods when an initial design does not perform as expected.
What I Would Do Differently
| Development Area | Future Improvement |
|---|---|
| Component Preparation | Verify the functionality and pin assignments of individual components before beginning schematic development. |
| PCB Design | Establish appropriate trace widths and clearances in KiCad before exporting fabrication files. |
| PCB Fabrication | Perform detailed visual inspection and continuity testing before removing the board from the milling substrate when practical. |
| Electronic Assembly | Improve soldering technique and minimize excessive heating of copper pads. |
| Sensor Integration | Develop a more repeatable sensor electrical configuration and calibration procedure. |
| Embedded Programming | Investigate non-blocking timing, press and release detection, and improved serial command processing. |
| Communication | Expand the command and response convention to support future wireless integration. |
Overall Reflection
Despite encountering several challenges during fabrication and assembly, I was able to adapt my original design and develop a functional embedded system.
This assignment strengthened my understanding of microcontroller architecture, technical documentation, embedded programming, electronic circuit integration, and communication protocols.
It also provided an opportunity to combine skills from multiple areas of digital fabrication while establishing a technical foundation for my subsequent Fab Academy assignments and final project development.
Files
| File | Description | Week 04 — Arduino Embedded Programming Source Code | IDE Code - Motor controller for SEEED Xiao RP2040 |