Skip to content

7. Embedded programming

This Weeks’ Task

1- Read the datasheet for the microcontroller board you are programming.

2- Program the board you have made to do something, with as many different programming.

3- languages and programming environments as possible. (two at least).

===============================================================

Embedded system

An embedded system is a small computer that forms part of a larger system, device or machine. Its purpose is to control the device and to allow a user to interact with it. They tend to have one, or a limited number of tasks that they can perform.

====================

Microcontroller datasheet

We are using Arduino nano. It is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online.

These are some important things to consider about the microcontroller, they are:

====================

Arduino Nano Pin Configuration

1- Power: Vin, 3.3V, 5V, GND

Vin: Input voltage to Arduino when using an external power source (6-12V).

5V: Regulated power supply used to power microcontroller and other components on the board.

3.3V: 3.3V supply generated by on-board voltage regulator. Maximum current draw is 50mA.

GND: Ground pins.

2- Reset: Reset

Resets the microcontroller.

3- Analog Pins: A0 – A7

Used to measure analog voltage in the range of 0-5V

4- Input/Output Pins: Digital Pins D0 - D13

Can be used as input or output pins. 0V (low) and 5V (high)

5- Serial: Rx, Tx

Used to receive and transmit TTL serial data.

6- External Interrupts: 2, 3

To trigger an interrupt.

7- PWM: 3, 5, 6, 9, 11

Provides 8-bit PWM output.

8- 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK)

Used for SPI communication.

9- Inbuilt LED: 13

To turn on the inbuilt LED.

10- IIC: A4 (SDA), A5 (SCA)

Used for TWI communication.

11- AREF: AREF

To provide reference voltage for input voltage.

===============================================================

Programming with Arduino IDE

Arduino nano

The arduino software is decided to be used to program the Arduino nano to interprets power to the outside world.

  • I started by downloading the software, then I loaded the Board Manager into the system. To do this you go to TOOLS in the upper bar, PORT, and choose the COM3.

====================

A problem happened that the software cannot read the microcontroller. This is because the laptop does not have the installer (USB Serial Port (COM3) drivers).

  • So we downloaded the port driver from driver scape, installed it and it worked!

To download

Driver Scape download

This is how I installed and download it

To get started, we used blink in the examples to check if it is working. To use the example, go to FILE, EXAMPLES, BASICS, BLINK.

===============================================================

Program the embedded LED in the Microcontroller by TinkerCad

To make thigs more exciting, I used Morse code to program the embedded LED in the microcontroller but this time I used TinkerCad and used the block system.

I made the timing based on:

Dott = 300 ms Dash = 900 ms

The delay between dot and dash = 300 ms The delay between the letters = 900 ms

====================

1- In the image below, I used the pink blocks to identify the delays. Dot for 300ms and dah/ dash for 900ms.

2- Then, I used the blue blocks to identify the high and low values of LED. High= light opens, Low= light closes

3- Adding the orange blocks in between the low and high blue blocks to specify the delays.

Using tinkerCad for Morse code

This is how it worked in tinkerCad! pretty cool ha!.

===============================================================

Program the embedded LED in the Microcontroller by Arduino IDE

I transferred the blocking code into Arduino IDE and wrote it as line coding.

As you can see in the pictures:

1- for the void setup, I set the code to pin 13 as it is the LED pin.

2- In the void loop, I began to write the high and low values to blink the LED in a specific timing based on the values that I specified earlier for Morse coding.

High= light opens, Low= light closes

void setup() {
  // put your setup code here, to run once:
 pinMode(13,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
 // F
  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(300);

  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(300);

  digitalWrite(13, HIGH);
  delay(900);
  digitalWrite(13, LOW);

  delay(300);

  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(900);

  //A
  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(300);

    digitalWrite(13, HIGH);
  delay(900);
  digitalWrite(13, LOW);

  delay(900);

  //J
    digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(300);

    digitalWrite(13, HIGH);
  delay(900);
  digitalWrite(13, LOW);

  delay(300);

    digitalWrite(13, HIGH);
  delay(900);
  digitalWrite(13, LOW);

  delay(300);

  digitalWrite(13, HIGH);
  delay(900);
  digitalWrite(13, LOW);

  delay(900);

  //E
  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(900);

  //R
  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(300);

  digitalWrite(13, HIGH);
  delay(900);
  digitalWrite(13, LOW);

  delay(300);

  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);

  delay(5000);

}

And this is how it works on the Arduino board!!!


Last update: September 11, 2021