Skip to content

4. Embedded programming

The objective for this week was to read the microcontroller’s datasheet and begin programming the Arduino board to perform a specific task. Additionally, at the teamwork level, the group explored the various microcontroller board options available in the FabLab.
Finally, two software programs were utilized:
1-Arduino IDE.
2-Thonny.

Microcontroller board

What are microcontroller board ?
images.. A microcontroller is a compact integrated circuit that combines a processor, memory, and input/output peripherals on a single chip. It is designed to govern specific operations in embedded systems, providing a self-contained and efficient solution for executing dedicated tasks.

Microcontroller Group Assignment done by Faisal Fathi

Arduino IDE

Arduino is an open-source electronics platform that simplifies the process of interacting with hardware. These boards can receive various inputs, such as sensor data or button presses, and use that information to control outputs like motors, LEDs, or online publishing. The hardware and software are designed to be accessible, making it easy for users to create interactive projects and prototypes.

To use Arduino IDE follow the steps 1-Download the application from the Arduino IDE website
alt text 2-After downloading and installing it on the device, open the Arduino IDE.
alt text 3-When opened, the following page will be displayed. alt text 4-When you connect the device to the computer, a picture will show the microcontroller board that should be used to establish the connection.
alt text 5-Now we can initiate a simple programming process by using the code from the program. Click on “File” as shown and follow the options selected in the image.
alt text 6-I will use the following codes to program it to turn the LED on and off for a specific period(sec).
alt text 7-Before running the code, I will modify the settings in the file using the option to display the output in the Arduino IDE.
alt text 8-Click on the upload.
alt text 9-Now we will observe the LED’s behavior based on the chosen on and off times.

Thonny

1-Download the application from the Thonny website

2-After downloading and installing it on the device, open the Thonny.

3-When opened, the following page will be displayed.

4-Before beginning any programming process, we need to connect the microcontroller board Thonny.
alt text

5-Press the tools, then follow the instructions in the image to connect the microcontroller board to Thonny. alt text

6- We will use the same codes (Arduino IDE), but in a different language. alt text 7-Click on the Run. alt text

8-Now we will observe the LED’s behavior based on the chosen on and off times.
LED Test other test

Practice in Arduino IDE & Thonny

In this section, we will feature the questions directed to us by ms.Duaa at various difficulty levels, along with their respective solutions and the modifications made to the microcontroller component.
Use the three backticks to separate code.

Hard mode:⁣ you select the duration of the light is on and off while the program is running by entering it in the serial monitor. Write a code that takes the data from the serial monitor and delays by that amount of time.

// the setup function runs once when you press reset or power the board
const int ledPin = 13;

// Variables to hold the duration times
unsigned long onDuration = 1000;  // Default on duration in milliseconds
unsigned long offDuration = 1000; // Default off duration in milliseconds

void setup() {
  // Initialize the LED pin as an output
  pinMode(ledPin, OUTPUT);

  // Initialize serial communication at 9600 bits per second
  Serial.begin(9600);

  // Print instructions to the serial monitor
  Serial.println("Enter the duration for LED ON and OFF in milliseconds (e.g., 1000, 2000):");
}
void loop() {
  // Check if data is available in the serial buffer
  if (Serial.available() > 0) {
    // Read the incoming string until a newline character
    String input = Serial.readStringUntil('\n');

    // Parse the input values (assuming input format is "onDuration,offDuration")
    int commaIndex = input.indexOf(',');
    if (commaIndex > 0) {
      String onDurationString = input.substring(0, commaIndex);
      String offDurationString = input.substring(commaIndex + 1);

      // Convert strings to unsigned long
      onDuration = onDurationString.toInt();
      offDuration = offDurationString.toInt();

      // Print the updated durations to the serial monitor
      Serial.print("Updated durations - ON: ");
      Serial.print(onDuration);
      Serial.print(" ms, OFF: ");
      Serial.println(offDuration);
    } else {
      Serial.println("Invalid input. Please enter durations in the format: onDuration,offDuration");
    }
  }

Last update: October 19, 2024