6. Embedded Programming

This week I worked on programming the PCB we made in previous weeks.

THIS WEEK GROUP ASSIGNMENT(click the title)

Using Arduino IDE with XIAO Microcontroller

  1. Install Arduino IDE: Begin by downloading and installing the Arduino IDE from the official Arduino website (https://www.arduino.cc/en/software). Choose the appropriate version for your operating system.
  2. Connect XIAO to Computer: Use a USB cable to connect your XIAO microcontroller board to your computer. Ensure the board is recognized and drivers are installed if prompted.
  3. Open Arduino IDE: Launch the Arduino IDE after installation. You should see a blank sketch (program) window open.
  4. Select Board:
    • Go to Tools > Board and select "Seeeduino XIAO" from the list of available boards. If "Seeeduino XIAO" is not listed, you may need to add the XIAO board to the Arduino IDE by following the instructions provided by Seeed Studio.
  5. Select Port:
    • Next, go to Tools > Port and select the COM port to which your XIAO board is connected. The exact port number may vary depending on your computer and operating system.
  6. Write Your Sketch:
    • Begin writing your Arduino sketch in the IDE. This can include setting up variables, defining functions, and implementing control logic.
    • For example, you can create a simple sketch to blink an LED connected to a pin on the XIAO board

    • Code Uploaded to XIAO

      Code in arduino

      
      		#include 
      
      			Servo servoMotor;  // Create a Servo object to control the servo motor
      			
      			void setup() {
      			  servoMotor.attach(9);  // Attach the servo motor to pin 9
      			}
      			
      			void loop() {
      			  moveServo(0);  // Move the servo to 0 degrees
      			  delay(2000);   // Wait for 2 seconds
      			  
      			  moveServo(180);  // Move the servo to 180 degrees
      			  delay(2000);     // Wait for 2 seconds
      			}
      			
      			void moveServo(int angle) {
      			  int duty = map(angle, 0, 180, 0, 180);  // Map the angle (0-180) to servo's duty cycle (0-180 degrees)
      			  servoMotor.write(duty);  // Set the servo position based on the calculated duty cycle
      			}
      	

      Explanation

      • The code begins by including the Servo.h library, essential for controlling servo motors with Arduino.
      • A Servo object named servoMotor is instantiated to manage the servo motor's operation.
      • In the setup() function, the servoMotor is initialized and attached to pin 9 of the XIAO board, preparing it for servo motor control.
      • Within the loop() function, the servo motor is sequentially moved:
        • moveServo(0); sets the servo motor to 0 degrees.
        • A delay(2000); follows, pausing the program for 2 seconds to allow the servo to reach its position.
        • moveServo(180); adjusts the servo to 180 degrees.
        • Another delay(2000); pause ensures a smooth transition and operational stability.
      • The moveServo(int angle) function calculates and assigns the appropriate duty cycle to the servo motor based on the desired angle parameter, ensuring accurate positioning.

      Having it connected the servo ground to top right pin in the xiao, ground to the own below and signal to the D5 port, it started moving.

      result