Skip to content

4. Embedded programming

This week I worked on programing a microcontroller. I worked on two different coding languages which are Arduino IDE and Python.

Research

Since I do not have any previous background in programming, I did research to understand programming better and get acquainted with its basic terms.

What is programming?

“Programming refers to a technological process for telling a computer which tasks to perform in order to solve problems. You can think of programming as a collaboration between humans and computers, in which humans create instructions for a computer to follow (code) in a language computers can understand.”

What is code?

“In computer programming, computer code refers to the set of instructions, or a system of rules, written in a particular programming language.”

What is the difference between code and markup language?

“The markup language is used to present information whereas programming language is used to give instructions to a computer to perform a particular task.”

What is a programming evironment?

“A programming environment combines hardware and software that allows a developer to build applications.”

Group Assignment

In the first session we were taught about what is a microcontroller. Then, we were asked to search for different types of microcontroller boards and compare between them.

A microcontroller is a computer system on a chip that does a job. It contains an integrated processor, memory, and programmable input/output peripherals, which are used to interact with things connected to the chip. There are many types of microcontrollers. Each has different features and is used for a different purpose.

Click here to view the embedded programming group assignmnet.

Individual Assignment

For the individual assignemnt, we were required to program a microcontroller chip. To do so, there are many languages that the programmer can use e.g. Python, C++.

The microcontroller I used is Arduino MKR Wifi 1010.

Arduino MKR Wifi 1010

“The Arduino MKR WiFi 1010 is the easiest point of entry to basic IoT and pico-network application design. Whether you are looking at building a sensor network connected to your office or home router, or if you want to create a Bluetooth Low Energy device sending data to a cellphone, the MKR WiFi 1010 is your one-stop-solution for many of the basic IoT application scenarios.”

Click here to read more.

Programming Platforms

In this week, we worked with two main programs: Arduino IDE and Mu Editor. We had a set of challenges to perform using these two programs.

Challenge 1: Blink Coding

The first challenge was the blink challenge, which entailed working on the blink effect in the microcontroller, to allow it to randomly blink in random intervals between 1 to 5 seconds. For this challenge, I used the built-in example in the arduino program. I then fixed the code to make the blinks random instead of fixed. The code can be seen below.

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(random(1000, 5000));                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(random(1000, 5000));
                     // wait for a second
}

You can see the result in the following video:

Challenge 2: Morse Code Blink

The second challenge was creating a morse code using the blink effect too, with each letter being represented by a specific number of blinks in a specific time for each.

To perform this challege, I worked on the Mu Editor. Before starting, I got an example from this link. I then rearranged the code to spell “Zam” in morse code, based on the table above. The final code can be seen below.

import time
import board
import digitalio

led = digitalio.DigitalInOut(board.D6)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(2)
    led.value = False
    time.sleep(0.5)
    led.value = True
    time.sleep(2)
    led.value = False
    time.sleep(0.5)
    led.value = True
    time.sleep(1)
    led.value = False
    time.sleep(0.5)
    led.value = True
    time.sleep(1)
    led.value = False
    time.sleep(3)
    led.value = True
    time.sleep(1)
    led.value = False
    time.sleep(0.5)
    led.value = True
    time.sleep(2)
    led.value = False
    time.sleep(3)
    led.value = True
    time.sleep(2)
    led.value = False
    time.sleep(0.5)
    time.sleep(2)
    led.value = False
    time.sleep(5)

You can see the result in the following video:

Challenge 3: User Input

In the third challenge, we had to to select the duration of the light being on and off while the program is running by entering it in the serial monitor. To perform this challenge, I needed to write a code that takes the data from the serial monitor and delays by that amount of time.

First, I wrote the basic blink code. Then, I added additional code that takes input from the user.

V = int(input("Enter Number"))

I executed the code and enter 7 to be the input. You can see the result in the following video:

NOTE: I used Mu Editor to perform the challenge

The final full code can be seen bellow.

import time
import board
import digitalio

led = digitalio.DigitalInOut(board.D6)
led.direction = digitalio.Direction.OUTPUT

V = int(input("Enter Number"))

while True:
    led.value = True
    time.sleep(V)
    led.value = False
    time.sleep(V) 

Last update: July 3, 2023