i
  1. Week 1 : Project Management
  2. Week 2 : Computer-aided
  3. Week 3 : Computer Controlled Cutting
  4. Week 4 : Embedded Programming
  5. Week 5 :3D Scanning and Printing
  6. Week 6 : Electronic Design
  7. Week 7 : Computer Controlled Machining
  8. Week 8 : Electronics Production
  9. Week 9 : Input Devices
  10. Week 10 : Output Devices
  11. Week 11 : Networking and Communication
  12. Week 12 : Mechanical Design and Machine Design
  13. Week 13 : Midterm Review
  14. Week 14 : Molding and Casting
  15. Week 15 : Interface and Application Programming
  16. Week 16 : System Integeration
  17. Week 17 : Wildcard Week
  18. Week 18 : Applications and Implications, Project Development
  19. Week 19 : Invention, Intellectual property and Income
  20. Week 20 : FInal Project Requirements

Week 15 : Interface and Application Programming

Objectives of the Week

  • Linked to the group assignment page.
  • Documented your process.
  • Explained the IJI that you made and how you did it.
  • Explained how your application communicates with your embedded microcontroller board.
  • Explained any problems you encountered and how you fixed them.
  • Included original source code (or a screenshot of the app code if thars not possible).
  • Included a 'hero shot' of your application running & communicating with your board.

  • Group Assignment Contribution

    For More about Group Assignment



    Introduction to Graphical User Interfaces (GUI)

    A GUI (Graphical User Interface) is a program that displays information and interactive elements like buttons, shapes, or images to the user. Its main goal is to create a visual environment to interact with hardware or software applications in a more intuitive way.

    Download the software

    Download Arduino IDE

    Download Processing

    Using Arduino (Seeed XIAO) for Input

    Hardware and Setup

    We used a custom board based on the Seeed XIAO microcontroller. The joystick is connected to analog pins A1 and A2 for X and Y axes, and a digital pin for the switch.

    Arduino Code Explanation

        int X_Pos = 0;
        int Y_Pos = 0;
        int b;
    
        void setup(){
            Serial.begin(9600); 
            pinMode(D2, INPUT_PULLUP);
        }
    
        void loop(){
            X_Pos = analogRead(A1);
            Y_Pos = analogRead(A2);
    
            Serial.print(X_Pos, DEC);
            Serial.print(",");
            Serial.print(Y_Pos, DEC);
            Serial.print(",");
            Serial.print(!b);
            Serial.print("\n");
            delay(10);
        }
            

    This code reads analog values from the joystick and prints them in decimal format, separated by commas. The Serial.print("\n") ensures each complete reading is sent on a new line, which helps during serial communication with Processing.

    Working with Processing

    What is Processing?

    Processing is a flexible software sketchbook and language designed for visual arts and creative coding. It’s especially useful for creating graphical representations and can interact with hardware like Arduino via serial communication.

    Setup and Serial Communication

            import processing.serial.*;
            Serial port;
    
            int x; 
            int y; 
            int Switch; 
            PFont f; 
            String portName;
            String value;
    
            void setup(){
                size(512, 512);
                port = new Serial(this, Serial.list()[0], 9600);
                port.bufferUntil('\n'); 
                f = createFont("Arial", 16, true);
                textFont(f, 16);
            }
            

    The size() function sets up the canvas. Serial.list()[0] selects the connected serial port (usually the first one). port.bufferUntil('\n') tells Processing to read data until a newline, aligning with how data is sent from Arduino.

    UI Creation Using Processing for Joystick Input Visualization

    Objective

    To visualize joystick movements (X, Y axes) and button press (switch) data from the Seeed XIAO in real-time using a graphical display built in Processing software.

    Key Concepts Used in Processing

    • Serial Communication – To receive real-time joystick data from Arduino.
    • Real-time Drawing – To dynamically update visuals like position and size of a circle.
    • Conditional Rendering – To change circle size based on button press.
    • Text Display – To show analog X and Y readings numerically.

    UI Building Steps (In Your Processing Code)

    1. Canvas Initialization

                size(512, 512);
                

    Sets the window size of the GUI to 512x512 pixels. This is where all the shapes and text are drawn.

    2. Serial Port Setup

                port = new Serial(this, Serial.list()[0], 9600);
                port.bufferUntil('\n');
                

    Establishes serial connection to the Arduino. bufferUntil('\n') waits until Arduino sends a complete line of data, ensuring clean parsing.

    3. Font Setup for Display

                f = createFont("Arial", 16, true);
                textFont(f, 16);
                

    Sets a readable font to display joystick values (Analog X and Y) on the canvas.

    4. Real-Time Drawing Logic

                void draw() {
                    clear(); // Clears previous frame
                    fill(255); // White fill color for ellipse
    
                    if (Switch == 1){
                        ellipse(x/2, y/2, 100, 100); // Bigger circle when button is pressed
                    } else {
                        ellipse(x/2, y/2, 25, 25);   // Smaller circle when not pressed
                    }
    
                    text("AnalogX=" + (1023 - x) + " AnalogY=" + (1023 - y), 10, 20);
                }
                

    Dynamically draws a circle based on joystick input. Size of the circle changes depending on the joystick's button state. Text output displays real-time analog values.

    5. Serial Data Parsing

                void serialEvent(Serial port) {
                    value = port.readStringUntil('\n');
                    if (value != null) {
                        value = trim(value);
                        int[] values = int(splitTokens(value, ","));
                        x = values[0];
                        y = values[1];
                        Switch = values[2];
                    }
                }
                

    Parses the string data received from Arduino into integer values for:

    • x → Analog X position
    • y → Analog Y position
    • Switch → Button state (1 = pressed, 0 = not pressed)

    What my UI Looks Like

    A white circle moves around the canvas based on the joystick direction. Pressing the joystick button enlarges the circle. Numerical values for analog positions are shown in the top-left corner.

    Drawing and Data Handling

            void draw(){
            fill(0);
            clear();
            fill(255);
    
            if (Switch == 1){
                ellipse(x/2, y/2, 100, 100);
            } else {
                ellipse(x/2, y/2, 25, 25);
            }
    
            text("AnalogX=" + (1023 - x) + " AnalogY=" + (1023 - y), 10, 20);
            }
            

    The circle's size changes based on whether the joystick button is pressed. The coordinates of the ellipse follow the joystick’s X and Y movements. The text() function displays the analog values.

    Serial Data Parsing

            void serialEvent(Serial port) {
            value = port.readStringUntil('\n');
            
            if (value != null) {
                value = trim(value);
                int[] values = int(splitTokens(value, ","));
                
                x = values[0];
                y = values[1];
                Switch = values[2];
            }
            }
            

    This function reads incoming serial data, trims any whitespace, splits it using commas, and stores the joystick values in respective variables. This keeps the GUI updated with live joystick input.

    Conclusion

    This offers a simple yet powerful introduction to interfacing embedded hardware with visual interfaces. By combining Seeed XIAO with Processing, beginners can learn about real-time data communication, sensor integration, and graphical interaction—all essential skills in embedded systems and human-computer interaction.

    Hero Shot

    Finally Leaving my files here

    Arduino Code

    Processsing Code