This we were introduced to microcontrollers, their specifications and how to program them.

Microcontroller:

A microcontroller is a small integrated circuit that controls a single function in an embedded system. On a single chip, a typical microcontroller has a CPU, memory, and input/output (I/O) peripherals.

Microcontrollers, also known as embedded controllers or microcontroller units (MCU), are found in a variety of equipment such as cars, robotics, office machinery, medical devices, mobile wireless transceivers, vending machines, and household appliances. They are basically modest little personal computers (PCs) meant to control minor aspects of a bigger component without the need for a complicated front-end operating system (OS).


Group Work



In the group work, we worked in pairs to search about a microcontroller and understand it. We searched about different types of Microcontrollers and filled out the table diagram that we were signed up to do, so all of us can find the information of all the microcontrollers easily.

- You can find the Group Work here.

Individual Work


To start programming the microcontroller, I had to dowload two different programming environments; the Arduino IDE and Mu Editor. These two programs are used to code the microcontroller into the desired commands.

Programming Environments:

Programing environment is a combination of hardware and software that is used to create programs.


Starting Off With Simple Coding:

I had microcontroller type: Adafruit Feather nRF52840 Express and I did simple codings to understand the principles of coding a microcntroller.

In the coding process; I opened the Arduino IDE app and followed the instuctions given on the Arduino Support Website.

The microcontroller is connected to my pc with an USB to Type C port, and then device is reseted to apply the changes from the coding.

On every change or error accuring on the coding process the device has to be reseted to be modified.

Changing the device blinking speed:

The following data are controlling the blinking speed per second; and I tried couple of settings to test the changes appearing. I did not see a noticeable difference but if concentrating the blinking speed of the light changes by the changes applied on the coding input.




Coding The Microcontroller:

I coded the microcontroller using both apps, the Aruino IDE and the Mu Editor. Both apps are similar in coding in someway.

Coding Using Arduino IDE

Coding Adafruit Feather nRF52840 Sense

1. Connect the microcontroller to the pc.

2. Open the Arduino IDE app and go to files > Examples > 01.Basics > Blink. It will give a jumpstart with the coding.

3. Connecting the microcontroller data to the app; Tools > Boar > Adafruit nRF52840 > Adafruit Feather nRF52840 Sense.

4. Going again to Tools > Port. Now the app is connected to the microcontroller and the new coding will be directly influenced on the microcontroller.

5. Write the new code; each second = 1000.

6. Rest the microcntroller from the "Reset" botton.

7. Back to the Arduino IDE app and click on "Upload". Here the codes will be running to the microcntroller and when it is done uploading, the microcntroller led light will blink according to the given code.



Coding Using Mu Editor

Setting Up The Adafruit Feather nRF52840 Sense Before Coding in Mu Editor

1. Connect the microcontroller to the pc.

2. Dowloading "CircuitPython 7.3.3" from Circuit Python Website. This a built in module to ease the coding process.

3. Copy the dowloaded file to the microcontroller folder; which pops up once it is connected to the pc, and ensure to not disconect the microcntroller. Diconnecting the microcntroller might cause to lose the added file.

4. Two new folders will be added to the microcntroller folder. In the "lib" folder, there should be many folders inside containing coding library. I the folder is empty; then step "5" must be proceeded. In my case all the necessary files were existing in the "lib" folder; so I immediately skipped to the next process.

5. The microcntroller libraries can be found and dowloaded from Circuit Python Website.


Coding Adafruit Feather nRF52840 Sense

1. Keep the microcontroller connected to the pc and open Mu Editor.

2. From the tool bar > Mode > Select "CircuitPython".

3. A sample coding was copied from Adafruit website > Paste it in the Mu Editor app.

4. Write the new code; where each second = 1.

5. From the tool bar > Save > saving the folder as "code.py" in the app folder and not in any folder on the pc.

6. Few seconds later the microcntroller will receive the data from the codes and will blink accordingly.



- When switching between codings apps I disconnect the microcntroller from the pc and reconnect it again, to ensure the new codes are applied.

1. Coding the microcntroller to blink delay periods randomly between the values 1 second and 5 seconds - Easy Coding.

Coding Using Arduino IDE


           /*
         Blink

         Turns an LED on for one second, then off for one second, repeatedly.

         Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
         it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
         the correct LED pin independent of which board is used.
         If you want to know what pin the on-board LED is connected to on your Arduino
         model, check the Technical Specs of your board at:
         https://www.arduino.cc/en/Main/Products

         modified 8 May 2014
         by Scott Fitzgerald
         modified 2 Sep 2016
         by Arturo Guadalupi
         modified 8 Sep 2016
         by Colby Newman

         This example code is in the public domain.

         https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
       */

       // 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
       }
    
  

Click to dowload! Arduino IDE

2. Coding the microcntroller to Send a Morse Code - Medium Coding.

Coding Using Arduino IDE


                 */

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

Click to dowload! Arduino IDE

Coding Using Mu Editor



            """CircuitPython Blink Example - the CircuitPython 'Hello, World!'"""
  import time
  import board
  import digitalio

  led = digitalio.DigitalInOut(board.LED)
  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(2)
      led.value = False
      time.sleep(3)
      led.value = True
      time.sleep(1)
      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(2)
      led.value = False
      time.sleep(3)
      led.value = True
      time.sleep(1)
      led.value = False
      time.sleep(3)
      led.value = True
      time.sleep(1)
      led.value = False
      time.sleep(3)
      led.value = True
      time.sleep(2)
      led.value = False
      time.sleep(0.5)
      led.value = True
      time.sleep(1)
      led.value = False
      time.sleep(5)