Interface and Application Programming

Group Assignment

Group Assignment – Interface Tools Comparison

Fab Lab Peru icon

Exploring serial, graphical, and wireless communication with the XIAO ESP32-C3.

Overview

Summary of the Week

This week focused on Interface and Application Programming. The group explored multiple tools to develop user interfaces and establish communication between software applications and a microcontroller system.

Different platforms were tested to understand how they interact with embedded systems, including serial communication, graphical interfaces, and wireless control.

Objective

The objective was to compare different interface tools and analyze how they communicate with a microcontroller, identifying their workflows, use cases, and communication protocols.

Group Work

In this group assignment, we explored multiple interface development tools and evaluated their functionality in relation to embedded systems. Each tool was analyzed based on how it communicates with the XIAO ESP32-C3 and how it can be used to interact with input/output devices.

Quick Data

  • Topic: Interface and Application Programming
  • Board: XIAO ESP32-C3
  • Tools: PuTTY, Processing, RemoteXY, MIT App Inventor
  • Protocols: Serial, WiFi, Bluetooth
  • Students:
  • Carmen Elena Gutiérrez Apolinario, David Ávila Pimentel, Esteban M. Valladares, Jianfranco Bazán J., Mario Chong, Rocio Maravi, Grace Schwan, Cindy Marilyn Crispin, Jennifer Wong

Tasks and Deliverables

  • Compare as many tool options as possible
  • Describe workflows and use cases
  • Analyze communication methods
  • Document the group work

Goal

The goal of this assignment was to explore interface programming tools and understand how they enable communication between users and embedded systems.

Tool Comparison Matrix

We evaluated each development tool based on key parameters including communication type, target device protocols, complexity, and specific use cases.

Tool Type Communication Use Case Workflow
PuTTY CLI Serial Monitoring / debugging Direct serial connection
Processing GUI Serial Interactive control Interface → Serial commands
RemoteXY Mobile UI WiFi IoT control App → WiFi → Board
MIT App Inventor Mobile App Bluetooth Wireless control App → Bluetooth → Board

Equipment Used

Tool / Device Purpose
XIAO ESP32-C3 Microcontroller
HC-SR04 Input device (sensor)
LED Output device
PuTTY Serial communication
Processing GUI interface
RemoteXY WiFi interface
MIT App Inventor Bluetooth app

Procedure 1 – Serial Interface (PuTTY)

Interface-Based Control Test – HC-SR04 with Putty

This section documents the communication between the XIAO ESP32-C3, HC-SR04 and serial with PuTTY software.

Objective

The objective interact between microcontroller, HC-SR04 sensor and an external software.

Software Installation – PuTTY

PuTTY is a free implementation of SSH and Telnet for Windows platforms (Download Site).

Step 1: Download PuTTY

Open a web browser to visit the official PuTTY download site.

PuTTY download page
Figure 1.1: Official PuTTY download page.
Step 2: Choose Features

The installer asks you which PuTTY features to install. Standard features are recommended.

Select features
Figure 1.2: Selecting PuTTY installer options.
Step 3: Desktop Shortcut

It is convenient to enable a shortcut on your desktop for quick access.

Desktop Shortcut option
Figure 1.3: Enable desktop shortcut option.
Step 4: Installation Progress

Wait for the installer to finish copying files to the system.

Installation progress
Figure 1.4: PuTTY installation wizard complete.
Step 5: Starting PuTTY

Double-click the PuTTY icon to start the PuTTY client and begin configuration.

Starting PuTTY
Figure 1.5: Initial PuTTY SSH & Serial client interface.

Initial Interface Exploration & Configuration

Then, you can configure the category and the specific options to set up the serial link.

Category Selection

Navigate through the sidebar categories to explore configuration options.

PuTTY Category
Figure 1.6: Categorized settings menu in PuTTY.
Connection - Serial

We selected Connection → Serial and configured the specific port and baud rate (115200).

Connection Serial
Figure 1.7: Configuring serial connection parameters.

Arduino Code & Validation

The microcontroller reads the distance values from the HC-SR04 ultrasonic sensor and prints them over Serial.

Arduino Code for HC-SR04 Sensor
#define TRIG_PIN D2
#define ECHO_PIN D3

void setup() {
    Serial.begin(115200);
    pinMode(TRIG_PIN, OUTPUT);
    pinMode(ECHO_PIN, INPUT);
}

long readDistance() {
    digitalWrite(TRIG_PIN, LOW);
    delayMicroseconds(2);
    digitalWrite(TRIG_PIN, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG_PIN, LOW);
    
    long duration = pulseIn(ECHO_PIN, HIGH);
    long distance = duration * 0.034 / 2;
    return distance;
}

void loop() {
    long distCM = readDistance();
    long distIN = distCM / 2.54;
    
    Serial.print("Distance : ");
    Serial.print(distCM);
    Serial.print(" cm  /  ");
    Serial.print(distIN);
    Serial.println(" in");
    delay(500);
}
Arduino IDE Serial Monitor

Confirming correct sensor operation using Arduino's built-in monitor.

Arduino Serial Monitor
Figure 1.8: Verifying serial outputs on Arduino IDE.
PuTTY Serial Port Terminal

Establishing the connection via PuTTY client on the mapped COM Port.

PuTTY Serial Connection
Figure 1.9: Serial terminal running in PuTTY.
Simultaneous Validation

This side-by-side view demonstrates both screens displaying real-time distance measurements.

Simultaneous screens
Figure 1.10: Double validation of HC-SR04 readings in real-time.

Procedure 2 – Graphical Interface (Processing)

Interface-Based Control Test – LED Actuation via Processing

This section documents the validation of LED control using a graphical interface developed in Processing, communicating with the XIAO ESP32-C3 via serial connection.

Objective

The objective of this test was to establish a complete workflow where a user interface sends commands to a microcontroller, enabling real-time control of an output device (LED) integrated into the custom board.

Software Installation – Processing

Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts (Download Page).

Step 1: Download zip

Select your operating system and download the Processing zip file.

Processing download
Figure 2.1: Selecting download platform.
Step 2: Extraction

Extract the contents of the downloaded archive into a system folder.

Extract Processing
Figure 2.2: Extracting files from the archive.
Step 3: Application Run

Double-click the processing executable file to launch the editor.

Launch Processing
Figure 2.3: Processing startup and initial workspace.

Initial Interface Exploration (Processing)

Before establishing communication with the microcontroller, an initial exploration of Processing was carried out to understand its rendering pipeline (setup() and draw()) and interaction capabilities.

Sketch 1: Static Shape

A simple static ellipse rendered in the center of a black background.

Processing Code
void setup() {
  size(400, 400);
}
void draw() {
  background(0);
  ellipse(200, 200, 100, 100);
}
Static shape rendering
Figure 2.4: Rendered static ellipse interface.
Sketch 2: Interactive Mouse Version

An interactive sketch where the shape follows the mouse coordinates and changes fill color when clicked.

Processing Code
void setup() {
  size(400, 400);
}
void draw() {
  background(0);
  if (mousePressed) {
    fill(0, 255, 0);
  } else {
    fill(255);
  }
  ellipse(mouseX, mouseY, 80, 80);
}
Interactive shape rendering
Figure 2.5: Ellipse dynamic tracking of cursor.

Hardware Configuration & Script Execution

The LED used in this test is integrated into our custom PCB, connected to pin D6.

Step-by-Step Procedure
  1. Step 1 – Upload Arduino Code: The microcontroller was programmed to listen for commands ("ON", "OFF", "BLINK") over serial and change the D6 pin accordingly.
    Arduino LED Control Code
    #define LED_PIN D6
    bool blinkMode = false;
    bool ledState = false;
    unsigned long lastBlinkTime = 0;
    
    void setup() {
      Serial.begin(115200);
      Serial.setTimeout(20);
      pinMode(LED_PIN, OUTPUT);
      digitalWrite(LED_PIN, LOW); // apagado
    }
    
    void loop() {
      if (Serial.available()) {
        String command = Serial.readStringUntil('\n');
        command.trim();
        
        if (command == "ON") {
          blinkMode = false;
          digitalWrite(LED_PIN, HIGH);
          Serial.println("ON");
        }
        else if (command == "OFF") {
          blinkMode = false;
          digitalWrite(LED_PIN, LOW);
          Serial.println("OFF");
        }
        else if (command == "BLINK") {
          blinkMode = true;
          Serial.println("BLINK");
        }
      }
      
      if (blinkMode) {
        if (millis() - lastBlinkTime > 300) {
          lastBlinkTime = millis();
          ledState = !ledState;
          digitalWrite(LED_PIN, ledState ? HIGH : LOW);
        }
      }
    }
  2. Step 2 – Verify Serial Communication: Run the serial monitor and type "ON", "OFF" or "BLINK" to ensure hardware reactions.
    Verify serial communication
    Figure 2.6: Verifying led reactions via serial text lines.
  3. Step 3 – Close Serial Monitor: Important! You must close the Serial Monitor before launching the Processing application, otherwise, the serial port will be locked and busy.
  4. Step 4 – Run Processing Interface: Open and run the custom Processing script. This script opens a COM port at 115200 and renders interactive graphical buttons ("ON", "OFF", "BLINK") to control the board.
    Processing Graphical Interface Code
    import processing.serial.*;
    
    Serial myPort;
    String status = "OFF";
    
    void setup() {
      size(430, 500);
      smooth();
      textAlign(CENTER, CENTER);
      println(Serial.list());
      myPort = new Serial(this, "COM3", 115200);
      myPort.clear();
    }
    
    void draw() {
      background(245);
      fill(0);
      textSize(28);
      text("LED Control", width/2, 60);
      
      fill(120);
      textSize(14);
      text("ON / OFF / BLINK", width/2, 90);
      
      // STATUS BOX
      fill(255);
      rect(50, 120, 330, 100, 20);
      
      fill(0);
      textSize(18);
      text("Status", width/2, 150);
      
      fill(status.equals("ON") ? color(0,200,100) :
           status.equals("BLINK") ? color(0,120,255) :
           color(150));
      textSize(28);
      text(status, width/2, 190);
      
      // BUTTONS
      drawButton(60, 270, 90, 70, "ON");
      drawButton(170, 270, 90, 70, "OFF");
      drawButton(280, 270, 90, 70, "BLINK");
    }
    
    void drawButton(float x, float y, float w, float h, String label) {
      boolean hover = mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h;
      noStroke();
      fill(hover ? color(80) : color(50));
      rect(x, y, w, h, 15);
      
      fill(255);
      textSize(16);
      text(label, x + w/2, y + h/2);
    }
    
    void mousePressed() {
      if (mouseY > 270 && mouseY < 340) {
        if (mouseX > 60 && mouseX < 150) {
          send("ON");
          status = "ON";
        }
        if (mouseX > 170 && mouseX < 260) {
          send("OFF");
          status = "OFF";
        }
        if (mouseX > 280 && mouseX < 370) {
          send("BLINK");
          status = "BLINK";
        }
      }
    }
    
    void send(String cmd) {
      myPort.write(cmd + "\n");
      println("Sent: " + cmd);
    }
Graphical Interface Operation

The screenshot shows the running Processing interface transmitting digital commands to COM3.

Processing Interface Executing
Figure 2.7: Execution and click trigger confirmation in Processing.
Results & Troubleshooting
  • Results: The custom board LED responded perfectly in real-time to clicking the interactive graphic buttons. Non-blocking timing on Arduino (millis) kept the board responsive.
  • Issues Encountered:
    • Serial Port Conflict: Resolved by ensuring Arduino Serial Monitor was fully closed before running Processing.
    • Incorrect LED pin: Onboard LED couldn't be toggled, so swapped the script configuration to pin D6.
Conclusion: This test successfully demonstrated the integration of a graphical interface with an embedded system through serial communication. The workflow enables intuitive and responsive control of an output device, validating both hardware configuration and software interaction.

Procedure 3 – WiFi Interface (RemoteXY)

Tool Selection and Configuration

We decided to create a mobile interface using the RemoteXY platform to control our XIAO ESP32-C3 board wirelessly. This platform allows developers to build graphical panels visually and exports the matching Arduino source code automatically.

Step 1: Access Web Editor

Enter the cloud editor workspace at remotexy.com/en/editor/.

RemoteXY cloud environment
Figure 3.1: Launching the RemoteXY development editor.
Step 1 (Alt): Alternate Workspace view

Another view of the project load page inside RemoteXY interface.

Alternative loading screen
Figure 3.2: Loading environment properties.
Step 2: Project Settings Configuration

In this stage, the critical communication parameters between the mobile interface and the board hardware are defined in the properties sidebar:

  • Connection Type: Wi-Fi Access Point (allows the board to broadcast its own network)
  • Motherboard: XIAO ESP32-C3
  • Communication Module: Built-in ESP32 Wi-Fi module
  • Baud Rate: 115200 (stable serial diagnostic transfer speed)
  • SSID Name: IoT_UP
  • Password: Configured securely
RemoteXY Properties Panel
Figure 3.3: Configuring project wireless properties.

Interface Design & Variable Configuration

🔹 Step 1: Selecting Graphics Components

From the left pane ("Controls"), we dragged several controls to the virtual mobile screen area:

  • Switch: Toggle ON/OFF state
  • Button: Momentary toggle impulse
  • Gauge: Analog progress dashboard
  • Text Label: System labeling identification
Dragging UI controls
Figure 3.4: Dragging design elements.
🔹 Step 2 & 3: UI Layout & Variables

Organize controls based on basic UX/UI principles (visual hierarchy, landscape layout, ease of use). Then, we linked each layout component to internal variables:

  • Switch component → linked to variable switch_1
  • Button component → linked to variable button_1
Linking components to variables
Figure 3.5: Linking visual layouts to code variables.
🔹 Step 4: Source Code Generation

By clicking on "Get Source Code", RemoteXY automatically compiles network structures, control arrays, sync arrays, and headers.

Code generation
Figure 3.6: Generation tab.
Code array
Figure 3.7: Export structures.
Export files
Figure 3.8: Complete source code ready for import.

Procedure 4 – Mobile Application (MIT App Inventor)

MIT App Inventor custom Bluetooth Controller

MIT App Inventor es una plataforma gratuita que permite crear aplicaciones móviles de forma visual, sin necesidad de programar con código tradicional. Funciona mediante bloques tipo "rompecabezas", diseñando la interfaz y el comportamiento de manera sencilla. Es ideal para controlar un ESP32 mediante Bluetooth Serial.

Starting Designer Mode

Launch the App Inventor interface and set up the device view.

App Inventor Designer
Figure 4.1: Initial designer space of MIT App Inventor.

Mobile UI Design Steps

Step 1: Create New Project

We created a new project and configured advanced application properties like orientation.

New Project Config
Figure 4.2: Initial properties.
Step 2: Add Containers

Drag a HorizontalArrangement from the Layout palette onto the mobile interface.

Horizontal arrangement
Figure 4.3: Incorporating horizontal layout blocks.
Step 3: Layout Properties

Modify layout widths, padding, backgrounds, and align dimensions under the Properties bar.

Appearance configuration
Figure 4.4: Customizing container styles.
Step 4: Incorporating Buttons

We added two functional Button controls into the container layout to manage LED power states.

Two buttons
Figure 4.5: Adding buttons into layout container.
Step 5: Incorporating ListPicker

We added a ListPicker block directly to let users select paired Bluetooth devices.

ListPicker block
Figure 4.6: Adding Bluetooth list selector.
Step 6: Style Refinements

We refined dimensions, backgrounds, texts, and margin values for all visual components.

Final UI designs
Figure 4.7: Polishing visual components styles.
Step 7: Media Image Embedding

We loaded a custom image inside the interface to improve graphical appearance and design.

App interface with image
Figure 4.8: Complete visual mockup layout with active image element.

Blocks Coding Logic

We switched the App Inventor mode to **Blocks** to configure logical connections, Bluetooth arrays, and click actions:

Bluetooth Pairing List

Configure ListPicker1.BeforePicking to fetch paired devices using BluetoothClient1.AddressesAndNames.

BeforePicking blocks
Figure 4.9: Logic blocks for loading paired connections.
Connection Selection Action

Configure ListPicker1.AfterPicking to call BluetoothClient1.Connect based on selection.

AfterPicking blocks
Figure 4.10: Bluetooth connection initialization blocks.
Connection Status Feedback

Check if connection was successful to change a label text dynamically to "Connected" or "Not Connected".

Status text blocks
Figure 4.11: Dynamic feedback and label configuration.
Toggling Commands

Configure click events for ON and OFF buttons to call BluetoothClient1.SendText transmitting "1" or "0".

Button toggles
Figure 4.12: Transmitting digital values '1' and '0'.

App Compiling, Installation & Hardware Verification

Once logic was ready, we compiled the app and programmed the board with Bluetooth receiver configurations:

1. Compile APK QR

Click on Build → Android App (apk) to generate a package QR code.

QR Compilation
Figure 4.13: QR build option.
2. Waiting Server Build

The system builds the source and packs compiled classes in progress.

Building progress
Figure 4.14: Build progress window.
3. Installing App

The compiled APK was downloaded and successfully installed (Android 11).

App installed
Figure 4.15: Installed app dashboard view.
Microcontroller Programming (Bluetooth Serial)

Open Arduino IDE, connect the ESP32 board, select the ESP32 Dev Module, and program the controller to act as a Bluetooth host receiving serial char commands:

Arduino Bluetooth Serial Code
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;
const int ledPin = 2; // LED Pin representation

void setup() {
  SerialBT.begin("ESP32-Bluetooth"); // Bluetooth broadcast name
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (SerialBT.available()) {
    char c = SerialBT.read();
    if(c == '1') {
      digitalWrite(ledPin, HIGH); // LED ON
    } else if (c == '0') {
      digitalWrite(ledPin, LOW);  // LED OFF
    }
  }
}
Arduino IDE Upload
Figure 4.16: Confirming successful code upload.
A. Pair Board in Settings

Turn on mobile Bluetooth, find the broadcast net "ESP32-Bluetooth" and link.

Bluetooth pairing
Figure 4.17: Setting connections in smartphone.
B. List Selector

Open the custom controller app and tap on the device list selector.

Select paired device
Figure 4.18: Select mapped bluetooth device.
C. Toggling Toggles

Select the device to verify link success and click button toggles to trigger LED.

Toggling led states
Figure 4.19: Operational wireless mobile control.

Key Lesson & Conclusions

Key Lessons

Each interface development tool evaluates distinct aspects of microcontroller interaction:

  • PuTTY: Excellent direct diagnostic terminal for debugging serial outputs.
  • Processing: Robust and visually rich environment to develop customizable desktop graphical controls.
  • RemoteXY: Fast drag-and-drop generator ideal for prototyping simple wireless interfaces without manual network coding.
  • MIT App Inventor: Highly flexible block programming workspace to build native mobile software controller apps.

Conclusion

This group assignment allowed us to explore multiple interface tools and understand how different communication protocols interact with embedded systems.

We successfully compared serial, graphical, WiFi, and Bluetooth interfaces, demonstrating how each tool enables interaction between the user and the microcontroller.

Overall Testing and Validation Diagram

This diagram summarizes our overall exploration of different physical communication and software layers.

Laboratory complete structure map
Figure 5.1: Overall systematic structure of weekly interface lab work.