Skip to content

5. Embedded programming

This week’s tasks:

a) Learn the basics of programming and research on different types

b) Program the light in the microcontroller to do different things

Microcontrollers

In short, A Microcontroller (MCU) is a tiny computer chip that can: Control things around you, get input from sensors or buttons and give output to lights, motors, or displays. In short, A Microcontroller (MCU) is a tiny computer chip that can: Control things around you, get input from sensors or buttons and give output to lights, motors, or displays.

Microcontroller boards take in information and uses it to do something that we programmed it to do. The reason we use is to replace or remove the human element in the sense that instead of having to do everything manually, you can interact with a click of a button to make it do everything it was programmed to.

The first thing we did was identify the different types of microcontrollers and the different things they can do. We summarized them as a group in THIS WEBSITE

MKR1010

It has a chip with MKR1010 wifi that acts as a brain and support components. The pins all have different capabilities and choose which connect where. These are the steps on how to use it:

1) connect to the right place

2) give it power using a usb or battery

3) program -tell it what to do

Here’s how it looks like

Arduino Adafruit

Arduino is another type of microcontroller that we were introduced to. It essentially works the same as the MKR1010, just a different model and few different features. Now in order to program it, we were assigned a simple task of changing the built-in blinking bulb that it has to either blink faster or slower than it already is. In order to do so, we have to install the software for it called the Arduino IDE. “It makes it easy to write code and upload it to the board.”

Programming your microcontroller

Install necessary files/libraries

In order to load the code to the microcontroller you’re working with, you must first select the board and port relevant

To test out some codes, we can load some from the examples from here

Challenges

We were asked to give the mirocrontoller prompts for programming with the built in LED alone (no buttons).

The first challenge was: “blink your led but have your blink delay periods be randomized values between 1 second and 5 seconds” We did that by changing the milliseconds in the code to a certain number, then the code repeats itself.

The second one was to “pre code your microcontroller to send a Morse code 1 word message and challenge a friend or your instructor to figure it out.”

// 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(1000);                      // wait for half a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(500);                      // wait for half a second
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(500);                      // wait for half a second
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(500);                      // wait for half a second
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(3000);                      // wait for 3 seconds 
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(500);                      // wait for half a second
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(3000);                      // wait for 3 seconds
}

Python

Python is another programming language that we used. Its design philosophy emphasizes code readability with the use of significant indentation. I did the same challenge but this time using Mu Circuit-Python Programming. So the first thing I did was download the Mu software

Start by downloading the software

Then install its library

This will show up. Click ok.

I did the same morse code but this time in python language in comparison to C++. They work slightly different but it’s essentially the same concept.

Comparison between Arduino IDE and Mu Editor. Import necessary libraries for the board, the input and output and time

Before you run it, make sure everything is in the right format and indentation. But if typos still prevail, it will still notify you which line to modify to make the code valid

DIGITAL VS ANALOG

In programming, digital” and “analog” refer to different approaches or representations of data.

Digital: Represents information as discrete values or symbols. A digital clock shows time using digits (0-9) that change discretely every second. another example: light switch (has two options)

Analog: Represents information as a continuous signal. For instance, an analog clock uses rotating hands to show time continuously. another example: a ceiling fan (has a range of settings)


Last update: July 20, 2024